diff --git a/templates/todo/common/infra/bicep/app/cosmos-mongo-db-avm.bicep b/templates/todo/common/infra/bicep/app/cosmos-mongo-db-avm.bicep new file mode 100644 index 00000000000..ff5ec734380 --- /dev/null +++ b/templates/todo/common/infra/bicep/app/cosmos-mongo-db-avm.bicep @@ -0,0 +1,77 @@ +param accountName string +param location string = resourceGroup().location +param tags object = {} +param cosmosDatabaseName string = '' +param keyVaultResourceId string +param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' +param collections array = [ + { + name: 'TodoList' + id: 'TodoList' + shardKey: { + keys: [ + 'Hash' + ] + } + indexes: [ + { + key: { + keys: [ + '_id' + ] + } + } + ] + } + { + name: 'TodoItem' + id: 'TodoItem' + shardKey: { + keys: [ + 'Hash' + ] + } + indexes: [ + { + key: { + keys: [ + '_id' + ] + } + } + ] + } +] + +var defaultDatabaseName = 'Todo' +var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName + +module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { + name: 'cosmos' + params: { + locations: [ + { + failoverPriority: 0 + isZoneRedundant: false + locationName: location + } + ] + name: accountName + location: location + mongodbDatabases: [ + { + name: actualDatabaseName + tags: tags + collections: collections + } + ] + secretsExportConfiguration: { + keyVaultResourceId: keyVaultResourceId + primaryWriteConnectionStringSecretName: connectionStringKey + } + } +} + +output connectionStringKey string = connectionStringKey +output databaseName string = cosmos.outputs.name +output endpoint string = cosmos.outputs.endpoint diff --git a/templates/todo/common/infra/bicep/app/cosmos-sql-db-avm.bicep b/templates/todo/common/infra/bicep/app/cosmos-sql-db-avm.bicep new file mode 100644 index 00000000000..2a8609af133 --- /dev/null +++ b/templates/todo/common/infra/bicep/app/cosmos-sql-db-avm.bicep @@ -0,0 +1,58 @@ +param accountName string +param location string = resourceGroup().location +param tags object = {} +param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' +param databaseName string = '' +param keyVaultResourceId string +param principalId string = '' + +var defaultDatabaseName = 'Todo' +var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName + +module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { + name: 'cosmos' + params: { + name: accountName + location: location + tags: tags + locations: [ + { + failoverPriority: 0 + locationName: location + isZoneRedundant: false + } + ] + secretsExportConfiguration:{ + keyVaultResourceId: keyVaultResourceId + primaryWriteConnectionStringSecretName: connectionStringKey + } + capabilitiesToAdd: [ 'EnableServerless' ] + automaticFailover: false + sqlDatabases: [ + { + name: actualDatabaseName + containers: [ + { + name: 'TodoList' + paths: [ 'id' ] + } + { + name: 'TodoItem' + paths: [ 'id' ] + } + ] + } + ] + sqlRoleAssignmentsPrincipalIds: [ principalId ] + sqlRoleDefinitions: [ + { + name: 'writer' + } + ] + } +} + +output accountName string = cosmos.outputs.name +output connectionStringKey string = connectionStringKey +output databaseName string = actualDatabaseName +output endpoint string = cosmos.outputs.endpoint diff --git a/templates/todo/common/infra/bicep/app/sql-deployment-script.bicep b/templates/todo/common/infra/bicep/app/sqlserver-avm.bicep similarity index 64% rename from templates/todo/common/infra/bicep/app/sql-deployment-script.bicep rename to templates/todo/common/infra/bicep/app/sqlserver-avm.bicep index fcbb9ea7081..f99786c4703 100644 --- a/templates/todo/common/infra/bicep/app/sql-deployment-script.bicep +++ b/templates/todo/common/infra/bicep/app/sqlserver-avm.bicep @@ -1,13 +1,13 @@ param location string = resourceGroup().location @description('Application user name') -param appUser string = 'appUser' +param appUser string @description('SQL Server administrator name') param sqlAdmin string = 'sqlAdmin' @description('The name for sql database ') -param sqlDatabaseName string +param sqlDatabaseName string = '' @description('Resource name for sql service') param sqlServiceName string @@ -20,6 +20,35 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string +param tags object = {} + +var defaultDatabaseName = 'Todo' +var actualDatabaseName = !empty(sqlDatabaseName) ? sqlDatabaseName : defaultDatabaseName + +module sqlServer 'br/public:avm/res/sql/server:0.2.0' = { + name: 'sqlservice' + params: { + name: sqlServiceName + administratorLogin: sqlAdmin + administratorLoginPassword: sqlAdminPassword + location: location + tags: tags + publicNetworkAccess: 'Enabled' + databases: [ + { + name: actualDatabaseName + } + ] + firewallRules: [ + { + name: 'Azure Services' + startIpAddress: '0.0.0.1' + endIpAddress: '255.255.255.254' + } + ] + } +} + module deploymentScript 'br/public:avm/res/resources/deployment-script:0.1.3' = { name: 'deployment-script' params: { @@ -42,11 +71,11 @@ module deploymentScript 'br/public:avm/res/resources/deployment-script:0.1.3' = } { name: 'DBNAME' - value: !empty(sqlDatabaseName) ? sqlDatabaseName : 'Todo' + value: actualDatabaseName } { name: 'DBSERVER' - value: '${sqlServiceName}${environment().suffixes.sqlServerHostname}' + value: '${sqlServer.outputs.name}${environment().suffixes.sqlServerHostname}' } { name: 'SQLCMDPASSWORD' @@ -75,3 +104,6 @@ SCRIPT_END ''' } } + +output databaseName string = actualDatabaseName +output sqlServerName string = sqlServer.outputs.name diff --git a/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.bicep b/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.bicep index 7e1ddc00353..ebe1eaedb78 100644 --- a/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.bicep @@ -18,13 +18,11 @@ param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param appServicePlanName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' param webServiceName string = '' param apimServiceName string = '' -param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' @@ -40,7 +38,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : 'Todo' // Organize resources in a resource group resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { @@ -79,8 +76,8 @@ module api '../../../../../common/infra/bicep/app/api-appservice-avm.bicep' = { } appSettings: { AZURE_KEY_VAULT_ENDPOINT: keyVault.outputs.uri - AZURE_COSMOS_CONNECTION_STRING_KEY: connectionStringKey - AZURE_COSMOS_DATABASE_NAME: actualDatabaseName + AZURE_COSMOS_CONNECTION_STRING_KEY: cosmos.outputs.connectionStringKey + AZURE_COSMOS_DATABASE_NAME: cosmos.outputs.databaseName AZURE_COSMOS_ENDPOINT: cosmos.outputs.endpoint API_ALLOW_ORIGINS: web.outputs.SERVICE_WEB_URI SCM_DO_BUILD_DURING_DEPLOYMENT: false @@ -119,46 +116,15 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.5.1' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-sql-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - locations: [ - { - failoverPriority: 0 - locationName: location - isZoneRedundant: false - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } - capabilitiesToAdd: [ 'EnableServerless' ] - automaticFailover: false - sqlDatabases: [ - { - name: actualDatabaseName - containers: [ - { - name: 'TodoList' - paths: [ 'id' ] - } - { - name: 'TodoItem' - paths: [ 'id' ] - } - ] - } - ] - sqlRoleAssignmentsPrincipalIds: [ principalId ] - sqlRoleDefinitions: [ - { - name: 'writer' - } - ] + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId + principalId: principalId } } @@ -167,7 +133,7 @@ module apiCosmosSqlRoleAssign 'br/public:avm/res/document-db/database-account:0. name: 'api-cosmos-access' scope: rg params: { - name: cosmos.outputs.name + name: cosmos.outputs.accountName location: location sqlRoleAssignmentsPrincipalIds: [ api.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID ] sqlRoleDefinitions: [ @@ -292,8 +258,8 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_ENDPOINT string = cosmos.outputs.endpoint -output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_CONNECTION_STRING_KEY string = cosmos.outputs.connectionStringKey +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/repo.yaml b/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/repo.yaml index 53eec76d18b..95fa7204787 100644 --- a/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/repo.yaml +++ b/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/repo.yaml @@ -75,6 +75,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-sql-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/wwwroot/openapi.yaml patterns: @@ -105,6 +110,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-sql-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-sql-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.bicep b/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.bicep index 5ebdb7f95a8..9aeb163e766 100644 --- a/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.bicep @@ -26,7 +26,6 @@ param sqlServerName string = '' param webServiceName string = '' param apimServiceName string = '' param appUser string = 'appUser' -param sqlAdmin string = 'sqlAdmin' param connectionStringKey string = 'AZURE-SQL-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' @@ -51,8 +50,6 @@ param appUserPassword string var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(sqlDatabaseName) ? sqlDatabaseName : defaultDatabaseName var webUri = 'https://${web.outputs.defaultHostname}' // Organize resources in a resource group @@ -139,7 +136,7 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.5.1' = { } { name: connectionStringKey - value: 'Server=${sqlService.outputs.name}${environment().suffixes.sqlServerHostname}; Database=${actualDatabaseName}; User=${appUser}; Password=${appUserPassword}' + value: 'Server=${sqlService.outputs.sqlServerName}${environment().suffixes.sqlServerHostname}; Database=${sqlService.outputs.databaseName}; User=${appUser}; Password=${appUserPassword}' } ] } @@ -147,41 +144,15 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.5.1' = { } // The application database -module sqlService 'br/public:avm/res/sql/server:0.2.0' = { - name: 'sqlservice' - scope: rg - params: { - name: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${resourceToken}' - administratorLogin: sqlAdmin - administratorLoginPassword: sqlAdminPassword - location: location - tags: tags - publicNetworkAccess: 'Enabled' - databases: [ - { - name: actualDatabaseName - } - ] - firewallRules:[ - { - name: 'Azure Services' - startIpAddress: '0.0.0.1' - endIpAddress: '255.255.255.254' - } - ] - } -} - -//Add appuser to database owner -module sqlDeploymentScript '../../../../../common/infra/bicep/app/sql-deployment-script.bicep' = { +module sqlService '../../../../../common/infra/bicep/app/sqlserver-avm.bicep' = { name: 'sqldeploymentscript' scope: rg params: { location: location appUserPassword: appUserPassword sqlAdminPassword: sqlAdminPassword - sqlDatabaseName: actualDatabaseName - sqlServiceName: sqlService.outputs.name + sqlServiceName: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${resourceToken}' + appUser: appUser } } diff --git a/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/repo.yaml b/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/repo.yaml index 554b37ce849..50f6e847571 100644 --- a/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/repo.yaml +++ b/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/repo.yaml @@ -75,6 +75,11 @@ repo: patterns: - "**/main.bicep" + - from: /sqlserver-avm.bicep + to: /db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -105,6 +110,9 @@ repo: - from: ../../../../common/infra/bicep/app/sqlserver.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/sqlserver-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.bicep b/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.bicep index d2196f067e8..433156633fd 100644 --- a/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.bicep @@ -45,12 +45,9 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string param appUser string = 'appUser' -param sqlAdmin string = 'sqlAdmin' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(sqlDatabaseName) ? sqlDatabaseName : defaultDatabaseName // Organize resources in a resource group resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { @@ -134,7 +131,7 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.3.5' = { } { name: connectionStringKey - value: 'Server=${sqlService.outputs.name}${environment().suffixes.sqlServerHostname}; Database=${actualDatabaseName}; User=${appUser}; Password=${appUserPassword}' + value: 'Server=${sqlService.outputs.sqlServerName}${environment().suffixes.sqlServerHostname}; Database=${sqlService.outputs.databaseName}; User=${appUser}; Password=${appUserPassword}' } ] } @@ -142,41 +139,15 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.3.5' = { } // The application database -module sqlService 'br/public:avm/res/sql/server:0.2.0' = { - name: 'sqlservice' - scope: rg - params: { - name: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${resourceToken}' - administratorLogin: sqlAdmin - administratorLoginPassword: sqlAdminPassword - location: location - tags: tags - publicNetworkAccess: 'Enabled' - databases: [ - { - name: actualDatabaseName - } - ] - firewallRules: [ - { - name: 'Azure Services' - startIpAddress: '0.0.0.1' - endIpAddress: '255.255.255.254' - } - ] - } -} - -//Add appuser to database owner -module sqlDeploymentScript '../../../../../common/infra/bicep/app/sql-deployment-script.bicep' = { +module sqlService '../../../../../common/infra/bicep/app/sqlserver-avm.bicep' = { name: 'sqldeploymentscript' scope: rg params: { location: location appUserPassword: appUserPassword sqlAdminPassword: sqlAdminPassword - sqlDatabaseName: actualDatabaseName - sqlServiceName: sqlService.outputs.name + sqlServiceName: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${resourceToken}' + appUser: appUser } } diff --git a/templates/todo/projects/csharp-sql/.repo/bicep/repo.yaml b/templates/todo/projects/csharp-sql/.repo/bicep/repo.yaml index b0af207ec6e..7a8b498987f 100644 --- a/templates/todo/projects/csharp-sql/.repo/bicep/repo.yaml +++ b/templates/todo/projects/csharp-sql/.repo/bicep/repo.yaml @@ -76,6 +76,11 @@ repo: patterns: - "**/main.bicep" + - from: /sqlserver-avm.bicep + to: /db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/wwwroot/openapi.yaml patterns: @@ -109,8 +114,8 @@ repo: - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep - - from: ../../../../common/infra/bicep/app/sql-deployment-script.bicep - to: ./infra/app/sql-deployment-script.bicep + - from: ../../../../common/infra/bicep/app/sqlserver-avm.bicep + to: ./infra/app/db-avm.bicep - from: ../../../../common/infra/bicep/app/web-appservice-avm.bicep to: ./infra/app/web-appservice-avm.bicep diff --git a/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.bicep b/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.bicep index e233be2aa8e..8231d9d8ca6 100644 --- a/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.bicep @@ -19,7 +19,6 @@ param applicationInsightsName string = '' param containerAppsEnvironmentName string = '' param containerRegistryName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -28,40 +27,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -78,8 +43,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName var apiContainerAppNameOrDefault = '${abbrs.appContainerApps}web-${resourceToken}' var corsAcaUrl = 'https://${apiContainerAppNameOrDefault}.${containerAppsEnvironment.outputs.defaultDomain}' var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') @@ -241,30 +204,14 @@ module api 'br/public:avm/res/app/container-app:0.2.0' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration: { - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -378,7 +325,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output API_CORS_ACA_URL string = corsAcaUrl diff --git a/templates/todo/projects/java-mongo-aca/.repo/bicep/repo.yaml b/templates/todo/projects/java-mongo-aca/.repo/bicep/repo.yaml index 4258cd5d7d9..f5a82320ef5 100644 --- a/templates/todo/projects/java-mongo-aca/.repo/bicep/repo.yaml +++ b/templates/todo/projects/java-mongo-aca/.repo/bicep/repo.yaml @@ -82,6 +82,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -109,6 +114,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/java-mongo/.repo/bicep/infra/main.bicep b/templates/todo/projects/java-mongo/.repo/bicep/infra/main.bicep index df3ddcb3ae1..e5ea7dafa66 100644 --- a/templates/todo/projects/java-mongo/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/java-mongo/.repo/bicep/infra/main.bicep @@ -18,7 +18,6 @@ param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param appServicePlanName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -27,44 +26,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: { - keys: [ - 'Hash' - ] - } - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: { - keys: [ - 'Hash' - ] - } - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -78,8 +39,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName // Organize resources in a resource group resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { @@ -119,8 +78,8 @@ module api '../../../../../common/infra/bicep/app/api-appservice-avm.bicep' = { appSettings: { AZURE_KEY_VAULT_ENDPOINT: keyVault.outputs.uri AZURE_COSMOS_CONNECTION_STRING_KEY: connectionStringKey - AZURE_COSMOS_DATABASE_NAME: actualDatabaseName - AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.name}.mongo.cosmos.azure.com:443/' + AZURE_COSMOS_DATABASE_NAME: cosmos.outputs.databaseName + AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.databaseName}.mongo.cosmos.azure.com:443/' API_ALLOW_ORIGINS: web.outputs.SERVICE_WEB_URI JAVA_OPTS: join(concat([], [ '-Djdk.attach.allowAttachSelf=true' ]), ' ') SCM_DO_BUILD_DURING_DEPLOYMENT: true @@ -159,30 +118,14 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.3.5' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration: { - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -300,7 +243,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/java-mongo/.repo/bicep/repo.yaml b/templates/todo/projects/java-mongo/.repo/bicep/repo.yaml index d3b618e8096..02fb262b6d6 100644 --- a/templates/todo/projects/java-mongo/.repo/bicep/repo.yaml +++ b/templates/todo/projects/java-mongo/.repo/bicep/repo.yaml @@ -75,6 +75,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -102,6 +107,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.bicep b/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.bicep index 8794ecbf080..8231d9d8ca6 100644 --- a/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.bicep @@ -19,7 +19,6 @@ param applicationInsightsName string = '' param containerAppsEnvironmentName string = '' param containerRegistryName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -28,40 +27,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -78,8 +43,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName var apiContainerAppNameOrDefault = '${abbrs.appContainerApps}web-${resourceToken}' var corsAcaUrl = 'https://${apiContainerAppNameOrDefault}.${containerAppsEnvironment.outputs.defaultDomain}' var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') @@ -241,30 +204,14 @@ module api 'br/public:avm/res/app/container-app:0.2.0' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -378,7 +325,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output API_CORS_ACA_URL string = corsAcaUrl diff --git a/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/repo.yaml b/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/repo.yaml index cade3ef6850..a8180c398b0 100644 --- a/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/repo.yaml +++ b/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/repo.yaml @@ -82,6 +82,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -112,6 +117,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/infra/main.bicep b/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/infra/main.bicep index 7f9a2d76b32..407f0557be6 100644 --- a/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/infra/main.bicep @@ -22,45 +22,10 @@ param containerRegistryName string = '' param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Id of the user or app to assign application roles') param principalId string = '' @@ -77,8 +42,6 @@ param systemPoolType string = 'CostOptimised' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') var aksClusterAdminRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b1ff04bb-8a4e-4dc4-8eb5-8693973ce19b') var systemPoolSpec = nodePoolPresets[systemPoolType] @@ -246,30 +209,14 @@ module containerRegistry 'br/public:avm/res/container-registry/registry:0.1.1' = } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -338,7 +285,7 @@ module applicationInsightsDashboard '../../../../../common/infra/bicep/app/appli // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/repo.yaml b/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/repo.yaml index db69596b955..64968eb667e 100644 --- a/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/repo.yaml +++ b/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/repo.yaml @@ -70,6 +70,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -85,6 +90,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.bicep b/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.bicep index 27c110cfd5c..a7047dc01d2 100644 --- a/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.bicep @@ -18,7 +18,6 @@ param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param appServicePlanName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -28,40 +27,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -75,8 +40,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName var webUri = 'https://${web.outputs.defaultHostname}' // Organize resources in a resource group @@ -111,9 +74,9 @@ module api '../../../../../common/infra/bicep/app/api-appservice-avm.bicep' = { appSettings: { API_ALLOW_ORIGINS: webUri AZURE_COSMOS_CONNECTION_STRING_KEY: connectionStringKey - AZURE_COSMOS_DATABASE_NAME: actualDatabaseName + AZURE_COSMOS_DATABASE_NAME: cosmos.outputs.databaseName AZURE_KEY_VAULT_ENDPOINT:keyVault.outputs.uri - AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.name}.documents.azure.com:443/' + AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.databaseName}.documents.azure.com:443/' FUNCTIONS_EXTENSION_VERSION: '~4' FUNCTIONS_WORKER_RUNTIME: 'node' SCM_DO_BUILD_DURING_DEPLOYMENT: true @@ -157,30 +120,14 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.5.1' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -316,7 +263,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/repo.yaml b/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/repo.yaml index 77ee5f978f1..55376aa2a25 100644 --- a/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/repo.yaml +++ b/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/repo.yaml @@ -75,6 +75,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -105,6 +110,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.bicep b/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.bicep index 3a7d7469ba0..29edc6dc1d8 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.bicep @@ -18,7 +18,6 @@ param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param appServicePlanName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -27,40 +26,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -74,8 +39,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName // Organize resources in a resource group resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { @@ -115,8 +78,8 @@ module api '../../../../../common/infra/bicep/app/api-appservice-avm.bicep' = { appSettings: { AZURE_KEY_VAULT_ENDPOINT: keyVault.outputs.uri AZURE_COSMOS_CONNECTION_STRING_KEY: connectionStringKey - AZURE_COSMOS_DATABASE_NAME: actualDatabaseName - AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.name}.documents.azure.com:443/' + AZURE_COSMOS_DATABASE_NAME: cosmos.outputs.databaseName + AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.databaseName}.documents.azure.com:443/' API_ALLOW_ORIGINS: web.outputs.SERVICE_WEB_URI SCM_DO_BUILD_DURING_DEPLOYMENT: true } @@ -154,30 +117,14 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.3.5' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -295,7 +242,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/nodejs-mongo/.repo/bicep/repo.yaml b/templates/todo/projects/nodejs-mongo/.repo/bicep/repo.yaml index bbad0da2998..ec9ae9a7401 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/bicep/repo.yaml +++ b/templates/todo/projects/nodejs-mongo/.repo/bicep/repo.yaml @@ -75,6 +75,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -101,6 +106,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.bicep b/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.bicep index 8794ecbf080..8231d9d8ca6 100644 --- a/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.bicep @@ -19,7 +19,6 @@ param applicationInsightsName string = '' param containerAppsEnvironmentName string = '' param containerRegistryName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -28,40 +27,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -78,8 +43,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName var apiContainerAppNameOrDefault = '${abbrs.appContainerApps}web-${resourceToken}' var corsAcaUrl = 'https://${apiContainerAppNameOrDefault}.${containerAppsEnvironment.outputs.defaultDomain}' var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') @@ -241,30 +204,14 @@ module api 'br/public:avm/res/app/container-app:0.2.0' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -378,7 +325,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output API_CORS_ACA_URL string = corsAcaUrl diff --git a/templates/todo/projects/python-mongo-aca/.repo/bicep/repo.yaml b/templates/todo/projects/python-mongo-aca/.repo/bicep/repo.yaml index 10412677686..3f771f3f927 100644 --- a/templates/todo/projects/python-mongo-aca/.repo/bicep/repo.yaml +++ b/templates/todo/projects/python-mongo-aca/.repo/bicep/repo.yaml @@ -81,6 +81,11 @@ repo: to: db.bicep patterns: - "**/main.bicep" + + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml @@ -112,6 +117,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.bicep b/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.bicep index 5856580ee75..d094a3be88b 100644 --- a/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.bicep @@ -18,7 +18,6 @@ param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param appServicePlanName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -28,40 +27,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -75,8 +40,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName var webUri = 'https://${web.outputs.defaultHostname}' // Organize resources in a resource group @@ -111,9 +74,9 @@ module api '../../../../../common/infra/bicep/app/api-appservice-avm.bicep' = { appSettings: { API_ALLOW_ORIGINS: webUri AZURE_COSMOS_CONNECTION_STRING_KEY: connectionStringKey - AZURE_COSMOS_DATABASE_NAME: actualDatabaseName + AZURE_COSMOS_DATABASE_NAME: cosmos.outputs.databaseName AZURE_KEY_VAULT_ENDPOINT:keyVault.outputs.uri - AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.name}.documents.azure.com:443/' + AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.databaseName}.documents.azure.com:443/' FUNCTIONS_EXTENSION_VERSION: '~4' FUNCTIONS_WORKER_RUNTIME: 'python' SCM_DO_BUILD_DURING_DEPLOYMENT: true @@ -157,30 +120,14 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.5.1' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -316,7 +263,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/python-mongo-swa-func/.repo/bicep/repo.yaml b/templates/todo/projects/python-mongo-swa-func/.repo/bicep/repo.yaml index acf7e8eab7b..28285350535 100644 --- a/templates/todo/projects/python-mongo-swa-func/.repo/bicep/repo.yaml +++ b/templates/todo/projects/python-mongo-swa-func/.repo/bicep/repo.yaml @@ -74,6 +74,11 @@ repo: to: db.bicep patterns: - "**/main.bicep" + + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml @@ -104,6 +109,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep diff --git a/templates/todo/projects/python-mongo/.repo/bicep/infra/main.bicep b/templates/todo/projects/python-mongo/.repo/bicep/infra/main.bicep index 3996fd127ba..78fd51148b7 100644 --- a/templates/todo/projects/python-mongo/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/python-mongo/.repo/bicep/infra/main.bicep @@ -18,7 +18,6 @@ param applicationInsightsDashboardName string = '' param applicationInsightsName string = '' param appServicePlanName string = '' param cosmosAccountName string = '' -param cosmosDatabaseName string = '' param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' @@ -27,40 +26,6 @@ param apimServiceName string = '' param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING' param apimApiName string = 'todo-api' param apimLoggerName string = 'app-insights-logger' -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: {keys: [ - 'Hash' - ]} - indexes: [ - { - key: { - keys: [ - '_id' - ] - } - } - ] - } -] @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false @@ -74,8 +39,6 @@ param principalId string = '' var abbrs = loadJsonContent('../../../../../../common/infra/bicep/abbreviations.json') var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) var tags = { 'azd-env-name': environmentName } -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName // Organize resources in a resource group resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { @@ -116,8 +79,8 @@ module api '../../../../../common/infra/bicep/app/api-appservice-avm.bicep' = { appSettings: { AZURE_KEY_VAULT_ENDPOINT: keyVault.outputs.uri AZURE_COSMOS_CONNECTION_STRING_KEY: connectionStringKey - AZURE_COSMOS_DATABASE_NAME: actualDatabaseName - AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.name}.documents.azure.com:443/' + AZURE_COSMOS_DATABASE_NAME: cosmos.outputs.databaseName + AZURE_COSMOS_ENDPOINT: 'https://${cosmos.outputs.databaseName}.documents.azure.com:443/' API_ALLOW_ORIGINS: web.outputs.SERVICE_WEB_URI SCM_DO_BUILD_DURING_DEPLOYMENT: true } @@ -155,30 +118,14 @@ module accessKeyVault 'br/public:avm/res/key-vault/vault:0.3.5' = { } // The application database -module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = { +module cosmos '../../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep' = { name: 'cosmos' scope: rg params: { - locations: [ - { - failoverPriority: 0 - isZoneRedundant: false - locationName: location - } - ] - name: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' + accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}' location: location - mongodbDatabases: [ - { - name: actualDatabaseName - tags: tags - collections: collections - } - ] - secretsExportConfiguration:{ - keyVaultResourceId: keyVault.outputs.resourceId - primaryWriteConnectionStringSecretName: connectionStringKey - } + tags: tags + keyVaultResourceId: keyVault.outputs.resourceId } } @@ -296,7 +243,7 @@ module apimApi 'br/public:avm/ptn/azd/apim-api:0.1.0' = { // Data outputs output AZURE_COSMOS_CONNECTION_STRING_KEY string = connectionStringKey -output AZURE_COSMOS_DATABASE_NAME string = actualDatabaseName +output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName // App outputs output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsights.outputs.connectionString diff --git a/templates/todo/projects/python-mongo/.repo/bicep/repo.yaml b/templates/todo/projects/python-mongo/.repo/bicep/repo.yaml index ead8f2a9205..3f634b42834 100644 --- a/templates/todo/projects/python-mongo/.repo/bicep/repo.yaml +++ b/templates/todo/projects/python-mongo/.repo/bicep/repo.yaml @@ -85,6 +85,11 @@ repo: patterns: - "**/main.bicep" + - from: cosmos-mongo-db-avm.bicep + to: db-avm.bicep + patterns: + - "**/main.bicep" + - from: ../../../../api/common/openapi.yaml to: ../../src/api/openapi.yaml patterns: @@ -115,6 +120,9 @@ repo: - from: ../../../../common/infra/bicep/app/cosmos-mongo-db.bicep to: ./infra/app/db.bicep + - from: ../../../../common/infra/bicep/app/cosmos-mongo-db-avm.bicep + to: ./infra/app/db-avm.bicep + - from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep to: ./infra/app/applicationinsights-dashboard.bicep