Azure CLI部署ARM模板报无法解析azuredeploy.parameters.json参数错误
问题原因与修复方案
你遇到的参数解析错误由三处问题共同导致,按以下步骤修复即可正常部署:
- 部署命令的参数文件名拼写错误:你输入的参数值为
azuredeploy.parameter,缺失了s.json后缀,Azure CLI找不到对应参数文件时,会将输入的字符串当作内联参数解析,直接触发解析报错。如果执行命令时终端当前工作目录不在D:\Azure下,还需要写全参数文件的绝对路径,避免路径匹配失败。 - 参数文件存在非法JSON语法:
azuredeploy.parameters.json中写了// TODO: Fill in parameter value单行注释,标准JSON不支持注释语法,ARM部署引擎解析文件时会直接抛出格式错误,删除该注释即可。 - 模板文件存在多余逗号:
azuredeploy.json中storageAccountName参数的metadata配置块闭合后多了一个冗余逗号,严格JSON校验场景下会触发解析失败,删除该冗余逗号即可。
修正后的部署命令
az deployment group create --resource-group az204-arm-rg --template-file D:\Azure\azuredeploy.json --parameters D:\Azure\azuredeploy.parameters.json
修正后文件内容
azuredeploy.json
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageAccountName": { "type": "string", "metadata": { "description": "Storage Account Name", "minLength": 3, "maxLength": 24 } } }, "functions": [], "variables": {}, "resources": [ { "name": "[parameters('storageAccountName')]", "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2021-04-01", "tags": { "displayName": "storageaccount1" }, "location": "[resourceGroup().location]", "kind": "StorageV2", "sku": { "name": "Premium_LRS", "tier": "Premium" } } ], "outputs": {} }
azuredeploy.parameters.json
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "storageAccountName": { "value": "az204storageacctarm" } } }
内容的提问来源于stack exchange,提问作者sundar rajan
相关产品推荐
相关产品推荐

