假设您有以下文件,这些文件是在Visual Studio中通过选择新的Azure资源组部署然后再添加嵌套模板而创建的
azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
}
},
"variables": {
"linkedTemplateTemplateFolder": "nestedtemplates",
"linkedTemplateTemplateFileName": "linkedTemplate.json",
"linkedTemplateTemplateParametersFileName": "linkedTemplate.parameters.json"
},
"resources": [
{
"name": "linkedTemplate",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri":
"[concat(parameters('_artifactsLocation'), '/', variables('linkedTemplateTemplateFolder'), '/', variables('linkedTemplateTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parametersLink": {
"uri":
"[concat(parameters('_artifactsLocation'), '/', variables('linkedTemplateTemplateFolder'), '/', variables('linkedTemplateTemplateParametersFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"_artifactsLocation": { "value": "[parameters('_artifactsLocation')]" },
"_artifactsLocationSasToken": { "value": "[parameters('_artifactsLocationSasToken')]" }
}
}
}
],
"outputs": {
"result": {
"type": "object",
"value": "[reference('linkedTemplate').outputs.result.value]"
}
}
}
azuredeploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
}
}
nestedtemplates \ linkedTemplate.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Foo": {
"type": "string"
},
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
}
},
"variables": {
"thirdTeirTemplateFolder": "nestedtemplates",
"thirdTeirTemplateFileName": "thirdTeir.json",
"thirdTeirTemplateParametersFileName": "thirdTeir.parameters.json"
},
"resources": [
{
"name": "thirdTeir",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('thirdTeirTemplateFolder'), '/', variables('thirdTeirTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"Foo": {"value": "[parameters('Foo')]"}
}
}
}
],
"outputs": {
"result": {
"type": "string",
"value": "[reference('thirdTeir').outputs.result]"
}
}
}
nestedtemplates \ linkedTemplate.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Foo": {
"value": "Foo!"
}
}
}
nestedtemplates \ thirdTeir.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Foo": {
"type": "string"
}
},
"variables": {},
"resources": [],
"outputs": {
"result": {
"type": "string",
"value": "[parameters('Foo')]"
}
}
}
这自然会因错误
而失败错误:Code = InvalidDeployment;消息=部署' linkedTemplate'不能同时设置ParameterLink和Parameter属性。请使用其中一个。有关使用详情,请参阅https://aka.ms/arm-deploy。
这是完全合理的,因为the documentation states您无法同时使用parametersLink
和parameters
。
在这种情况下我应该采取哪些解决方法,如何将_artifactsLocation
和_artifactsLocationSasToken
传递到模板的中间层,同时仍允许单独的文件保存将传入的配置值?
以防我问一个XY问题,我试图解决的真正问题是,是否有某种方法可以直接读取json文件,该文件包含通过uri传入的一些配置数据并访问其内容?这是我需要做的事情。
答案 0 :(得分:2)
我认为您尝试解决的根本问题是将参数和链接参数传递给嵌套部署......我可以想到几个选项,没有一个非常优雅:
3可能是最不容易的,可以完全在模板中完成,但可能会让你的sasToken不再保密。 (我想,不确定你是否可以将它保留为secureString)。
那有帮助吗?