diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 091842a55..424a51ef7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "python-app-service-postgresql-redis-infra", + "name": "python-app-service-postgresql-managed-redis-infra", "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", diff --git a/README.md b/README.md index 260d41e42..1c5c9d14b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ description: This is a Python web app using the Django framework and the Azure D This is a Python web app using the Django framework and the Azure Database for PostgreSQL relational database service. The Django app is hosted in a fully managed Azure App Service. This app is designed to be be run locally and then deployed to Azure. You can either deploy this project by following the tutorial [*Deploy a Python (Django or Flask) web app with PostgreSQL in Azure*](https://docs.microsoft.com/azure/app-service/tutorial-python-postgresql-app) or by using the [Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) according to the instructions below. -Additionally, the sample application demonstrates Azure Redis Cache access by caching the restaurant details page for 60 seconds. You can add the Azure Redis Cache integration in the [secure-by-default web app + database creation wizard](https://portal.azure.com/?feature.customportal=false#create/Microsoft.AppServiceWebAppDatabaseV3), and it's also included in the [AZD template](https://github.com/Azure-Samples/python-app-service-postgresql-infra). +Additionally, the sample application demonstrates Azure Managed Redis access by caching the restaurant details page for 60 seconds. You can add the Azure Managed Redis integration in the [AZD template](https://github.com/Azure-Samples/python-app-service-postgresql-infra). ## Requirements diff --git a/azure.yaml b/azure.yaml index 033038f25..90578da97 100644 --- a/azure.yaml +++ b/azure.yaml @@ -1,9 +1,9 @@ # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json # azure.yaml is an azd configuration file and isn't used by the sample application. -name: python-app-service-postgresql-redis-infra +name: python-app-service-postgresql-managed-redis-infra metadata: - template: python-app-service-postgresql-redis-infra@0.0.1-beta + template: python-app-service-postgresql-managed-redis-infra@0.0.1-beta services: web: project: . diff --git a/infra/resources.bicep b/infra/resources.bicep index f5fba55f0..66afdd5c1 100644 --- a/infra/resources.bicep +++ b/infra/resources.bicep @@ -148,7 +148,7 @@ resource privateDnsZoneDB 'Microsoft.Network/privateDnsZones@2024-06-01' = { } } -// Resources needed to secure Redis Cache behind a private endpoint +// Resources needed to secure Azure Managed Redis behind a private endpoint resource cachePrivateEndpoint 'Microsoft.Network/privateEndpoints@2024-03-01' = { name: '${appName}-cache-privateEndpoint' location: location @@ -161,7 +161,7 @@ resource cachePrivateEndpoint 'Microsoft.Network/privateEndpoints@2024-03-01' = name: '${appName}-cache-privateEndpoint' properties: { privateLinkServiceId: redisCache.id - groupIds: ['redisCache'] + groupIds: ['redisEnterprise'] } } ] @@ -181,7 +181,7 @@ resource cachePrivateEndpoint 'Microsoft.Network/privateEndpoints@2024-03-01' = } } resource privateDnsZoneCache 'Microsoft.Network/privateDnsZones@2024-06-01' = { - name: 'privatelink.redis.cache.windows.net' + name: 'privatelink.redisenterprise.cache.azure.net' location: 'global' dependsOn: [ virtualNetwork @@ -274,23 +274,33 @@ resource dbserver 'Microsoft.DBforPostgreSQL/flexibleServers@2022-01-20-preview' ] } -// The Redis cache is configured to the minimum pricing tier -resource redisCache 'Microsoft.Cache/redis@2024-11-01' = { +// The Azure Managed Redis cluster is configured to the minimum Balanced tier +resource redisCache 'Microsoft.Cache/redisEnterprise@2024-10-01' = { name: '${appName}-cache' location: location + sku: { + name: 'Balanced_B0' + capacity: 1 + } properties: { - sku: { - name: 'Basic' - family: 'C' - capacity: 0 - } - redisConfiguration: {} - enableNonSslPort: false - redisVersion: '6' + minimumTlsVersion: '1.2' publicNetworkAccess: 'Disabled' } } +// The Azure Managed Redis database +resource redisCacheDb 'Microsoft.Cache/redisEnterprise/databases@2024-10-01' = { + parent: redisCache + name: 'default' + properties: { + evictionPolicy: 'AllKeysLRU' + // EnterpriseCluster exposes a single endpoint so standard (non-cluster-aware) + // Redis clients like django-redis / redis-py work without modification. + clusteringPolicy: 'EnterpriseCluster' + port: 10000 + } +} + // The App Service plan is configured to the B1 pricing tier resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = { name: '${appName}-plan' @@ -430,7 +440,7 @@ resource cacheConnector 'Microsoft.ServiceLinker/linkers@2024-04-01' = { clientType: 'python' targetService: { type: 'AzureResource' - id: resourceId('Microsoft.Cache/Redis/Databases', redisCache.name, '0') + id: redisCacheDb.id } authInfo: { authType: 'accessKey'