ARM嵌套模板:部署带有嵌套模板的模板时,_artifactLocation参数未正确填充 [英] ARM nested templates: _artifactLocation parameter is not populated correctly when deploying template with nested templates

查看:81
本文介绍了ARM嵌套模板:部署带有嵌套模板的模板时,_artifactLocation参数未正确填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚嵌套模板是如何工作的,我有以下模板.我正在尝试使用VS部署机制从VS进行部署:

I am trying to figure out how nested templates work and I have the below templates. I am trying to deploy from VS using the VS deploy mechanism:

  1. 右键单击项目>部署>新建
  2. 工件存储帐户"字段中预先填充了自动创建存储帐户",我将其保留为这样
  3. 单击部署"按钮

如果您在变量的HelloWorldParent.json模板中查看,您将看到两个变量"nestedTemplateUri"和"nestedTemplateUriWithBlobContainerName".

If you take a look in HelloWorldParent.json template in variables you will see two variables "nestedTemplateUri" and "nestedTemplateUriWithBlobContainerName".

据我了解,"nestedTemplateUri"应包含"blob容器名称",但事实并非如此.

It is my understanding that "nestedTemplateUri" should contain the "blob container name" but that doesn't seem to be the case.

如果我使用资源>属性> templateLink>"uri"进行部署:"[variables('nestedTemplateUri')]"

If I deploy with resources > properties > templateLink > "uri": "[variables('nestedTemplateUri')]"

  • 部署失败并显示:

错误:代码= InvalidContentLink; Message =无法下载部署 来自的内容 'https://********.blob.core.windows.net/NestedTemplates/HelloWorld.json?sv = 2017-07-29& sr = c& sig = ZCJAoOdp08qDWxbzKbXSZzX1VBCf7%2FNSt4aIznFCTPQ%3D& se = 2019-03-12T03:39:09Z& sp = r'

Error: Code=InvalidContentLink; Message=Unable to download deployment content from 'https://********.blob.core.windows.net/NestedTemplates/HelloWorld.json?sv=2017-07-29&sr=c&sig=ZCJAoOdp08qDWxbzKbXSZzX1VBCf7%2FNSt4aIznFCTPQ%3D&se=2019-03-12T03:39:09Z&sp=r'

  • 创建存储帐户,上传模板,参数和PS1脚本
  • 未在资源组/部署中创建新的部署
  • 如果我使用资源>属性> templateLink>"uri"进行部署:"[variables('nestedTemplateUriWithBlobContainerName')]"

    If I deploy with resources > properties > templateLink > "uri": "[variables('nestedTemplateUriWithBlobContainerName')]"

    • 部署成功.

    有什么主意吗?非常感谢您的帮助!

    Any idea? Any help is highly appreciated!

    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"
        }
      }
    }
    

    推荐答案

    不幸的是,VS在支持您的方案方面有点过时" ...问题是您使用的是URI函数,而_artifactsLocation没有有一个斜杠.因此,您可以选择以下几种解决方法:

    Unfortunately VS is a bit "dated" in it's support for your scenario... the problem is that you're using the URI function and the _artifactsLocation does not have a trailing slash. So you have a few options to fix:

    1)在VS中的PS1文件中,有一行看起来像这样:

    1) in the PS1 file in VS there is a line that looks like this:

    $OptionalParameters[$ArtifactsLocationName] = $StorageAccount.Context.BlobEndPoint + $StorageContainerName
    

    如果将其更改为此(添加尾随/):

    If you change it to this (add a trailing /):

    $OptionalParameters[$ArtifactsLocationName] = $StorageAccount.Context.BlobEndPoint + $StorageContainerName + "/"
    

    它应该起作用-或者,您也可以用以下脚本替换整个脚本: https://github.com/Azure/azure-quickstart-templates/blob/master/Deploy-AzureResourceGroup.ps1

    It should work - alternatively you can just replace the entire script with this one: https://github.com/Azure/azure-quickstart-templates/blob/master/Deploy-AzureResourceGroup.ps1

    请注意,如果您还有其他不带斜杠的模板都可以使用,那么这将是一个重大突破.

    Note that if you have other templates that work without the trailing slash, this will be a breaking change.

    2)使用concat()创建uri而不是uri()函数.您仍然必须知道是否有斜杠,但是可以在模板而不是PS1文件中完成此更改.

    2) use concat() to create the uri instead of the uri() function. You still have to know whether there is a trailing slash but this change can be done in the template and not the PS1 file.

       "nestedTemplateUri": "[concat(parameters('_artifactsLocation'), '/NestedTemplates/HelloWorld.json', parameters('_artifactsLocationSasToken'))]"
    

    应该都可以.

    这篇关于ARM嵌套模板:部署带有嵌套模板的模板时,_artifactLocation参数未正确填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