Azure 链接模板 - 未找到内联参数

Azure linked template - inline parameter not found

我正在尝试使用此文档后的链接模板创建 ARM 模板 - https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-create-linked-templates

这是我上传到 public 位置

的链接模板
{
   "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion":"1.0.0.0",
   "parameters":{
     "location":{
         "type":"string",
         "defaultValue":"fakevalue",
         "metadata":{
            "description":"location of deployment."
         }
      },
      "storageName":{
         "type":"string",
         "defaultValue":"[concat('storage', take(uniqueString(subscription().subscriptionId, resourceGroup().id, resourceGroup().name), 5))]",
         "metadata":{
            "description":"The name of the storageAccount"
         }
      },
      "storageSkuName":{
         "type":"string",
         "defaultValue":"Standard_LRS",
         "allowedValues":[
            "Standard_LRS",
            "Standard_GRS",
            "Standard_RAGRS",
            "Standard_ZRS",
            "Premium_LRS"
         ],
         "metadata":{
            "description":"The storage SKU name"
         }
      }
   },
   "variables":{
      "storageApiVersion":"2018-11-01"
    },
   "resources":[
      {
         "comments":"Azure storage for general purpose",
         "type":"Microsoft.Storage/storageAccounts",
         "name":"[parameters('storageName')]",
         "apiVersion":"[variables('storageApiVersion')]",
         "location":"[variables('location')]",
         "kind":"StorageV2",
         "sku":{
            "name":"[parameters('storageSkuName')]"
         },
         "properties":{
            "supportsHttpsTrafficOnly":true
         }
      }
   ],
   "outputs":{

   }
}

这是我尝试使用的主模板运行

{
   "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion":"1.0.0.0",
   "parameters":{
      "linkedDeploymentName":{
         "type":"string",
         "defaultValue":"[concat('deployment-', resourceGroup().name, '-linked')]",
         "metadata":{
            "description":"linked deployment name."
         }
      },
         "location":{
         "type":"string",
         "defaultValue":"fakevalue",
         "metadata":{
            "description":"location of deployment."
         }
      }
   },
   "variables":{

   },
   "resources":[
      {
         "apiVersion":"2018-02-01",
         "name":"pid-7d82386d-966e-5431-bf88-1e6ccb393300",
         "type":"Microsoft.Resources/deployments",
         "properties":{
            "mode":"Incremental",
            "template":{
               "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
               "contentVersion":"1.0.0.0",
               "resources":[

               ]
            }
         }
      },
      {
         "apiVersion":"2019-10-01",
         "name":"[parameters('linkedDeploymentName')]",
         "type":"Microsoft.Resources/deployments",
         "properties":{
            "mode":"Incremental",
            "templateLink":{
               "uri":"<linked-template-url>",
               "contentVersion":"1.0.0.0"
            },
            "parameters":{
               "location":{
                  "value":"[parameters('location')]"
               }
            }
         }
      }
   ]
}

这是参数文件

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value": "australiaeast"
    }
  }
}

当我尝试使用

部署它时
New-AzResourceGroupDeployment -Name "est-deployment" -ResourceGroupName "test-rg"  -TemplateFile .\template4.json -TemplateParameterFile .\params1.json

我得到的错误是

Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template variable 'location' is not found. Please see https://aka.ms/arm-template/#variables for usage details.'.
At line:1 char:5

如何将参数从主模板传递到链接模板?

这个(在链接的模板存储帐户中):

"location":"[variables('location')]",

应该是这样的:

"location":"[parameters('location')]",

因为您使用的是参数,而不是变量。所以它应该是这样的:

"comments":"Azure storage for general purpose",
"type":"Microsoft.Storage/storageAccounts",
"name":"[parameters('storageName')]",
"apiVersion":"[variables('storageApiVersion')]",
"location":"[parameters('location')]",
"kind":"StorageV2",

我假设您的资源有问题 "object" 通过将位置引用为变量而不是参数 - 正如您定义的那样:

"resources":[
  {
     "comments":"Azure storage for general purpose",
     "type":"Microsoft.Storage/storageAccounts",
     "name":"[parameters('storageName')]",
     "apiVersion":"[variables('storageApiVersion')]",
     "location":"[parameters('location')]",  <-- THE CHANGE IS HERE
     "kind":"StorageV2",
     "sku":{
        "name":"[parameters('storageSkuName')]"
     },
     "properties":{
        "supportsHttpsTrafficOnly":true
     }
  }

],