From 2d887a4e7881936c4da5d32c62b4d5a4452cbe1c Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Fri, 1 Mar 2024 14:54:42 -0800 Subject: [PATCH] Add template changes --- .../bicep/core/host/container-app-upsert.bicep | 2 +- .../infra/bicep/core/host/container-app.bicep | 4 ++-- .../core/host/container-apps-environment.bicep | 2 +- .../bicep/core/host/container-registry.bicep | 4 ++-- .../bicep/core/search/search-services.bicep | 10 +++------- .../bicep/core/security/registry-access.bicep | 2 +- .../terraform/core/database/cosmos/cosmos.tf | 2 ++ .../appservicenode/appservicenode_output.tf | 6 +++++- .../appservicepython/appservicepython_output.tf | 5 ++++- .../.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../csharp-sql/.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../java-mongo-aca/.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../java-mongo/.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../.repo/terraform/infra/main.tf | 2 +- .../.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../nodejs-mongo-aks/.repo/bicep/azure.yaml | 16 ++++++++++++---- .../.repo/bicep/infra/main.bicep | 3 +++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../nodejs-mongo/.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../.repo/terraform/OPTIONAL_FEATURES.md | 7 +++++++ .../nodejs-mongo/.repo/terraform/infra/main.tf | 15 +++++++++++++-- .../.repo/terraform/infra/main.tfvars.json | 3 ++- .../.repo/terraform/infra/variables.tf | 6 ++++++ .../.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../python-mongo/.repo/bicep/infra/main.bicep | 4 ++++ .../.repo/bicep/infra/main.parameters.json | 3 +++ .../python-mongo/.repo/terraform/infra/main.tf | 16 +++++++++++++--- .../.repo/terraform/infra/main.tfvars.json | 3 ++- .../.repo/terraform/infra/variables.tf | 6 ++++++ 40 files changed, 159 insertions(+), 28 deletions(-) diff --git a/templates/common/infra/bicep/core/host/container-app-upsert.bicep b/templates/common/infra/bicep/core/host/container-app-upsert.bicep index f4a493d0d2f..3eec62f2954 100644 --- a/templates/common/infra/bicep/core/host/container-app-upsert.bicep +++ b/templates/common/infra/bicep/core/host/container-app-upsert.bicep @@ -67,7 +67,7 @@ param serviceBinds array = [] @description('The target port for the container') param targetPort int = 80 -resource existingApp 'Microsoft.App/containerApps@2023-05-02-preview' existing = if (exists) { +resource existingApp 'Microsoft.App/containerApps@2023-04-01-preview' existing = if (exists) { name: name } diff --git a/templates/common/infra/bicep/core/host/container-app.bicep b/templates/common/infra/bicep/core/host/container-app.bicep index ba8d7ee0737..3724086d24d 100644 --- a/templates/common/infra/bicep/core/host/container-app.bicep +++ b/templates/common/infra/bicep/core/host/container-app.bicep @@ -89,7 +89,7 @@ module containerRegistryAccess '../security/registry-access.bicep' = if (usePriv } } -resource app 'Microsoft.App/containerApps@2023-05-02-preview' = { +resource app 'Microsoft.App/containerApps@2023-04-01-preview' = { name: name location: location tags: tags @@ -150,7 +150,7 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = { } } -resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = { +resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-04-01-preview' existing = { name: containerAppsEnvironmentName } diff --git a/templates/common/infra/bicep/core/host/container-apps-environment.bicep b/templates/common/infra/bicep/core/host/container-apps-environment.bicep index 20f4632e0d7..8633ba48792 100644 --- a/templates/common/infra/bicep/core/host/container-apps-environment.bicep +++ b/templates/common/infra/bicep/core/host/container-apps-environment.bicep @@ -12,7 +12,7 @@ param daprEnabled bool = false @description('Name of the Log Analytics workspace') param logAnalyticsWorkspaceName string -resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = { +resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-04-01-preview' = { name: name location: location tags: tags diff --git a/templates/common/infra/bicep/core/host/container-registry.bicep b/templates/common/infra/bicep/core/host/container-registry.bicep index 26b4d2ffdb5..9c64531b965 100644 --- a/templates/common/infra/bicep/core/host/container-registry.bicep +++ b/templates/common/infra/bicep/core/host/container-registry.bicep @@ -34,8 +34,8 @@ param zoneRedundancy string = 'Disabled' @description('The log analytics workspace ID used for logging and monitoring') param workspaceId string = '' -// 2023-01-01-preview needed for anonymousPullEnabled -resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' = { +// 2022-02-01-preview needed for anonymousPullEnabled +resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' = { name: name location: location tags: tags diff --git a/templates/common/infra/bicep/core/search/search-services.bicep b/templates/common/infra/bicep/core/search/search-services.bicep index d9c619a96ec..32edfd604cc 100644 --- a/templates/common/infra/bicep/core/search/search-services.bicep +++ b/templates/common/infra/bicep/core/search/search-services.bicep @@ -36,16 +36,14 @@ param replicaCount int = 1 ]) param semanticSearch string = 'disabled' -var searchIdentityProvider = (sku.name == 'free') ? null : { - type: 'SystemAssigned' -} - resource search 'Microsoft.Search/searchServices@2021-04-01-preview' = { name: name location: location tags: tags // The free tier does not support managed identity - identity: searchIdentityProvider + identity: (sku.name == 'free') ? null : { + type: 'SystemAssigned' + } properties: { authOptions: authOptions disableLocalAuth: disableLocalAuth @@ -64,5 +62,3 @@ resource search 'Microsoft.Search/searchServices@2021-04-01-preview' = { output id string = search.id output endpoint string = 'https://${name}.search.windows.net/' output name string = search.name -output principalId string = !empty(searchIdentityProvider) ? search.identity.principalId : '' - diff --git a/templates/common/infra/bicep/core/security/registry-access.bicep b/templates/common/infra/bicep/core/security/registry-access.bicep index fc66837a12d..5335efabc8b 100644 --- a/templates/common/infra/bicep/core/security/registry-access.bicep +++ b/templates/common/infra/bicep/core/security/registry-access.bicep @@ -14,6 +14,6 @@ resource aksAcrPull 'Microsoft.Authorization/roleAssignments@2022-04-01' = { } } -resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' existing = { +resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = { name: containerRegistryName } diff --git a/templates/common/infra/terraform/core/database/cosmos/cosmos.tf b/templates/common/infra/terraform/core/database/cosmos/cosmos.tf index 798be23c637..494556fcf22 100644 --- a/templates/common/infra/terraform/core/database/cosmos/cosmos.tf +++ b/templates/common/infra/terraform/core/database/cosmos/cosmos.tf @@ -68,6 +68,7 @@ resource "azurerm_cosmosdb_mongo_collection" "list" { index { keys = ["_id"] + unique = true } } @@ -80,5 +81,6 @@ resource "azurerm_cosmosdb_mongo_collection" "item" { index { keys = ["_id"] + unique = true } } \ No newline at end of file diff --git a/templates/common/infra/terraform/core/host/appservice/appservicenode/appservicenode_output.tf b/templates/common/infra/terraform/core/host/appservice/appservicenode/appservicenode_output.tf index 81689fd303f..2715d689547 100644 --- a/templates/common/infra/terraform/core/host/appservice/appservicenode/appservicenode_output.tf +++ b/templates/common/infra/terraform/core/host/appservice/appservicenode/appservicenode_output.tf @@ -5,4 +5,8 @@ output "URI" { output "IDENTITY_PRINCIPAL_ID" { value = length(azurerm_linux_web_app.web.identity) == 0 ? "" : azurerm_linux_web_app.web.identity.0.principal_id sensitive = true -} \ No newline at end of file +} + +output "APPSERVICE_NAME" { + value = azurerm_linux_web_app.web.name +} diff --git a/templates/common/infra/terraform/core/host/appservice/appservicepython/appservicepython_output.tf b/templates/common/infra/terraform/core/host/appservice/appservicepython/appservicepython_output.tf index 7821671ec18..cecf9b98dbe 100644 --- a/templates/common/infra/terraform/core/host/appservice/appservicepython/appservicepython_output.tf +++ b/templates/common/infra/terraform/core/host/appservice/appservicepython/appservicepython_output.tf @@ -5,4 +5,7 @@ output "URI" { output "IDENTITY_PRINCIPAL_ID" { value = length(azurerm_linux_web_app.web.identity) == 0 ? "" : azurerm_linux_web_app.web.identity.0.principal_id sensitive = true -} \ No newline at end of file +} +output "APPSERVICE_NAME" { + value = azurerm_linux_web_app.web.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 60dd53f7c2d..c0207ef535b 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 @@ -28,6 +28,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -178,6 +181,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.parameters.json index 1b12cb32a96..af7f6f2cd1a 100644 --- a/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/csharp-cosmos-sql/.repo/bicep/infra/main.parameters.json @@ -13,6 +13,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 1b4b4bd2d81..a3c50163619 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 @@ -29,6 +29,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -163,6 +166,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.parameters.json index 84929e7bb6a..7bdb51a7f1c 100644 --- a/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/csharp-sql-swa-func/.repo/bicep/infra/main.parameters.json @@ -19,6 +19,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 a3c15a5e8fd..35f2685f768 100644 --- a/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.bicep @@ -28,6 +28,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -163,6 +166,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.parameters.json index 84929e7bb6a..7bdb51a7f1c 100644 --- a/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/csharp-sql/.repo/bicep/infra/main.parameters.json @@ -19,6 +19,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 fb9a4a0292e..54ec97e9fd5 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 @@ -31,6 +31,9 @@ param webAppExists bool = false @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -151,6 +154,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.parameters.json index 8ddb71e6e8e..675a89c4c01 100644 --- a/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/java-mongo-aca/.repo/bicep/infra/main.parameters.json @@ -22,6 +22,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 a282c3c7f17..fd2ffe033de 100644 --- a/templates/todo/projects/java-mongo/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/java-mongo/.repo/bicep/infra/main.bicep @@ -28,6 +28,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -156,6 +159,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/java-mongo/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/java-mongo/.repo/bicep/infra/main.parameters.json index 1b12cb32a96..af7f6f2cd1a 100644 --- a/templates/todo/projects/java-mongo/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/java-mongo/.repo/bicep/infra/main.parameters.json @@ -13,6 +13,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file diff --git a/templates/todo/projects/java-postgresql/.repo/terraform/infra/main.tf b/templates/todo/projects/java-postgresql/.repo/terraform/infra/main.tf index 3ab8039ca6d..7cd652f8c1a 100644 --- a/templates/todo/projects/java-postgresql/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/java-postgresql/.repo/terraform/infra/main.tf @@ -82,7 +82,7 @@ module "web" { app_settings = { "SCM_DO_BUILD_DURING_DEPLOYMENT" = "false" "REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING" = module.applicationinsights.APPLICATIONINSIGHTS_CONNECTION_STRING - "REACT_APP_API_BASE_URL" = "https://app-api-${local.resource_token}.azurewebsites.net" + "REACT_APP_API_BASE_URL" = module.api.URI } app_command_line = "./entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa" 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 b8803240c81..eb7f677f1ef 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 @@ -31,6 +31,9 @@ param webAppExists bool = false @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -151,6 +154,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.parameters.json index 8ddb71e6e8e..675a89c4c01 100644 --- a/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/nodejs-mongo-aca/.repo/bicep/infra/main.parameters.json @@ -22,6 +22,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file diff --git a/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/azure.yaml b/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/azure.yaml index 40eafba2ef7..f9b07ea8e2f 100644 --- a/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/azure.yaml +++ b/templates/todo/projects/nodejs-mongo-aks/.repo/bicep/azure.yaml @@ -11,8 +11,12 @@ services: host: aks hooks: postdeploy: - shell: sh - run: azd env set REACT_APP_WEB_BASE_URL ${SERVICE_WEB_ENDPOINT_URL} + windows: + shell: pwsh + run: azd env set REACT_APP_WEB_BASE_URL $env:SERVICE_WEB_ENDPOINT_URL + posix: + shell: sh + run: azd env set REACT_APP_WEB_BASE_URL ${SERVICE_WEB_ENDPOINT_URL} api: project: ../../api/js language: js @@ -22,5 +26,9 @@ services: relativePath: api hooks: postdeploy: - shell: sh - run: azd env set REACT_APP_API_BASE_URL ${SERVICE_API_ENDPOINT_URL} \ No newline at end of file + windows: + shell: pwsh + run: azd env set REACT_APP_API_BASE_URL $env:SERVICE_API_ENDPOINT_URL + posix: + shell: sh + run: azd env set REACT_APP_API_BASE_URL ${SERVICE_API_ENDPOINT_URL} \ No newline at end of file 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 d5bd0dd463e..c4284419485 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 @@ -29,6 +29,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' diff --git a/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.parameters.json index 1b12cb32a96..af7f6f2cd1a 100644 --- a/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/nodejs-mongo-swa-func/.repo/bicep/infra/main.parameters.json @@ -13,6 +13,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 18fdf994545..1769518f027 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.bicep @@ -28,6 +28,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -156,6 +159,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.parameters.json index 1b12cb32a96..af7f6f2cd1a 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/nodejs-mongo/.repo/bicep/infra/main.parameters.json @@ -13,6 +13,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file diff --git a/templates/todo/projects/nodejs-mongo/.repo/terraform/OPTIONAL_FEATURES.md b/templates/todo/projects/nodejs-mongo/.repo/terraform/OPTIONAL_FEATURES.md index 41db2723804..830ccdb980a 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/terraform/OPTIONAL_FEATURES.md +++ b/templates/todo/projects/nodejs-mongo/.repo/terraform/OPTIONAL_FEATURES.md @@ -9,6 +9,13 @@ To use APIM on this template you just need to set the environment variable with ```bash azd env set USE_APIM true ``` + +The default SKU is `Consumption` but you can change it by setting the `APIM_SKU` environment variable: + +```bash +azd env set APIM_SKU Standard +``` + And then execute `azd up` to provision and deploy. No worries if you already did `azd up`! You can set the `USE_APIM` environment variable at anytime and then just repeat the `azd up` command to run the incremental deployment. Here's the high level architecture diagram when APIM is used: diff --git a/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tf b/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tf index 1c6ffe58b50..a4acef9e61e 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tf @@ -102,7 +102,7 @@ module "web" { app_settings = { "SCM_DO_BUILD_DURING_DEPLOYMENT" = "false" "REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING" = module.applicationinsights.APPLICATIONINSIGHTS_CONNECTION_STRING - "REACT_APP_API_BASE_URL" = "https://app-api-${local.resource_token}.azurewebsites.net" + "REACT_APP_API_BASE_URL" = module.api.URI } app_command_line = "./entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa" @@ -136,6 +136,17 @@ module "api" { }] } +# Workaround: set API_ALLOW_ORIGINS to the web app URI +resource "null_resource" "api_set_allow_origins" { + triggers = { + web_uri = module.web.URI + } + + provisioner "local-exec" { + command = "az webapp config appsettings set --resource-group ${azurerm_resource_group.rg.name} --name ${module.api.APPSERVICE_NAME} --settings API_ALLOW_ORIGINS=${module.web.URI}" + } +} + # ------------------------------------------------------------------------------------------------------ # Deploy app service apim # ------------------------------------------------------------------------------------------------------ @@ -147,7 +158,7 @@ module "apim" { rg_name = azurerm_resource_group.rg.name tags = merge(local.tags, { "azd-service-name" : var.environment_name }) application_insights_name = module.applicationinsights.APPLICATIONINSIGHTS_NAME - sku = "Consumption" + sku = var.apimSKU } # ------------------------------------------------------------------------------------------------------ diff --git a/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tfvars.json b/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tfvars.json index ba3972d6ad6..1f4002bcd34 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tfvars.json +++ b/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/main.tfvars.json @@ -2,5 +2,6 @@ "location": "${AZURE_LOCATION}", "environment_name": "${AZURE_ENV_NAME}", "principal_id": "${AZURE_PRINCIPAL_ID}", - "useAPIM" : "${USE_APIM=false}" + "useAPIM" : "${USE_APIM=false}", + "apimSKU": "${APIM_SKU=Consumption}" } diff --git a/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/variables.tf b/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/variables.tf index 81af85dbeb6..b5bcc1af76a 100644 --- a/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/variables.tf +++ b/templates/todo/projects/nodejs-mongo/.repo/terraform/infra/variables.tf @@ -19,3 +19,9 @@ variable "useAPIM" { type = bool default = false } + +variable "apimSKU" { + description = "Azure API Management SKU. Only used if useAPIM is true." + type = string + default = "Consumption" +} \ No newline at end of file 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 fb9a4a0292e..54ec97e9fd5 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 @@ -31,6 +31,9 @@ param webAppExists bool = false @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -151,6 +154,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.parameters.json index 8ddb71e6e8e..675a89c4c01 100644 --- a/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/python-mongo-aca/.repo/bicep/infra/main.parameters.json @@ -22,6 +22,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 ae6e81e7fe5..1ece762da0b 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 @@ -29,6 +29,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -156,6 +159,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.parameters.json index 1b12cb32a96..af7f6f2cd1a 100644 --- a/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/python-mongo-swa-func/.repo/bicep/infra/main.parameters.json @@ -13,6 +13,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file 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 85c31ba81db..058b6faa75a 100644 --- a/templates/todo/projects/python-mongo/.repo/bicep/infra/main.bicep +++ b/templates/todo/projects/python-mongo/.repo/bicep/infra/main.bicep @@ -28,6 +28,9 @@ param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') param useAPIM bool = false +@description('API Management SKU to use if APIM is enabled') +param apimSku string = 'Consumption' + @description('Id of the user or app to assign application roles') param principalId string = '' @@ -156,6 +159,7 @@ module apim '../../../../../../common/infra/bicep/core/gateway/apim.bicep' = if scope: rg params: { name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}' + sku: apimSku location: location tags: tags applicationInsightsName: monitoring.outputs.applicationInsightsName diff --git a/templates/todo/projects/python-mongo/.repo/bicep/infra/main.parameters.json b/templates/todo/projects/python-mongo/.repo/bicep/infra/main.parameters.json index 1b12cb32a96..af7f6f2cd1a 100644 --- a/templates/todo/projects/python-mongo/.repo/bicep/infra/main.parameters.json +++ b/templates/todo/projects/python-mongo/.repo/bicep/infra/main.parameters.json @@ -13,6 +13,9 @@ }, "useAPIM": { "value": "${USE_APIM=false}" + }, + "apimSku": { + "value": "${APIM_SKU=Consumption}" } } } \ No newline at end of file diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf index 0599630ae8d..e7f814db0cb 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf @@ -103,7 +103,7 @@ module "web" { app_settings = { "SCM_DO_BUILD_DURING_DEPLOYMENT" = "false" "REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING" = module.applicationinsights.APPLICATIONINSIGHTS_CONNECTION_STRING - "REACT_APP_API_BASE_URL" = "https://app-api-${local.resource_token}.azurewebsites.net" + "REACT_APP_API_BASE_URL" = module.api.URI } app_command_line = "./entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa" @@ -127,7 +127,6 @@ module "api" { "SCM_DO_BUILD_DURING_DEPLOYMENT" = "true" "AZURE_KEY_VAULT_ENDPOINT" = module.keyvault.AZURE_KEY_VAULT_ENDPOINT "APPLICATIONINSIGHTS_CONNECTION_STRING" = module.applicationinsights.APPLICATIONINSIGHTS_CONNECTION_STRING - "API_ALLOW_ORIGINS" = "https://app-web-${local.resource_token}.azurewebsites.net" } app_command_line = local.api_command_line @@ -136,6 +135,17 @@ module "api" { }] } +# Workaround: set API_ALLOW_ORIGINS to the web app URI +resource "null_resource" "api_set_allow_origins" { + triggers = { + web_uri = module.web.URI + } + + provisioner "local-exec" { + command = "az webapp config appsettings set --resource-group ${azurerm_resource_group.rg.name} --name ${module.api.APPSERVICE_NAME} --settings API_ALLOW_ORIGINS=${module.web.URI}" + } +} + # ------------------------------------------------------------------------------------------------------ # Deploy app service apim # ------------------------------------------------------------------------------------------------------ @@ -147,7 +157,7 @@ module "apim" { rg_name = azurerm_resource_group.rg.name tags = merge(local.tags, { "azd-service-name" : var.environment_name }) application_insights_name = module.applicationinsights.APPLICATIONINSIGHTS_NAME - sku = "Consumption" + sku = var.apimSKU } # ------------------------------------------------------------------------------------------------------ diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tfvars.json b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tfvars.json index ba3972d6ad6..1f4002bcd34 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tfvars.json +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tfvars.json @@ -2,5 +2,6 @@ "location": "${AZURE_LOCATION}", "environment_name": "${AZURE_ENV_NAME}", "principal_id": "${AZURE_PRINCIPAL_ID}", - "useAPIM" : "${USE_APIM=false}" + "useAPIM" : "${USE_APIM=false}", + "apimSKU": "${APIM_SKU=Consumption}" } diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/variables.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/variables.tf index 81af85dbeb6..6b0b0446486 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/variables.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/variables.tf @@ -19,3 +19,9 @@ variable "useAPIM" { type = bool default = false } + +variable "apimSKU" { + description = "Azure API Management SKU. Only used if useAPIM is true." + type = string + default = "Consumption" +}