다음을 통해 공유


ARM 템플릿을 사용하여 리소스 그룹 배포

이 문서에서는 배포 범위를 리소스 그룹으로 지정하는 방법을 설명합니다. 배포에 ARM 템플릿(Azure Resource Manager 템플릿)을 사용합니다. 이 문서에서는 배포 작업에서 리소스 그룹을 넘어 범위를 확장하는 방법도 보여줍니다.

팁 (조언)

ARM 템플릿과 동일한 기능을 제공하므로 Bicep 을 사용하는 것이 좋으며 구문을 사용하기가 더 쉽습니다. 자세한 내용은 리소스 그룹 배포를 참조하세요.

지원되는 리소스

대부분의 리소스는 리소스 그룹에 배포가 가능합니다. 사용 가능한 리소스 목록은 ARM 템플릿 참조를 참조하세요.

스키마

템플릿의 경우 다음 스키마를 사용합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  ...
}

매개 변수 파일의 경우 다음을 사용합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  ...
}

배포 명령

리소스 그룹에 배포하려면 리소스 그룹 배포 명령을 사용합니다.

Azure CLI의 경우 az deployment group create를 사용합니다. 다음 예제에서는 리소스 그룹을 만드는 템플릿을 배포합니다. 매개 변수에 지정하는 --resource-group 리소스 그룹은 대상 리소스 그룹입니다.

az deployment group create \
  --name demoRGDeployment \
  --resource-group ExampleGroup \
  --template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.storage/storage-account-create/azuredeploy.json" \
  --parameters storageAccountType=Standard_GRS

ARM 템플릿 배포를 위한 배포 명령 및 옵션에 대한 자세한 내용은 다음을 참조하세요.

배포 범위

리소스 그룹에 배포할 때 리소스를 다음과 같이 배포할 수 있습니다.

  • 작업에서 대상 리소스 그룹
  • 동일한 구독 또는 다른 구독의 다른 리소스 그룹
  • 테넌트의 모든 구독
  • 리소스 그룹에 대한 테넌트

유일하게 금지된 범위 전환은 리소스 그룹에서 관리 그룹으로 또는 구독에서 관리 그룹으로의 전환입니다.

확장 리소스는 배포 대상과 다른 대상으로 범위를 지정할 수 있습니다.

템플릿을 배포하는 사용자가 지정된 범위에 액세스할 수 있어야 합니다.

이 섹션에서는 다양한 범위를 지정하는 방법을 보여 줍니다. 단일 템플릿에서 이러한 여러 범위를 결합할 수 있습니다.

대상 리소스 그룹으로 범위 지정

대상 리소스에 리소스를 배포하려면 템플릿의 리소스 섹션에 해당 리소스를 추가합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    resource-group-resources
  ],
  "outputs": {}
}

예제 템플릿은 대상 리소스 그룹에 배포를 참조하세요.

동일한 구독의 리소스 그룹으로 범위 지정

동일한 구독의 다른 리소스 그룹에 리소스를 배포하려면 중첩된 배포를 추가하고 속성을 포함합니다 resourceGroup . 구독 ID 또는 리소스 그룹을 지정하지 않으면 부모 템플릿의 구독 및 리소스 그룹이 사용됩니다. 배포를 실행하기 전에 모든 리소스 그룹이 있어야 합니다.

다음 예제에서 중첩된 배포는 demoResourceGroup이라는 이름의 리소스 그룹을 대상으로 합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "nestedDeployment",
      "resourceGroup": "demoResourceGroup",
      "properties": {
        "mode": "Incremental",
        "template": {
          resource-group-resources
        }
      }
    }
  ],
  "outputs": {}
}

예제 템플릿은 여러 리소스 그룹에 배포를 참조하세요.

다른 구독의 리소스 그룹으로 범위 지정

