首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure链接模板-未找到内联参数

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

Stack Overflow用户
提问于 2020-01-05 02:51:58
回答 2查看 677关注 0票数 0

我正在尝试创建一个带有链接模板的ARM模板,该模板遵循以下文档- https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-create-linked-templates

这是我在公共位置上传的链接模板

代码语言:javascript
复制
{
   "$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":{

   }
}

这是我试图运行的mainTemplate

代码语言:javascript
复制
{
   "$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')]"
               }
            }
         }
      }
   ]
}

这是params文件

代码语言:javascript
复制
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value": "australiaeast"
    }
  }
}

当我尝试使用以下命令部署它时

代码语言:javascript
复制
New-AzResourceGroupDeployment -Name "est-deployment" -ResourceGroupName "test-rg"  -TemplateFile .\template4.json -TemplateParameterFile .\params1.json

我得到的错误是

代码语言:javascript
复制
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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-05 03:07:32

我假设你通过引用location作为变量而不是参数,在你的资源"object“中遇到了问题--正如你所定义的:

代码语言:javascript
复制
"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
     }
  }

],

票数 0
EN

Stack Overflow用户

发布于 2020-01-05 02:56:25

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

代码语言:javascript
复制
"location":"[variables('location')]",

应该是这样:

代码语言:javascript
复制
"location":"[parameters('location')]",

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

代码语言:javascript
复制
"comments":"Azure storage for general purpose",
"type":"Microsoft.Storage/storageAccounts",
"name":"[parameters('storageName')]",
"apiVersion":"[variables('storageApiVersion')]",
"location":"[parameters('location')]",
"kind":"StorageV2",
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59593832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档