From bed5a562ab907d998abbb75de7633acea9e008ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Fiuman=C3=B2?= Date: Mon, 19 Jun 2023 08:15:08 +0100 Subject: [PATCH] Add additionalAppSettings parameter to the bicep module (#547) * Add additionalAppSettings parameter to the bicep module * Update azuredeploy.bicep * Update azuredeploy.json * Update build.yml * Update publish.yml * Update azuredeploy.json * Fixed bicep linter error --------- Co-authored-by: Antonio Co-authored-by: Tatsuro Shibamura --- .github/workflows/publish.yml | 2 +- azuredeploy.bicep | 96 ++++++++++++++++++----------------- azuredeploy.json | 56 ++++---------------- 3 files changed, 60 insertions(+), 94 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 62127967..c1edd986 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: env: DOTNET_VERSION: 6.0.x - BICEP_VERSION: 0.15.31 + BICEP_VERSION: 0.18.4 jobs: publish: diff --git a/azuredeploy.bicep b/azuredeploy.bicep index 8e103cfd..c9cdac57 100644 --- a/azuredeploy.bicep +++ b/azuredeploy.bicep @@ -33,6 +33,9 @@ param keyVaultSkuName string = 'standard' @description('Enter the base URL of an existing Key Vault. (ex. https://example.vault.azure.net)') param keyVaultBaseUrl string = '' +@description('Specifies additional name/value pairs to be appended to the functionap app appsettings.') +param additionalAppSettings array = [] + var functionAppName = 'func-${appNamePrefix}-${substring(uniqueString(resourceGroup().id, deployment().name), 0, 4)}' var appServicePlanName = 'plan-${appNamePrefix}-${substring(uniqueString(resourceGroup().id, deployment().name), 0, 4)}' var appInsightsName = 'appi-${appNamePrefix}-${substring(uniqueString(resourceGroup().id, deployment().name), 0, 4)}' @@ -45,6 +48,52 @@ var appInsightsEndpoints = { AzureUSGovernment: 'applicationinsights.us' } var roleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions/', 'a4417e6f-fecd-4de8-b567-7b0420556985') +var acmebotAppSettings = [ + { + name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' + value: 'InstrumentationKey=${appInsights.properties.InstrumentationKey};EndpointSuffix=${appInsightsEndpoints[environment().name]}' + } + { + name: 'AzureWebJobsStorage' + value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value};EndpointSuffix=${environment().suffixes.storage}' + } + { + name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' + value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value};EndpointSuffix=${environment().suffixes.storage}' + } + { + name: 'WEBSITE_CONTENTSHARE' + value: toLower(functionAppName) + } + { + name: 'WEBSITE_RUN_FROM_PACKAGE' + value: 'https://stacmebotprod.blob.core.windows.net/keyvault-acmebot/v4/latest.zip' + } + { + name: 'FUNCTIONS_EXTENSION_VERSION' + value: '~4' + } + { + name: 'FUNCTIONS_WORKER_RUNTIME' + value: 'dotnet' + } + { + name: 'Acmebot:Contacts' + value: mailAddress + } + { + name: 'Acmebot:Endpoint' + value: acmeEndpoint + } + { + name: 'Acmebot:VaultBaseUrl' + value: (createWithKeyVault ? 'https://${keyVaultName}${environment().suffixes.keyvaultDns}' : keyVaultBaseUrl) + } + { + name: 'Acmebot:Environment' + value: environment().name + } +] resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = { name: storageAccountName @@ -106,52 +155,7 @@ resource functionApp 'Microsoft.Web/sites@2022-03-01' = { httpsOnly: true serverFarmId: appServicePlan.id siteConfig: { - appSettings: [ - { - name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' - value: 'InstrumentationKey=${appInsights.properties.InstrumentationKey};EndpointSuffix=${appInsightsEndpoints[environment().name]}' - } - { - name: 'AzureWebJobsStorage' - value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value};EndpointSuffix=${environment().suffixes.storage}' - } - { - name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' - value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value};EndpointSuffix=${environment().suffixes.storage}' - } - { - name: 'WEBSITE_CONTENTSHARE' - value: toLower(functionAppName) - } - { - name: 'WEBSITE_RUN_FROM_PACKAGE' - value: 'https://stacmebotprod.blob.core.windows.net/keyvault-acmebot/v4/latest.zip' - } - { - name: 'FUNCTIONS_EXTENSION_VERSION' - value: '~4' - } - { - name: 'FUNCTIONS_WORKER_RUNTIME' - value: 'dotnet' - } - { - name: 'Acmebot:Contacts' - value: mailAddress - } - { - name: 'Acmebot:Endpoint' - value: acmeEndpoint - } - { - name: 'Acmebot:VaultBaseUrl' - value: (createWithKeyVault ? 'https://${keyVaultName}${environment().suffixes.keyvaultDns}' : keyVaultBaseUrl) - } - { - name: 'Acmebot:Environment' - value: environment().name - } - ] + appSettings: concat(acmebotAppSettings, additionalAppSettings) netFrameworkVersion: 'v6.0' ftpsState: 'Disabled' minTlsVersion: '1.2' diff --git a/azuredeploy.json b/azuredeploy.json index d613feb8..2442de4b 100644 --- a/azuredeploy.json +++ b/azuredeploy.json @@ -5,7 +5,7 @@ "_generator": { "name": "bicep", "version": "0.18.4.5664", - "templateHash": "9826976639435610874" + "templateHash": "6843255573517711123" } }, "parameters": { @@ -69,6 +69,13 @@ "metadata": { "description": "Enter the base URL of an existing Key Vault. (ex. https://example.vault.azure.net)" } + }, + "additionalAppSettings": { + "type": "array", + "defaultValue": [], + "metadata": { + "description": "Specifies additional name/value pairs to be appended to the functionap app appsettings." + } } }, "variables": { @@ -155,52 +162,7 @@ "httpsOnly": true, "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]", "siteConfig": { - "appSettings": [ - { - "name": "APPLICATIONINSIGHTS_CONNECTION_STRING", - "value": "[format('InstrumentationKey={0};EndpointSuffix={1}', reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2020-02-02').InstrumentationKey, variables('appInsightsEndpoints')[environment().name])]" - }, - { - "name": "AzureWebJobsStorage", - "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};EndpointSuffix={2}', variables('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2022-09-01').keys[0].value, environment().suffixes.storage)]" - }, - { - "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", - "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};EndpointSuffix={2}', variables('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2022-09-01').keys[0].value, environment().suffixes.storage)]" - }, - { - "name": "WEBSITE_CONTENTSHARE", - "value": "[toLower(variables('functionAppName'))]" - }, - { - "name": "WEBSITE_RUN_FROM_PACKAGE", - "value": "https://stacmebotprod.blob.core.windows.net/keyvault-acmebot/v4/latest.zip" - }, - { - "name": "FUNCTIONS_EXTENSION_VERSION", - "value": "~4" - }, - { - "name": "FUNCTIONS_WORKER_RUNTIME", - "value": "dotnet" - }, - { - "name": "Acmebot:Contacts", - "value": "[parameters('mailAddress')]" - }, - { - "name": "Acmebot:Endpoint", - "value": "[parameters('acmeEndpoint')]" - }, - { - "name": "Acmebot:VaultBaseUrl", - "value": "[if(parameters('createWithKeyVault'), format('https://{0}{1}', variables('keyVaultName'), environment().suffixes.keyvaultDns), parameters('keyVaultBaseUrl'))]" - }, - { - "name": "Acmebot:Environment", - "value": "[environment().name]" - } - ], + "appSettings": "[concat(createArray(createObject('name', 'APPLICATIONINSIGHTS_CONNECTION_STRING', 'value', format('InstrumentationKey={0};EndpointSuffix={1}', reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2020-02-02').InstrumentationKey, variables('appInsightsEndpoints')[environment().name])), createObject('name', 'AzureWebJobsStorage', 'value', format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};EndpointSuffix={2}', variables('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2022-09-01').keys[0].value, environment().suffixes.storage)), createObject('name', 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING', 'value', format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};EndpointSuffix={2}', variables('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2022-09-01').keys[0].value, environment().suffixes.storage)), createObject('name', 'WEBSITE_CONTENTSHARE', 'value', toLower(variables('functionAppName'))), createObject('name', 'WEBSITE_RUN_FROM_PACKAGE', 'value', 'https://stacmebotprod.blob.core.windows.net/keyvault-acmebot/v4/latest.zip'), createObject('name', 'FUNCTIONS_EXTENSION_VERSION', 'value', '~4'), createObject('name', 'FUNCTIONS_WORKER_RUNTIME', 'value', 'dotnet'), createObject('name', 'Acmebot:Contacts', 'value', parameters('mailAddress')), createObject('name', 'Acmebot:Endpoint', 'value', parameters('acmeEndpoint')), createObject('name', 'Acmebot:VaultBaseUrl', 'value', if(parameters('createWithKeyVault'), format('https://{0}{1}', variables('keyVaultName'), environment().suffixes.keyvaultDns), parameters('keyVaultBaseUrl'))), createObject('name', 'Acmebot:Environment', 'value', environment().name)), parameters('additionalAppSettings'))]", "netFrameworkVersion": "v6.0", "ftpsState": "Disabled", "minTlsVersion": "1.2",