다른 구독의 리소스 그룹에 리소스를 배포하려면 중첩된 배포를 추가하고 subscriptionIdresourceGroup 속성을 포함합니다. 다음 예제에서 중첩된 배포는 demoResourceGroup이라는 이름의 리소스 그룹을 대상으로 합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "nestedDeployment",
      "subscriptionId": "00000000-0000-0000-0000-000000000000",
      "resourceGroup": "demoResourceGroup",
      "properties": {
        "mode": "Incremental",
        "template": {
          resource-group-resources
        }
      }
    }
  ],
  "outputs": {}
}

예제 템플릿은 여러 리소스 그룹에 배포를 참조하세요.

구독으로 범위 지정

구독에 리소스를 배포하려면 중첩된 배포를 추가하고 속성을 포함합니다 subscriptionId . 구독은 대상 리소스 그룹에 대한 구독이거나 테넌트에 있는 다른 구독일 수 있습니다. 또한 중첩된 배포에 대한 속성을 설정합니다 location .

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "nestedDeployment",
      "location": "centralus",
      "subscriptionId": "0000000-0000-0000-0000-000000000000",
      "properties": {
        "mode": "Incremental",
        "template": {
          subscription-resources
        }
      }
    }
  ],
  "outputs": {}
}

예제 템플릿은 리소스 그룹 만들기를 참조하세요.

테넌트로 범위 지정

테넌트에서 리소스를 만들려면 scope/로 설정합니다. 템플릿을 배포하는 사용자는 테넌트에서 배포하는 데 필요한 액세스 권한이 있어야 합니다.

중첩된 배포를 사용하려면 scopelocation을 설정합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "nestedDeployment",
      "location": "centralus",
      "scope": "/",
      "properties": {
        "mode": "Incremental",
        "template": {
          tenant-resources
        }
      }
    }
  ],
  "outputs": {}
}

또는 관리 그룹과 같은 일부 리소스 종류에 대해 범위를 /로 설정할 수 있습니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "mgName": {
      "type": "string",
      "defaultValue": "[concat('mg-', uniqueString(newGuid()))]"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Management/managementGroups",
      "apiVersion": "2021-04-01",
      "name": "[parameters('mgName')]",
      "scope": "/",
      "location": "eastus",
      "properties": {}
    }
  ],
  "outputs": {
    "output": {
      "type": "string",
      "value": "[parameters('mgName')]"
    }
  }
}

자세한 내용은 관리 그룹을 참조하세요.

대상 리소스 그룹으로 배포

대상 리소스 그룹에 리소스를 배포하려면 템플릿의 resources 섹션에서 해당 리소스를 정의합니다. 다음 템플릿은 배포 작업에 지정된 리소스 그룹에 스토리지 계정을 만듭니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storagePrefix": {
      "type": "string",
      "minLength": 3,
      "maxLength": 11
    },
    "storageSKU": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Standard_ZRS",
        "Premium_LRS",
        "Premium_ZRS",
        "Standard_GZRS",
        "Standard_RAGZRS"
      ]
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "variables": {
    "uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-09-01",
      "name": "[variables('uniqueStorageName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageSKU')]"
      },
      "kind": "StorageV2",
      "properties": {
        "supportsHttpsTrafficOnly": true
      }
    }
  ],
  "outputs": {
    "storageEndpoint": {
      "type": "object",
      "value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
    }
  }
}

여러 리소스 그룹으로 배포

단일 ARM 템플릿에서 둘 이상의 리소스 그룹에 배포할 수 있습니다. 부모 템플릿과 다른 리소스 그룹을 대상으로 지정하려면 중첩 또는 연결된 템플릿을 사용합니다. 배포 리소스 유형 내에서 중첩된 템플릿을 배포할 구독 ID 및 리소스 그룹에 대한 값을 지정합니다. 리소스 그룹은 다른 구독에 있을 수 있습니다.

비고

단일 배포에서 800개의 리소스 그룹에 배포할 수 있습니다. 일반적으로 이 제한 사항으로 인해 부모 템플릿에 지정된 하나의 리소스 그룹 및 중첩되거나 연결된 배포에서 최대 799개의 리소스 그룹에 배포할 수 있습니다. 그러나 부모 템플릿에 중첩 또는 연결된 템플릿만 포함되고 자체에서 리소스를 배포하지 않는 경우 중첩 또는 연결된 배포에 최대 800개의 리소스 그룹을 포함할 수 있습니다.

