빠른 시작: Bicep으로 배포 스택 만들기 및 배포

이 빠른 시작에서는 배포 스택을 만드는 방법을 설명합니다.

필수 조건

Bicep 파일 만들기

스토리지 계정 및 가상 네트워크를 만들기 위한 Bicep 파일을 만듭니다.

param resourceGroupLocation string = resourceGroup().location
param storageAccountName string = 'store${uniqueString(resourceGroup().id)}'
param vnetName string = 'vnet${uniqueString(resourceGroup().id)}'

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
  name: storageAccountName
  location: resourceGroupLocation
  kind: 'StorageV2'
  sku: {
    name: 'Standard_LRS'
  }
}

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2022-11-01' = {
  name: vnetName
  location: resourceGroupLocation
  properties: {
    addressSpace: {
      addressPrefixes: [
        '10.0.0.0/16'
      ]
    }
    subnets: [
      {
        name: 'Subnet-1'
        properties: {
          addressPrefix: '10.0.0.0/24'
        }
      }
      {
        name: 'Subnet-2'
        properties: {
          addressPrefix: '10.0.1.0/24'
        }
      }
    ]
  }
}

Bicep 파일을 main.bicep으로 저장합니다.

배포 스택 만들기

이 빠른 시작에서는 리소스 그룹 범위에서 배포 스택을 만듭니다. 구독 범위 또는 관리 그룹 범위에서 배포 스택을 만들 수도 있습니다. 자세한 내용은 배포 스택 만들기를 참조하세요.

az group create \
  --name 'demoRg' \
  --location 'centralus'

az stack group create \
  --name demoStack \
  --resource-group 'demoRg' \
  --template-file './main.bicep' \
  --deny-settings-mode 'none'

배포 확인

리소스 그룹 수준에서 배포된 배포 스택을 나열하려면 다음을 수행합니다.

az stack group show \
  --resource-group 'demoRg' \
  --name 'demoStack'

출력에는 두 개의 관리되는 리소스(스토리지 계정 하나와 가상 네트워크 하나)가 표시됩니다.

{
  "actionOnUnmanage": {
    "managementGroups": "detach",
    "resourceGroups": "detach",
    "resources": "detach"
  },
  "debugSetting": null,
  "deletedResources": [],
  "denySettings": {
    "applyToChildScopes": false,
    "excludedActions": null,
    "excludedPrincipals": null,
    "mode": "none"
  },
  "deploymentId": "/subscriptions/00000000-0000-0000-0000-000000000000/demoRg/providers/Microsoft.Resources/deployments/demoStack-2023-06-08-14-58-28-fd6bb",
  "deploymentScope": null,
  "description": null,
  "detachedResources": [],
  "duration": "PT30.1685405S",
  "error": null,
  "failedResources": [],
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/demoRg/providers/Microsoft.Resources/deploymentStacks/demoStack",
  "location": null,
  "name": "demoStack",
  "outputs": null,
  "parameters": {},
  "parametersLink": null,
  "provisioningState": "succeeded",
  "resourceGroup": "demoRg",
  "resources": [
    {
      "denyStatus": "none",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/demoRg/providers/Microsoft.Network/virtualNetworks/vnetthmimleef5fwk",
      "resourceGroup": "demoRg",
      "status": "managed"
    },
    {
      "denyStatus": "none",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/demoRg/providers/Microsoft.Storage/storageAccounts/storethmimleef5fwk",
      "resourceGroup": "demoRg",
      "status": "managed"
    }
  ],
  "systemData": {
    "createdAt": "2023-06-08T14:58:28.377564+00:00",
    "createdBy": "johndole@contoso.com",
    "createdByType": "User",
    "lastModifiedAt": "2023-06-08T14:58:28.377564+00:00",
    "lastModifiedBy": "johndole@contoso.com",
    "lastModifiedByType": "User"
  },
  "tags": null,
  "template": null,
  "templateLink": null,
  "type": "Microsoft.Resources/deploymentStacks"
}

관리되는 리소스를 배포 스택에 나열하여 배포를 확인할 수도 있습니다.

az stack group show \
  --name 'demoStack' \
  --resource-group 'demoRg' \
  --output 'json'

는 다음과 유사하게 출력됩니다.

