使用ARM模板创建Search Service时遇相对路径解析错误
解决ARM模板本地部署时relativePath解析错误问题
错误原因
本地部署ARM模板时,Azure无法通过relativePath属性解析链接模板的路径——该属性仅支持父模板托管在**外部公共URI(如Azure存储Blob)或模板规范(Template Specs)**的场景,本地文件部署模式下不兼容。
解决方案
方案1:将链接模板上传至Azure存储账户,使用绝对URI引用
- 将
artifacts/azure_deploycopy.json上传到Azure存储账户的Blob容器(建议设置容器为Blob级别的公开访问,或生成SAS令牌确保访问权限)。 - 修改父模板中的
templateLink配置,替换为Blob的绝对URI:
"resources": [ { "type": "Microsoft.Resources/deployments", "apiVersion": "2021-04-01", "name": "azure-restore", "properties": { "mode": "Incremental", "templateLink": { "uri": "https://<你的存储账户名>.blob.core.windows.net/<容器名>/artifacts/azure_deploycopy.json", "contentVersion": "1.0.0.0" // 可选,匹配链接模板的contentVersion }, "parameters": { "searchService_name": { "value": "[parameters('searchService_name')]" } } } } ]
如果使用SAS令牌授权访问Blob,需添加sasToken属性:
"templateLink": { "uri": "https://<你的存储账户名>.blob.core.windows.net/<容器名>/artifacts/azure_deploycopy.json", "sasToken": "[parameters('sasToken')]", "contentVersion": "1.0.0.0" }
同时在父模板的parameters节点添加sasToken参数:
"parameters": { "searchService_name": { "type": "string" }, "sasToken": { "type": "securestring" } }
方案2:将链接模板内容内嵌到父模板中
如果无需分离模板文件,可直接将链接模板的完整JSON内容嵌入父模板的template属性(替代templateLink):
"resources": [ { "type": "Microsoft.Resources/deployments", "apiVersion": "2021-04-01", "name": "azure-restore", "properties": { "mode": "Incremental", "template": { // 粘贴artifacts/azure_deploycopy.json的完整JSON内容 "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "searchService_name": { "type": "string" } }, "resources": [ // 此处为原链接模板中定义的Search Service等资源 ] }, "parameters": { "searchService_name": { "value": "[parameters('searchService_name')]" } } } } ]
方案3:使用Azure CLI本地部署时的替代方式
若通过Azure CLI执行本地部署,可直接指定链接模板的本地绝对路径:
"templateLink": { "uri": "file:///C:/<本地路径>/artifacts/azure_deploycopy.json" }
注意:此方式仅适用于本地CLI部署,路径格式需符合操作系统要求(Windows用file:///C:/...,Linux/macOS用file:///home/...)。
内容的提问来源于stack exchange,提问作者Nithin Viswanathan
相关产品推荐
相关产品推荐

