首页 > 解决方案 > 未读取 Azure ARM 参数文件中的值

问题描述

我想部署 Azure 资源。模板中使用的变量在专用参数文件中声明。但是,在部署模板时出现以下错误:

New-AzResourceGroupDeployment -ResourceGroupName $resourceGroup -TemplateUri $templateUri -TemplateParameterUri $paramUri

New-AzResourceGroupDeployment:10:13:17 - 错误:代码=无效模板;消息=部署模板验证失败:'未提供'22'行和'16'列的模板参数'sku'的值。请参阅 https://aka.ms/arm-deploy/#parameter-file了解使用详情。

“sku”是参数,定义为:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "sku": {
            "value": {
                "name": "Standard_B1s",
                "tier": "Standard",
                "capacity": 1
            }
        }
    }
}

它被这样调用/使用

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "sku": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "comments": "",
            "type": "Microsoft.Compute/virtualMachineScaleSets",
            "sku": "[parameters('sku')]",
            "name": "SomeName",
            "apiVersion": "2018-06-01",
            "location": "westeurope",
            "scale": null,
            "properties": {}
        }
    ],
    "outputs": {}
}

我正在使用这种方式在不同的模板中以这种方式调用参数而没有问题。

你们中的一些人发现错误了吗?

标签: azure-resource-manager

解决方案


好吧,是我的错。

我过度简化了模板,因此遗漏了一个关键信息:

我正在使用链接模板(用于应用程序网关的早期部署),并在此基础上添加新资源。第一个部署模板也有自己的参数文件。

下面是部署资源,我正在引用。我忘了输入 parametersLink 属性。因此 ARM 无法查找参数文件并将参数提供给第一个模板中的“sku”参数。

不幸的是,网关的模板也有一个“sku”参数,所以我错误地认为我的另一个模板有错误。我现在将参数命名为“skuGateway”和“skuScaleSet”作为经验教训。

{
    "apiVersion": "2017-05-10",
    "name": "stack1_gw",
    "type": "Microsoft.Resources/deployments",
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "[concat(uri(deployment().properties.templateLink.uri, 'stack1_gw.json'), parameters('containerSasToken'))]",
            "contentVersion": "1.0.0.0"
        },
        "parametersLink": {
            "uri": "[concat(uri(deployment().properties.templateLink.uri, 'stack1_gw.parameters.json'), parameters('containerSasToken'))]",
            "contentVersion": "1.0.0.0"
        }
    }
}


推荐阅读