Skip to content

Commit

Permalink
Improvement App Insights connection string format (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Feb 2, 2025
1 parent 1b70a9a commit 345ac4a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
DOTNET_VERSION: 6.0.x
BICEP_VERSION: 0.28.1
BICEP_VERSION: 0.33.93

jobs:
build:
Expand Down
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.28.1
BICEP_VERSION: 0.33.93

jobs:
publish:
Expand Down
11 changes: 3 additions & 8 deletions azuredeploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,11 @@ var appInsightsName = 'appi-${appNamePrefix}-${substring(uniqueString(resourceGr
var workspaceName = 'log-${appNamePrefix}-${substring(uniqueString(resourceGroup().id, deployment().name), 0, 4)}'
var storageAccountName = 'st${uniqueString(resourceGroup().id, deployment().name)}func'
var keyVaultName = 'kv-${appNamePrefix}-${substring(uniqueString(resourceGroup().id, deployment().name), 0, 4)}'
var appInsightsEndpoints = {
AzureCloud: 'applicationinsights.azure.com'
AzureChinaCloud: 'applicationinsights.azure.cn'
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]}'
value: appInsights.properties.ConnectionString
}
{
name: 'AzureWebJobsStorage'
Expand Down Expand Up @@ -115,7 +110,7 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
}
}

resource appServicePlan 'Microsoft.Web/serverfarms@2023-12-01' = {
resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = {
name: appServicePlanName
location: location
sku: {
Expand Down Expand Up @@ -149,7 +144,7 @@ resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
}
}

resource functionApp 'Microsoft.Web/sites@2023-12-01' = {
resource functionApp 'Microsoft.Web/sites@2024-04-01' = {
name: functionAppName
location: location
kind: 'functionapp'
Expand Down
21 changes: 8 additions & 13 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.28.1.47646",
"templateHash": "14872192790547142580"
"version": "0.33.93.31351",
"templateHash": "880883213041086321"
}
},
"parameters": {
Expand Down Expand Up @@ -87,11 +87,6 @@
"workspaceName": "[format('log-{0}-{1}', parameters('appNamePrefix'), substring(uniqueString(resourceGroup().id, deployment().name), 0, 4))]",
"storageAccountName": "[format('st{0}func', uniqueString(resourceGroup().id, deployment().name))]",
"keyVaultName": "[format('kv-{0}-{1}', parameters('appNamePrefix'), substring(uniqueString(resourceGroup().id, deployment().name), 0, 4))]",
"appInsightsEndpoints": {
"AzureCloud": "applicationinsights.azure.com",
"AzureChinaCloud": "applicationinsights.azure.cn",
"AzureUSGovernment": "applicationinsights.us"
},
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions/', 'a4417e6f-fecd-4de8-b567-7b0420556985')]"
},
"resources": [
Expand All @@ -112,7 +107,7 @@
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-12-01",
"apiVersion": "2024-04-01",
"name": "[variables('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
Expand Down Expand Up @@ -152,7 +147,7 @@
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-12-01",
"apiVersion": "2024-04-01",
"name": "[variables('functionAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp",
Expand All @@ -164,7 +159,7 @@
"httpsOnly": true,
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
"siteConfig": {
"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')), '2023-05-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')), '2023-05-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_INPROC_NET8_ENABLED', 'value', '1'), 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'))]",
"appSettings": "[concat(createArray(createObject('name', 'APPLICATIONINSIGHTS_CONNECTION_STRING', 'value', reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2020-02-02').ConnectionString), createObject('name', 'AzureWebJobsStorage', 'value', format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};EndpointSuffix={2}', variables('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2023-05-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')), '2023-05-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_INPROC_NET8_ENABLED', 'value', '1'), 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": "v8.0",
"ftpsState": "Disabled",
"minTlsVersion": "1.2",
Expand Down Expand Up @@ -206,7 +201,7 @@
"name": "[guid(resourceId('Microsoft.KeyVault/vaults', variables('keyVaultName')), variables('functionAppName'), variables('roleDefinitionId'))]",
"properties": {
"roleDefinitionId": "[variables('roleDefinitionId')]",
"principalId": "[reference(resourceId('Microsoft.Web/sites', variables('functionAppName')), '2023-12-01', 'full').identity.principalId]",
"principalId": "[reference(resourceId('Microsoft.Web/sites', variables('functionAppName')), '2024-04-01', 'full').identity.principalId]",
"principalType": "ServicePrincipal"
},
"dependsOn": [
Expand All @@ -222,11 +217,11 @@
},
"principalId": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Web/sites', variables('functionAppName')), '2023-12-01', 'full').identity.principalId]"
"value": "[reference(resourceId('Microsoft.Web/sites', variables('functionAppName')), '2024-04-01', 'full').identity.principalId]"
},
"tenantId": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Web/sites', variables('functionAppName')), '2023-12-01', 'full').identity.tenantId]"
"value": "[reference(resourceId('Microsoft.Web/sites', variables('functionAppName')), '2024-04-01', 'full').identity.tenantId]"
},
"keyVaultName": {
"type": "string",
Expand Down

0 comments on commit 345ac4a

Please sign in to comment.