如何使用 ARM 模板 `contentVersion`?

How to Use ARM Template `contentVersion`?

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

"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 值的示例吗?

我想你可能误解了 contentVersion 的用法,属性 只是用来记录你的模板的变化,并确保你使用的是正确的模板,它可以是任何值.

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

例如模板https://mystorageaccount.blob.core.windows.net/AzureTemplates/newStorageAccount.json中的contentVersion2.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:

中已经提到了

You don't have to provide the contentVersion property for the template or parameters. If you don't provide a content version value, the current version of the template is deployed. If you provide a value for content version, it must match the version in the linked template; otherwise, the deployment fails with an error.

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