如何使用ARM模板`contentVersion`?

问题描述 投票:0回答:1

ARM模板的文档没有说明如何使用不同的版本(至少我可以找到)。我从文档中得到的是contentVersiontemplateLink对象中的parameterLink值需要与链接模板中的值匹配。

"resources": [
  {
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "2018-05-01",
    "name": "linkedTemplate",
    "properties": {
    "mode": "Incremental",
    "templateLink": {
        "uri":"https://mystorageaccount.blob.core.windows.net/AzureTemplates/newStorageAccount.json",
        "contentVersion":"1.0.0.0"
    },
    "parametersLink": {
        "uri":"https://mystorageaccount.blob.core.windows.net/AzureTemplates/newStorageAccount.parameters.json",
        "contentVersion":"1.0.0.0"
    }
    }
  }
]

资料来源:https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates#external-template-and-external-parameters

有人在GitHub上打开了一个问题,要求提供更多信息,但我仍然没有清楚了解如何使用该版本。 https://github.com/MicrosoftDocs/azure-docs/issues/9402

有谁知道如何使用不同的contentVersion值的任何例子?

azure azure-resource-manager arm-template
1个回答
1
投票

我认为您可能会误解contentVersion的用法,该属性仅用于记录模板中的更改并确保您使用的是正确的模板,它可以是任何值。

见:https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates#template-format

enter image description here

例如,如果模板contentVersion中的https://mystorageaccount.blob.core.windows.net/AzureTemplates/newStorageAccount.json2.0.0.0

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "2.0.0.0",
    "parameters": {},
    "resources": []
}

但你使用下面的"contentVersion":"1.0.0.0"

 "templateLink": {
        "uri":"https://mystorageaccount.blob.core.windows.net/AzureTemplates/newStorageAccount.json",
        "contentVersion":"1.0.0.0"
    }

然后你会得到一个错误。在这个link中已经提到过:

您不必为模板或参数提供contentVersion属性。如果您未提供内容版本值,则会部署当前版本的模板。如果为内容版本提供值,则它必须与链接模板中的版本匹配;否则,部署失败并显示错误。

有一天,如果您对目标模板进行了一些更改,您可以将contentVersion更改为3.0.0.0以记录更改等。或者您不要更改它。这一切都取决于你。

© www.soinside.com 2019 - 2024. All rights reserved.