使用.bicepparam文件进行Azure部署时遇参数识别错误
解决Azure CLI部署中.bicepparam参数文件识别错误问题
问题分析
你遇到的错误是因为Azure CLI默认将@test.bicepparam视为ARM JSON参数文件解析,无法识别.bicepparam文件中的using关键字,进而把这一行内容当作无效参数处理。而传统ARM JSON参数文件没有这类关键字,所以能正常运行。
解决方案
针对.bicepparam文件,Azure CLI提供了专门的参数传递方式,以下两种方法均可解决问题:
方法1:使用--parameters-file参数(推荐)
Azure CLI 2.46.0及以上版本支持--parameters-file参数,专门用于指定.bicepparam文件,无需额外前缀:
az deployment group create --name test --resource-group test-resource-group --template-file test.bicep --parameters-file test.bicepparam
由于你的.bicepparam文件已经通过using './test.bicep'关联了模板,也可以省略--template-file参数:
az deployment group create --name test --resource-group test-resource-group --parameters-file test.bicepparam
方法2:使用bicepparam://前缀
如果需要继续使用--parameters参数,需通过bicepparam://前缀明确告知CLI这是一个Bicep参数文件:
az deployment group create --name test --resource-group test-resource-group --template-file test.bicep --parameters bicepparam://./test.bicepparam
版本验证
你的环境使用Azure CLI 2.49.0和Bicep 0.18.4,均已支持上述两种方法,无需升级版本即可正常运行。执行修正后的命令后,部署会正确解析参数,输出combinedValue为Hello World!。
内容的提问来源于stack exchange,提问作者SecondSleep
相关产品推荐
相关产品推荐

