【问题标题】:Using Variables in ested Azure ARM Templates在 ested Azure ARM 模板中使用变量
【发布时间】:2019-09-17 21:32:45
【问题描述】:

我想部署一个嵌套的 azure arm 模板,我需要提示如何重用主模板中定义的变量。

在 azuredeploy.json 中,我声明了一些要在模板中使用的变量。


   "variables": {
        "nestedtemplateUriStorage": "[uri(parameters('_artifactsLocation'), concat('nestedtemplates/storage.json', parameters('_artifactsLocationSasToken')))]",
        "location": "[resourceGroup().location]",
        "DiagStorageName": "[tolower(concat(parameters('Kundenkuerzel'),'sadiag'))]",
        "DiagStorageType": "Standard_LRS"
  },
  "resources": [
    {
        "name": "storage",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2018-05-01",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
              "uri": "[variables('nestedtemplateUriStorage')]"
            },
            "variables": {
              "location":{"value": "[variables('location')]" },
              "DiagStorageName" :{"value": "[variables('DiagStorageName')]" },
              "DiagStorageType" :{"value": "[variables('DiagStorageType')]" }
          }
        }
      },

我的 storage.json 如下所示。

{
   ...
        },
    "variables": {
        "location": "[variables('location')]",
        "DiagStorageName": "[variables('DiagStorageName')]",
        "DiagStorageType": "[variables('DiagStorageType')]"
      }, 
    "resources": [
       {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('DiagStorageName')]",
      "apiVersion": "2015-06-15",
      "location": "[variables('location')]",
      "tags": {
        "displayName": "StorageAccount"
      },
      "properties": {
        "accountType": "[variables('DiagStorageType')]"
      }
    }

    ]
}

如何在链接模板中使用主模板中声明的变量?

【问题讨论】:

    标签: azure templates azure-resource-manager


    【解决方案1】:

    是的,您需要将它们作为参数传递。运行嵌套模板时不能定义变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多