【问题标题】:Azure Deployment - Overide parameter with ARM functionsAzure 部署 - 使用 ARM 函数覆盖参数
【发布时间】:2018-12-13 00:03:27
【问题描述】:

我正在使用 VSTS 来部署 Azure 资源。 我使用任务“Azure 资源组部署”来部署 ARM 模板。 对于特定参数,如何使用 ARM 函数(concat、listkeys 等)覆盖该值?

示例:我的 ARM 模板有一个参数是存储帐户密钥,而不是直接提供密钥,我想通过传递 [listkeys(...)] 来提供它

【问题讨论】:

    标签: azure deployment


    【解决方案1】:

    您不能这样做,几个函数(如listKeys())仅在运行时进行评估。我不知道您要实现什么目标,因此可能有一些方法可以实现您要实现的目标。

    如果要隐藏密钥,可以将它们存储在 Key Vault 中并在部署时检索:

    "password": {
        "reference": {
            "keyVault": {
                "id": "[resourceId('kvGroup', 'Microsoft.KeyVault/vaults', 'kvName')]"
            },
            "secretName": "secret"
        }
    },
    

    【讨论】:

    • 我试图“隐藏”密钥,并试图避免使用 powershell 创建参数。看来我唯一的选择是使用 powershell。
    • 你总是可以在模板中使用 listKeys (是什么阻止你这样做)?
    • 没什么,我只是想看看这是否可行。谢谢。
    【解决方案2】:

    如果存储帐户不是在同一个 ARM 模板中创建的,我将使用参数提供存储帐户的名称,然后在 ARM 模板中使用 listkeys() 来获取存储帐户连接字符串。

    如果您在管道中的先前 ARM 模板部署中创建存储帐户,您可以use output parameters to make the connection string available in the pipeline。以下是xxx 代表您的公司命名前缀的示例:

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "environment": {
          "type": "string",
          "defaultValue": "d",
          "metadata": {
            "description": "The deployment environment, given by develop (d), testing (t), production (p) or quality assurance (q)"
          }
        }
      },
      "variables": {
        "busUnit": "vendor_name_here",
    
        //storage account names must be lowercase and are limited to 24 alpha numeric characters
        "storage_account_name": "[concat('xxx', parameters('environment'), variables('busUnit'), 'stor')]"        
      },
      "resources": [
        {
          "type": "Microsoft.Storage/storageAccounts",
          "sku": {
            "name": "Standard_LRS", //this is a hard coded SKU
            "tier": "Standard" //general purpose versus blob-only
          },
          "kind": "Storage", 
          "name": "[variables('storage_account_name')]",
          "apiVersion": "2017-06-01",
          "location": "[resourceGroup().location]", //add it to the same region/location as the resource group
          "properties": {
            "encryption": {
              "keySource": "Microsoft.Storage",
              "services": {
                "blob": {
                  "enabled": true
                }
              }
            },
            "networkAcls": {
              "bypass": "AzureServices",
              "defaultAction": "Allow",
              "ipRules": [],
              "virtualNetworkRules": []
            }
          },
          "dependsOn": []
        }
      ],
      "outputs": {
        "storageAccountKey": {
          //"description": "This works if the storage account is in the same resource group. It returns the access key for the account",
          "type": "securestring",
          "value": "[listKeys(variables('storage_account_name'),'2015-05-01-preview').key1]"
        },
        "storageAccountName": {
          //"description": "This is the computed name of the storage account, based on naming conventions in the variables",
          "type": "string",
          "value": "[variables('storage_account_name')]"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多