如何使用ARM模板规范?

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

我曾尝试使用链接模板格式一次性部署一些资源,但失败了,因为我的存储帐户只允许私人访问。

所以我想使用模板规范进行部署,但我不知道如何使用它。

这里是

main_template.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2022-09-01",
            "name": "storage",
            "properties": {
              "mode": "Incremental",
                "templateLink": {
                  "uri": "https://test/Storage/linkedtemplate_storage.json",
                  "contentVersion": "1.0.0.0"
                },
                "parametersLink": {
                  "uri": "https://test/Storage/linkedtemplate_storage.parameters-dev.json",
                  "contentVersion": "1.0.0.0"
                }
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2022-09-01",
            "name": "monitoring",
            "properties": {
              "mode": "Incremental",
                "templateLink": {
                  "uri": "https://test/Monitoring/linkedtemplate_monitoring.json",
                  "contentVersion": "1.0.0.0"
                },
                "parametersLink": {
                  "uri": "https://test/Monitoring/linkedtemplate_monitoring.parameters-dev.json",
                  "contentVersion": "1.0.0.0"
                }
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2022-09-01",
            "name": "notification",
            "properties": {
              "mode": "Incremental",
                "templateLink": {
                  "uri": "https://test/Notification/linkedtemplate_notification.json",
                  "contentVersion": "1.0.0.0"
                },
                "parametersLink": {
                  "uri": "https://test/Notification/linkedtemplate_notification.parameters-dev.json",
                  "contentVersion": "1.0.0.0"
                }
            }
        }
    ]
}

如您所见,我想为存储帐户中存储的每个链接模板使用一个参数文件。 但是,参考 MS 文档,我不确定是否可以使用存储在仅允许私人访问的存储帐户中的链接模板的 URI。

谁能解决这个问题? 任何答案都会有所帮助。

谢谢你。

azure azure-resource-manager
1个回答
0
投票

ARM模板规范的使用

您需要使用模板规范来存储链接的模板,而不是依赖存储帐户中的 URI。

enter image description here

此处您提供了存储帐户的 URL,其私有存储帐户将没有足够的权限。

首先为每个链接的模板创建模板规范

az ts create --name "storage-template" --version "1.0.0" --location "eastus" --template-file "./linkedtemplate_storage.json"

对于其余模板也同样遵循相同的操作。

演示配置:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  },
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "storageDeployment",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "https://<yourstorageaccount>.blob.core.windows.net/templates/linkedtemplate_storage.json?<SAStoken>",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "storageAccountName": {
            "value": "[parameters('storageAccountName')]"
          },
          "location": {
            "value": "[parameters('location')]"
          }
        }
      }
    }
}

由于您的存储帐户是私有的,请确保您通过了 SAS 令牌以获得必要的配置权限。

参考:

https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-specs-deploy-linked-template?tabs=azure-powershell

https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-specs-create-linked?tabs=azure-powershell

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