다음을 통해 공유


빠른 시작: Bicep을 사용하여 Azure DocumentDB 클러스터 배포

이 빠른 시작에서는 Bicep을 사용하여 새 Azure DocumentDB 클러스터를 배포합니다. 이 빠른 시작에서는 빠르게 시작하는 데 도움이 되는 단계별 지침을 제공합니다. 이 클러스터에는 모든 MongoDB 리소스(데이터베이스, 컬렉션 및 문서)가 포함됩니다. Azure DocumentDB에 연결하고 작업을 수행할 수 있는 도구 및 SDK(소프트웨어 개발 키트)에 대한 고유한 엔드포인트를 제공합니다.

필수 조건

  • Azure 구독

환경 구성

구독에서 Azure DocumentDB 리소스를 관리하도록 Azure CLI 환경을 설정합니다.

  1. 빈 디렉터리에서 시작합니다.

  2. Azure CLI에 로그인합니다.

    az login
    
  3. 대상 Azure 구독을 확인합니다.

    az account show
    

    비고

    예상한 구독에 연결되지 않은 경우 다음 명령을 사용하여 구독을 변경합니다.

    az account set --subscription "<subscription-name>"
    

    자세한 내용은 Azure CLI를 사용하여 Azure 구독 관리를 참조하세요.

Bicep 템플릿을 준비하세요.

Azure DocumentDB 클러스터를 배포하는 데 필요한 리소스를 정의하도록 Bicep 파일을 만들고 구성합니다.

  1. 프로젝트 디렉터리에 새 main.bicep 파일을 만듭니다.

  2. 파일의 콘텐츠에 이 템플릿을 추가합니다.

    @description('Cluster name')
    @minLength(8)
    @maxLength(40)
    param clusterName string = 'msdocs-${uniqueString(resourceGroup().id)}'
    
    @description('Location for the cluster.')
    param location string = resourceGroup().location
    
    @description('Username for admin user')
    param adminUsername string
    
    @secure()
    @description('Password for admin user')
    @minLength(8)
    @maxLength(128)
    param adminPassword string
    
    resource cluster 'Microsoft.DocumentDB/mongoClusters@2025-09-01' = {
      name: clusterName
      location: location
      properties: {
        administrator: {
          userName: adminUsername
          password: adminPassword
        }
        serverVersion: '8.0'
        sharding: {
          shardCount: 1
        }
        storage: {
          sizeGb: 32
        }
        highAvailability: {
          targetMode: 'Disabled'
        }
        compute: {
          tier: 'M10'
        }
      }
    }
    
    resource firewallRules 'Microsoft.DocumentDB/mongoClusters/firewallRules@2025-09-01' = {
      parent: cluster
      name: 'AllowAllAzureServices'
      properties: {
        startIpAddress: '0.0.0.0'
        endIpAddress: '0.0.0.0'
      }
    }
    

    팁 (조언)

    리소스를 사용하는 Microsoft.DocumentDB/mongoclusters 옵션에 대한 자세한 내용은 설명서를 참조Microsoft.DocumentDB/mongoclusters하세요.

템플릿 배포

Azure Resource Manager 배포를 사용하여 이전 단계에서 만든 템플릿을 배포합니다.

  1. az group create 명령을 사용하여 구독에 새 리소스 그룹을 만듭니다.

    az group create \
        --name "<resource-group-name>" \
        --location "<location>"
    
  2. bicep 템플릿을 배포하려면 az deployment group create를 사용하십시오. 그런 다음 adminUsernameadminPassword 매개 변수에 대한 값을 입력하라는 메시지가 표시됩니다.

    az deployment group create \
        --resource-group "<resource-group-name>" \
        --template-file 'main.bicep'
    

    팁 (조언)

    또는 미리 정의된 값이 있는 매개 변수 파일을 전달하는 옵션을 사용합니다 --parameters .

    az deployment group create \
        --resource-group "<resource-group-name>" \
        --template-file 'main.bicep' \
        --parameters @main.parameters.json
    

    이 예제 JSON 파일은 clusteradmin 값과 P@ssw.rd 값을 각각 adminUsernameadminPassword 매개 변수에 삽입합니다.

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "adminUsername": {
          "value": "clusteradmin"
        },
        "adminPassword": {
          "value": "P@ssw.rd"
        }
      }
    }
    
  3. 계속 진행하기 전에 배포 작업이 완료되기를 기다립니다.

배포된 리소스 검토

리소스 그룹에 배포된 Azure DocumentDB 리소스를 나열합니다.

  1. 리소스 그룹의 리소스 목록을 가져오는 데 사용합니다 az resource list .

    az resource list \
        --resource-group "<resource-group-name>" \
        --namespace "Microsoft.DocumentDB" \
        --resource-type "mongoClusters" \
        --query "[].name" \
        --output json
    
  2. 예제 출력에서 형식 Microsoft.DocumentDB/mongoClusters이 있는 리소스를 찾습니다. 다음은 예상할 출력 형식의 예입니다.

    [
      "msdocs-documentdb-example-cluster"
    ]
    

자원을 정리하세요

Azure DocumentDB 클러스터를 완료하면 더 많은 요금이 발생하지 않도록 만든 Azure 리소스를 삭제할 수 있습니다.

  1. 구독에서 리소스 그룹을 제거하는 데 사용합니다 az group delete .

    az group delete \
        --name "<resource-group-name>" \
        --yes \
        --no-wait
    

    중요합니다

    이 명령을 실행하기 전에 리소스가 영구적으로 삭제되므로 리소스가 더 이상 필요하지 않은지 확인합니다.