연결 및 중첩된 ARM 템플릿 배포

완료됨

배포 복잡성이 증가함에 따라 ARM(Azure Resource Manager) 연결 또는 중첩된 템플릿을 사용하여 리소스를 배포하는 모듈식 접근 방식으로 이동하는 것이 좋습니다. 연결 및 중첩된 템플릿은 배포를 여러 관련 템플릿으로 분할한 다음, 주 템플릿을 통해 함께 배포하는 방법입니다.

연결된 템플릿

‘연결된 템플릿’은 주 템플릿에서 링크로 참조되는 개별 템플릿 파일을 연결하는 동작을 나타냅니다. 연결된 템플릿을 사용하여 여러 개별 ARM 템플릿으로 구성된 재사용 가능하고 구성 가능한 모듈식 배포를 만들 수 있습니다.

연결된 템플릿을 참조하는 경우 HTTP 또는 HTTPS를 통해 액세스할 수 있는 URI 값을 제공해야 합니다. 이는 로컬 파일을 사용할 수 있는 마지막 단원과 다릅니다.

연결된 템플릿을 사용하려면 먼저 GitHub 또는 Azure Blob Storage와 같은 공개적으로 액세스할 수 있는 엔드포인트에서 템플릿을 스테이징해야 합니다. SAS(공유 액세스 서명) 토큰으로 보호되는 Azure Storage 계정을 사용하여 템플릿을 퍼블릭 액세스로부터 안전하게 유지합니다.

ARM 템플릿에 연결된 템플릿을 추가하려면 Microsoft.Resources/deployments 리소스 및 templateLink 속성(템플릿 위치로 구성됨)을 추가합니다.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string",
            "defaultValue": "linkeddemo001"
        }
    },
    "variables": {
        "linked-template": "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/mslearn-arm-Module-sample/storage.json",
        "linked-template-two": "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/mslearn-arm-Module-sample/identity.json"
    },
    "resources": [
        {
            "name": "storage",
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2019-10-01",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[variables('linked-template')]",
                    "contentVersion": "1.0.0.0"
                },
                "parameters": {
                    "name": { "value": "[parameters('name')]" },
                    "location": { "value": "[resourceGroup().location]" }
                }
            }
        },
        {
            "name": "identity",
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2019-10-01",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/deployments','storage')]"
            ],
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[variables('linked-template-two')]",
                    "contentVersion": "1.0.0.0"
                },
                "parameters": {
                    "name": { "value": "[parameters('name')]" },
                    "location": { "value": "[resourceGroup().location]" }
                }
            }
        }
    ],
    "outputs": {
        "storageURI": {
            "type": "string",
            "value": "[reference('storage').outputs.storageEndpoint.value]"
        }
    }
}

필요한 경우 매개 변수 값을 연결된 템플릿에 전달하고 배포 시간에 연결된 템플릿에서 출력을 가져올 수도 있습니다. 매개 변수는 매개 변수 파일 또는 인라인 매개 변수를 통해 전달할 수 있습니다.

{
  "name": "storage",
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2019-10-01",
  "properties": {
      "mode": "Incremental",
      "templateLink": {
          "uri": "[variables('linked-template')]",
          "contentVersion": "1.0.0.0"
      },
      "parameters": {
          "name": { "value": "[parameters('name')]" },
          "location": { "value": "[resourceGroup().location]" }
      }
  }
}

중소기업에게는 단일 템플릿이 더 간편하게 이해하고 유지 관리할 수 있습니다. 모든 리소스 및 값을 단일 파일에서 볼 수 있습니다. 고급 시나리오의 경우 연결된 템플릿을 사용하여 솔루션을 대상 구성 요소로 분할할 수 있습니다. 관련 템플릿을 다른 시나리오에 쉽게 재사용할 수 있습니다.

중첩된 템플릿

‘중첩된 템플릿’은 주 템플릿 내에 템플릿 구문을 포함하는 동작을 나타냅니다. 중첩된 템플릿은 단일 템플릿 파일에서 여러 Azure Resource Manager 범위 또는 여러 리소스 그룹에 배포하는 것과 같은 고급 배포 시나리오를 허용합니다. 각 템플릿이 자체 템플릿 파일에 저장되는 연결된 템플릿과 달리, 중첩된 템플릿을 사용하면 여러 개별 템플릿을 하나의 파일에 저장할 수 있습니다. 여러 리소스 그룹 또는 배포 범위에 리소스를 배포하는 경우와 같이 이 작업을 수행하려고 하는 여러 가지 이유가 있습니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "name": "nestedTemplate1",
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "type": "Microsoft.Storage/storageAccounts",
              "apiVersion": "2019-04-01",
              "name": "[parameters('storageAccountName')]",
              "location": "West US",
              "sku": {
                "name": "Standard_LRS"
              },
              "kind": "StorageV2"
            }
          ]
        }
      }
    }
  ],
  "outputs": {
  }
}

중첩된 템플릿을 사용하면 템플릿 식이 부모 템플릿 또는 중첩된 템플릿의 범위 내에서 평가되는지 여부를 지정할 수 있습니다. 범위에 따라 resourceGroupsubscription과 같은 매개 변수, 변수 및 함수를 확인하는 방법이 결정됩니다.