【问题标题】:Azure App Configuration: Getting PrimaryKey in a arm templateAzure 应用程序配置:在 arm 模板中获取主键
【发布时间】:2020-03-25 21:32:04
【问题描述】:

我已提取属于 Azure App Configuration 预览版的 ARM 模板,并将其设置到我们的 IaC 存储库中 - 到目前为止一切顺利。

我们的下一个合乎逻辑的步骤是将 AppConfiguration.PrimaryKey 插入到我们的 Key Vault 中。但是我不知道该物业的名称,也无法在网上找到有关该主题的任何信息。此外,我看不到 resources.azure.com 中列出的 AppConfiguration/configurationStores 类型(假设它仍然是公共预览版)。

有谁知道如何引用主键(可能还有只读主键),所以我可以通过 arm 模板中的“输出”变量来引用它们?

然后我可以让 Az Cli/Az Powershell 将秘密插入我们的 Key Vault,我们就可以完全自动化 IaC

【问题讨论】:

    标签: azure arm-template azure-app-configuration


    【解决方案1】:

    我想不通。

    但是,通过在 IaC 脚本中使用 az cli 命令(无论如何都会调用驻留在 azure blob 存储中的 arm 模板),我绕过了这个问题:

    $connStrings = az appconfig credential list -n $configName| ConvertFrom-Json 
    $readOnlyConnString = ($connStrings | Where {$_.name -eq "Primary Read Only"}).connectionString
    $primaryConnString = ($connStrings | Where {$_.name -eq "Primary"}).connectionString
    
    #then
    
    az keyvault secret set --vault-name $kvName --name $keyNameRO --value $readOnlyConnString
    az keyvault secret set --vault-name $kvName --name $keyNamePrimary --value $primaryConnString
    

    【讨论】:

      【解决方案2】:

      对于 ARM 模板,我执行了以下操作。 listkeys 函数返回与键有关的所有值的完整列表。这很难弄清楚。希望对你有帮助。

      {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
          "configurationStores_instance_name": {
              "defaultValue": "ac-instance",
              "type": "String"
          }
      },
      "variables": {
          "apiVersionVar": "[providers('Microsoft.AppConfiguration', 'configurationStores').apiVersions[0]]",
          "resourceId": "[resourceId('Microsoft.AppConfiguration/configurationStores', parameters('configurationStores_instance_name'))]",
      },
      "resources": [
          {
              "type": "Microsoft.AppConfiguration/configurationStores",
              "apiVersion": "2019-10-01",
              "name": "[parameters('configurationStores_instance_name')]",
              "location": "northcentralus",
              "sku": {
                  "name": "standard"
              },
              "properties": {}
          }
      ],
      "outputs": {
          "AppConfigEndpoint": {
              "type": "string",
              "value": "[reference(parameters('configurationStores_instance_name')).endpoint]"
          },
          "AppConfigKeys": {
              "type": "Array",
              "value": "[listkeys(variables('resourceId'), variables('apiVersionVar')).value]"
          }
      }
      

      }

      希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-12
        • 2021-01-31
        • 2017-08-07
        • 1970-01-01
        • 2020-08-23
        • 2020-09-29
        相关资源
        最近更新 更多