【问题标题】:parametersLink option not passing parameters to templateLinkparametersLink 选项未将参数传递给 templateLink
【发布时间】:2018-09-21 22:01:10
【问题描述】:

我收到一个错误:

“部署参数‘appServiceName’的值为空。”

即使它是在通过parametersLink 获得的文件中定义的。我从来没有收到提示,所以应该为 null,但为什么我从来没有收到提示?如何正确地将参数从parametersLink 文件传递​​到templateLink

主模板:

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "rgName": {
        "type": "string",
        "metadata": {
            "description": "Resource Group required in which to create App Service"
        }
    }
},
"variables": {},
"resources": [
    {
        "name": "LinkedAppServiceTemplate",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2017-05-10",
        "resourceGroup": "[parameters('rgName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "uri_to_template_file",
                "contentVersion": "1.0.0.0"
            },
            "parametersLink": {
                "uri": "uri_to_params_file",
                "contentVersion": "1.0.0.0"
            }
        }
    }
]
}

链接模板:

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
    {
        "name": "[parameters('appServiceName')]",
        "type": "Microsoft.Web/serverfarms",
        "apiVersion": "2015-05-01",
        "location": "[parameters('rgLocation')]"
    }
]
}

链接参数:

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "appServiceName": {
        "metadata": {
            "description": "Name of the App Service to be created"
        }
    },
    "rgLocation": {
        "defaultValue": "eastus",
        "metadata": {
            "description": "Location of the resource group to be created"
        }
    }
}
} 

【问题讨论】:

  • 如果您从部署资源中删除 resourceGroup 属性(并且只将所有内容部署到同一个资源组),它是否有效?

标签: azure azure-resource-manager arm-template


【解决方案1】:

您需要在您称为链接模板的文件中定义参数:

关注tutorial on how to create linked templates,它还将向您展示如何将参数从主模板传递到链接模板。

在这种情况下,您的链接模板需要在参数对象中声明参数。

"parameters": {
    "appServiceName" : {
        "type": "string",
        "metadata" : {
            "description": "This parameter needs to exist to pass from the link file"
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多