{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "metadata": { "description": "Location for the resources" } }, "functionAppName": { "type": "string", "defaultValue": "[concat('datadog-functionapp-', newGuid())]", "metadata": { "description": "The name of the function app." } }, "eventhubName": { "type": "string", "defaultValue": "datadog-eventhub", "metadata": { "description": "The name of the eventhub." } }, "eventhubNamespace": { "type": "string", "metadata": { "description": "The name of the eventhub namespace." } }, "functionPackageUri": { "type": "string", "metadata": { "description": "Code (packaged into a .zip) for the function to run" } }, "apiKey": { "type": "securestring", "metadata": { "description": "Datadog API key" } }, "datadogTags": { "type": "string", "defaultValue": "", "metadata": { "description": "Comma-separated list of tags" } }, "datadogSite": { "type": "string", "defaultValue": "datadoghq.com", "metadata": { "description": "Datadog site to send logs" } }, "endpointSuffix": { "type": "string", "defaultValue": "core.windows.net", "metadata": { "description": "Endpoint suffix for storage account" } } }, "variables": { "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'storageacct')]", "eventHubAuthRule": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', parameters('eventhubNamespace'),'RootManageSharedAccessKey')]" }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2023-05-01", "name": "[variables('storageAccountName')]", "location": "[parameters('location')]", "kind": "StorageV2", "sku": { "name": "Standard_LRS" }, "properties": { "minimumTlsVersion": "TLS1_2", "supportsHttpsTrafficOnly": true, "allowBlobPublicAccess": false } }, { "apiVersion": "2024-04-01", "type": "Microsoft.Web/sites", "name": "[parameters('functionAppName')]", "location": "[parameters('location')]", "kind": "functionapp", "dependsOn": [ "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]" ], "properties": { "name": "[parameters('functionAppName')]", "clientAffinityEnabled": false, "httpsOnly": true, "siteConfig": { "cors": { "allowedOrigins": [ "*" ] }, "appSettings": [ { "name": "FUNCTIONS_EXTENSION_VERSION", "value": "~4" }, { "name": "DD_API_KEY", "value": "[parameters('apiKey')]" }, { "name": "DD_SITE", "value": "[parameters('datadogSite')]" }, { "name": "DD_TAGS", "value": "[parameters('datadogTags')]" }, { "name": "AzureWebJobsStorage", "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2018-11-01').keys[0].value,';','EndpointSuffix=',parameters('endpointSuffix'),';')]" }, { "name": "FUNCTIONS_WORKER_RUNTIME", "value": "node" }, { "name": "EVENTHUB_NAME", "value": "[parameters('eventhubName')]" }, { "name": "EVENTHUB_CONNECTION_STRING", "value": "[listKeys(variables('eventHubAuthRule'),'2017-04-01').primaryConnectionString]" }, { "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2018-11-01').keys[0].value,';','EndpointSuffix=',parameters('endpointSuffix'),';')]" }, { "name": "WEBSITE_CONTENTSHARE", "value": "[toLower(parameters('functionAppName'))]" }, { "name": "WEBSITE_NODE_DEFAULT_VERSION", "value": "~20" }, { "name": "SCM_DO_BUILD_DURING_DEPLOYMENT", "value": "true" } ] } } }, { "type": "Microsoft.Web/sites/extensions", "apiVersion": "2021-02-01", "name": "[concat(parameters('functionAppName'), '/zipdeploy')]", "properties": { "packageUri": "[parameters('functionPackageUri')]" }, "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]" ] }, { "type": "Microsoft.ManagedIdentity/userAssignedIdentities", "apiVersion": "2023-01-31", "name": "[concat('syncFunctionTriggers-', parameters('functionAppName'), '-identity')]", "location": "[parameters('location')]" }, { "type": "Microsoft.Authorization/roleAssignments", "apiVersion": "2022-04-01", "name": "[guid('syncFunctionTriggers-', parameters('functionAppName'))]", "properties": { "roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', 'de139f84-1756-47ae-9be6-808fbbe84772')]", "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', concat('syncFunctionTriggers-', parameters('functionAppName'), '-identity')), '2023-01-31').principalId]", "principalType": "ServicePrincipal" }, "dependsOn": [ "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', concat('syncFunctionTriggers-', parameters('functionAppName'), '-identity'))]" ] }, { "type": "Microsoft.Resources/deploymentScripts", "apiVersion": "2023-08-01", "name": "[concat('syncFunctionTriggers-', parameters('functionAppName'))]", "location": "[parameters('location')]", "kind": "AzureCLI", "identity": { "type": "UserAssigned", "userAssignedIdentities": { "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', concat('syncFunctionTriggers-', parameters('functionAppName'), '-identity'))]": {} } }, "properties": { "azCliVersion": "2.67.0", "scriptContent": "[format('az rest --url ''{0}{1}/syncfunctiontriggers?api-version=2024-04-01'' --method post', environment().resourceManager, resourceId('Microsoft.Web/sites', parameters('functionAppName')))]", "timeout": "PT30M", "cleanupPreference": "OnSuccess", "retentionInterval": "P1D", "storageAccountSettings": { "storageAccountName": "[variables('storageAccountName')]", "storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value]" } }, "dependsOn": [ "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', concat('syncFunctionTriggers-', parameters('functionAppName'), '-identity'))]", "[resourceId('Microsoft.Web/sites/extensions', parameters('functionAppName'), 'zipdeploy')]" ] } ] }