Skip to content

Commit

Permalink
Add additionalAppSettings parameter to the bicep module (#547)
Browse files Browse the repository at this point in the history
* 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 <antonio@delli.market>
Co-authored-by: Tatsuro Shibamura <me@shibayan.jp>
  • Loading branch information
3 people authored Jun 19, 2023
1 parent c880521 commit bed5a56
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
DOTNET_VERSION: 6.0.x
BICEP_VERSION: 0.15.31
BICEP_VERSION: 0.18.4

jobs:
publish:
Expand Down
96 changes: 50 additions & 46 deletions azuredeploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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)}'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down
56 changes: 9 additions & 47 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "0.18.4.5664",
"templateHash": "9826976639435610874"
"templateHash": "6843255573517711123"
}
},
"parameters": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit bed5a56

Please sign in to comment.