{
  "actionOnUnmanage": {
    "managementGroups": "detach",
    "resourceGroups": "detach",
    "resources": "detach"
  },
  "debugSetting": null,
  "deletedResources": [],
  "denySettings": {
    "applyToChildScopes": false,
    "excludedActions": null,
    "excludedPrincipals": null,
    "mode": "none"
  },
  "deploymentId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/demoRg/providers/Microsoft.Resources/deployments/demoStack-2023-06-05-20-55-48-38d09",
  "deploymentScope": null,
  "description": null,
  "detachedResources": [],
  "duration": "PT29.006353S",
  "error": null,
  "failedResources": [],
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/demoRg/providers/Microsoft.Resources/deploymentStacks/demoStack",
  "location": null,
  "name": "demoStack",
  "outputs": null,
  "parameters": {},
  "parametersLink": null,
  "provisioningState": "succeeded",
  "resourceGroup": "demoRg",
  "resources": [
    {
      "denyStatus": "none",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/demoRg/providers/Microsoft.Network/virtualNetworks/vnetzu6pnx54hqubm",
      "resourceGroup": "demoRg",
      "status": "managed"
    },
    {
      "denyStatus": "none",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/demoRg/providers/Microsoft.Storage/storageAccounts/storezu6pnx54hqubm",
      "resourceGroup": "demoRg",
      "status": "managed"
    }
  ],
  "systemData": {
    "createdAt": "2023-06-05T20:55:48.006789+00:00",
    "createdBy": "johndole@contoso.com",
    "createdByType": "User",
    "lastModifiedAt": "2023-06-05T20:55:48.006789+00:00",
    "lastModifiedBy": "johndole@contoso.com",
    "lastModifiedByType": "User"
  },
  "tags": null,
  "template": null,
  "templateLink": null,
  "type": "Microsoft.Resources/deploymentStacks"
}

스택이 만들어지면 Azure Portal을 통해 스택 자체와 스택과 연결된 관리되는 리소스 모두에 액세스하고 볼 수 있습니다. 스택이 배포된 리소스 그룹으로 이동하면 모든 관련 정보 및 설정에 액세스할 수 있습니다.

Screenshot of a deployment stack in the Azure portal.

배포 스택 업데이트

배포 스택을 업데이트하려면 기본 Bicep 파일을 수정하고 배포 스택 만들기 명령을 다시 실행하면 됩니다.

main.bicep을 편집하여 SKU 이름을 Standard_LRS에서 Standard_GRS로 변경합니다.

다음 명령을 실행합니다.

az stack group create \
  --name 'demoStack' \
  --resource-group 'demoRg' \
  --template-file './main.bicep' \
  --deny-settings-mode 'none'

Azure Portal에서 스토리지 계정의 속성을 검사하여 변경 사항을 확인합니다.

동일한 방법을 사용하여 배포 스택에 리소스를 추가하거나 배포 스택에서 관리되는 리소스를 제거할 수 있습니다. 자세한 내용은 배포 스택에 리소스 추가배포 스택에서 관리되는 리소스 삭제를 참조하세요.

배포 스택 삭제

배포 스택 및 관리되는 리소스를 삭제하려면 다음을 수행합니다.

az stack group delete \
  --name 'demoStack' \
  --resource-group 'demoRg' \
  --delete-all

delete all 매개 변수 없이 delete 명령을 실행하면 관리되는 리소스가 분리되지만 삭제되지는 않습니다. 예시:

az stack group delete \
  --name 'demoStack' \
  --resource-group 'demoRg'

다음 매개 변수는 분리와 삭제 간을 제어하는 데 사용할 수 있습니다.

  • --delete-all: 리소스와 리소스 그룹을 모두 삭제합니다.
  • --delete-resources: 리소스만 삭제합니다.
  • --delete-resource-groups: 리소스 그룹만 삭제합니다. delete-resource-groups를 단독으로 사용하는 것은 유효하지 않습니다. delete-resource-groupsdelete-resources와 함께 사용해야 합니다.

자세한 내용은 배포 스택 삭제를 참조하세요.

remove 명령은 관리되는 리소스 및 관리되는 리소스 그룹을 단독으로 제거합니다. 배포 스택에서 관리되지 않는 리소스 그룹을 삭제할 책임은 사용자에게 있습니다.

리소스 정리

관리되지 않는 리소스 그룹을 삭제합니다.

az group delete --name 'demoRg'

다음 단계