我试图找出如何模板嵌套的工作,我有以下的模板。 我想用VS部署机制从VS部署:
- 右键单击项目>部署>新
- “神器存储帐户”字段预置了“自动创建一个存储账户”,我把它像
- 点击部署按钮
如果你把在HelloWorldParent.json模板看看变量,你会看到两个变量“nestedTemplateUri”和“nestedTemplateUriWithBlobContainerName”。
这是我的理解是“nestedTemplateUri”应包含“斑点容器名称”,但似乎并不如此。
如果我部署与资源>属性> templateLink> “URI”: “[变量( 'nestedTemplateUri')]”
- 部署失败:
错误:代码= InvalidContentLink; 消息=无法下载从“HTTPS部署内容://********.blob.core.windows.net/NestedTemplates/HelloWorld.json SV = 2017年7月29日与SR = C = SIG%ZCJAoOdp08qDWxbzKbXSZzX1VBCf7%2FNSt4aIznFCTPQ 3D&SE = 2019-03-12T03:39:09Z& SP = R”
- 存储账户创建时,模板参数和PS1脚本上传
- 没有在资源组/部署创建一个新的部署
如果我部署与资源>属性> templateLink> “URI”: “[变量( 'nestedTemplateUriWithBlobContainerName')]”
- 在部署成功。
任何想法? 任何帮助,不胜感激!
HelloWorldParent.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"_artifactsLocation": {
"type": "string",
"metadata": {
"description": "The base URI where artifacts required by this template are located including a trailing '/'"
}
},
"_artifactsLocationSasToken": {
"type": "securestring",
"metadata": {
"description": "The sasToken required to access _artifactsLocation. When the template is deployed using the accompanying scripts, a sasToken will be automatically generated. Use the defaultValue if the staging location is not secured."
},
"defaultValue": ""
}
},
"variables": {
"blobContainerName": "[concat(resourceGroup().name, '-stageartifacts/')]",
"nestedTemplateUriWithBlobContainerName": "[uri(parameters('_artifactsLocation'), concat(variables('blobContainerName'), 'NestedTemplates/HelloWorld.json', parameters('_artifactsLocationSasToken')))]",
"nestedTemplateUri": "[uri(parameters('_artifactsLocation'), concat('NestedTemplates/HelloWorld.json', parameters('_artifactsLocationSasToken')))]"
},
"resources": [
{
"apiVersion": "2017-05-10",
"name": "linkedTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "incremental",
"templateLink": {
"uri": "[variables('nestedTemplateUri')]",
"contentVersion": "1.0.0.0"
}
}
}
],
"outputs": {
"messageFromLinkedTemplate": {
"type": "string",
"value": "[reference('linkedTemplate').outputs.greetingMessage.value]"
},
"_artifactsLocation": {
"type": "string",
"value": "[parameters('_artifactsLocation')]"
}
}
}
HelloWorldParent.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
}
}
NestedTemplates / HelloWorld.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {
"greetingMessage": {
"value": "Hello World (1)",
"type": "string"
}
}
}