다음 예제에서는 두 개의 스토리지 계정을 만듭니다. 첫 번째 스토리지 계정은 배포 작업에 지정된 리소스 그룹에 배포됩니다. 두 번째 스토리지 계정은 secondResourceGroupsecondSubscriptionID 매개 변수에 지정된 리소스 그룹에 배포됩니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storagePrefix": {
      "type": "string",
      "maxLength": 11
    },
    "secondResourceGroup": {
      "type": "string"
    },
    "secondSubscriptionID": {
      "type": "string",
      "defaultValue": ""
    },
    "secondStorageLocation": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "variables": {
    "firstStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]",
    "secondStorageName": "[concat(parameters('storagePrefix'), uniqueString(parameters('secondSubscriptionID'), parameters('secondResourceGroup')))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-04-01",
      "name": "[variables('firstStorageName')]",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "Storage",
      "properties": {
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "nestedTemplate",
      "resourceGroup": "[parameters('secondResourceGroup')]",
      "subscriptionId": "[parameters('secondSubscriptionID')]",
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
            {
              "type": "Microsoft.Storage/storageAccounts",
              "apiVersion": "2021-04-01",
              "name": "[variables('secondStorageName')]",
              "location": "[parameters('secondStorageLocation')]",
              "sku": {
                "name": "Standard_LRS"
              },
              "kind": "Storage",
              "properties": {
              }
            }
          ]
        },
        "parameters": {}
      }
    }
  ]
}

존재하지 않는 리소스 그룹의 이름으로 설정 resourceGroup 하면 배포가 실패합니다.

이전 템플릿을 테스트하고 결과를 보려면 PowerShell 또는 Azure CLI를 사용합니다.

동일한 구독의 두 리소스 그룹에 두 개의 스토리지 계정을 배포하려면 다음을 사용합니다.

firstRG="primarygroup"
secondRG="secondarygroup"

az group create --name $firstRG --location southcentralus
az group create --name $secondRG --location eastus
az deployment group create \
  --name ExampleDeployment \
  --resource-group $firstRG \
  --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/crosssubscription.json \
  --parameters storagePrefix=tfstorage secondResourceGroup=$secondRG secondStorageLocation=eastus

두 개의 구독에 두 개의 스토리지 계정을 배포하려면 다음을 사용합니다.

firstRG="primarygroup"
secondRG="secondarygroup"

firstSub="<first-subscription-id>"
secondSub="<second-subscription-id>"

az account set --subscription $secondSub
az group create --name $secondRG --location eastus

az account set --subscription $firstSub
az group create --name $firstRG --location southcentralus

az deployment group create \
  --name ExampleDeployment \
  --resource-group $firstRG \
  --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/crosssubscription.json \
  --parameters storagePrefix=storage secondResourceGroup=$secondRG secondStorageLocation=eastus secondSubscriptionID=$secondSub

리소스 그룹 만들기

리소스 그룹 배포에서 구독 수준으로 전환하고 리소스 그룹을 만들 수 있습니다. 다음 템플릿은 대상 리소스 그룹에 스토리지 계정을 배포하고 지정된 구독에 새 리소스 그룹을 만듭니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storagePrefix": {
      "type": "string",
      "maxLength": 11
    },
    "newResourceGroupName": {
      "type": "string"
    },
    "nestedSubscriptionID": {
      "type": "string"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "variables": {
    "storageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-04-01",
      "name": "[variables('storageName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "Storage",
      "properties": {
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "demoSubDeployment",
      "location": "westus",
      "subscriptionId": "[parameters('nestedSubscriptionID')]",
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
            {
              "type": "Microsoft.Resources/resourceGroups",
              "apiVersion": "2021-04-01",
              "name": "[parameters('newResourceGroupName')]",
              "location": "[parameters('location')]",
              "properties": {}
            }
          ],
          "outputs": {}
        }
      }
    }
  ]
}

다음 단계