Get Azure Function keys from an Azure Function at deployment time?

后端 未结 5 1273
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 14:41

I\'m sending an email in Azure Functions using the SendGrid bindings. As part of the contents of that email, I\'d like to include a link to one of the HTTP methods in the Azure

5条回答
  •  庸人自扰
    2021-02-06 15:16

    To do this in a CI pipeline using ARM templates you need to ensure you key vault and function up are in the same resource group.

    1. Deploy your function app using ARM
    2. Deploy the function to the function app - update this code to look for the key from keyvault as you've mentioned you do for your SendGrid API Key
    3. Run the below as an ARM template ensuring it is run as incremental. This will get the key from the named function and put it into the desired key vault.

      {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
              "functionAppName":: {
                  "type": "string",
                  "metadata": {
                      "description": "The name of the function app that you wish to get the key from."
                  }
              },
              "functionName": {
                  "type": "string",
                  "metadata": {
                       "description": "The name of the function that you wish to get the key from."
                }
              },
              "keyVaultName": {
                  "type": "string",
                  "metadata": {
                      "description": "The name of the key vault you wish to put the key in."
                  }
              }
          },
          "variables": {
              "functionAppName": "[parameters('functionAppName')]",
              "keyVaultName": "[parameters('keyVaultName')]",
              "functionName": "[parameters('functionName')]"
          },
          "resources": [
              {
                  "type": "Microsoft.KeyVault/vaults/secrets",
                  "name": "[concat(variables('keyVaultName'),'/', variables('functionAppName'))]",
                  "apiVersion": "2015-06-01",
                  "properties": {
                      "contentType": "text/plain",
                      "value": "[listsecrets(resourceId('Microsoft.Web/sites/functions', variables('functionAppName'),  variables('functionName'),'2015-08-01').key]"
                  },
                  "dependsOn": []
              }
          ]
      }
      

提交回复
热议问题