다음을 통해 공유


Bicep을 사용하여 Azure Cosmos DB for Table 리소스 관리

적용 대상: 테이블

이 문서에서는 Bicep을 사용하여 Azure Cosmos DB for Table 계정 및 테이블을 배포하고 관리하는 방법을 알아봅니다.

이 문서에는 API for Table 계정에 대한 예만 있습니다. Cassandra, Gremlin, MongoDB, SQL 문서에 대한 Bicep 샘플도 찾을 수 있습니다.

Important

  • 계정 이름은 44자(모두 소문자)로 제한됩니다.
  • 처리량 값을 변경하려면 업데이트된 RU/s로 템플릿을 다시 배포합니다.
  • Azure Cosmos DB 계정에 위치를 추가하거나 제거하면 다른 속성을 동시에 수정할 수 없습니다. 이러한 작업은 별도로 수행해야 합니다.

아래의 Azure Cosmos DB 리소스를 만들려면 다음 예제를 새 bicep 파일에 복사합니다. 필요에 따라 이름 및 값이 다른 동일한 리소스의 여러 인스턴스를 배포할 때 매개 변수 파일을 만들 수 있습니다. Azure CLI, Azure PowerShellCloud Shell을 비롯한 Azure Resource Manager 템플릿을 배포할 수 있는 여러 가지 방법이 있습니다.

ARM 템플릿 또는 Bicep을 사용하여 계정 수준 처리량을 사용하도록 설정할 수 없습니다. Table용 API를 사용할 때 공유 처리량을 사용하도록 설정하려면 Azure CLI 또는 PowerShell을 사용합니다.

자동 크기 조정 처리량이 있는 Table에 대한 Azure Cosmos DB 계정

자동 크기 조정 처리량이 있는 하나의 테이블이 있는 API for Table에 대한 Azure Cosmos DB 계정을 만듭니다.

@description('Cosmos DB account name')
param accountName string = 'table-${uniqueString(resourceGroup().id)}'

@description('Location for the Cosmos DB account.')
param ___location string = resourceGroup().___location

@description('The primary region for the Cosmos DB account.')
param primaryRegion string

@description('The secondary region for the Cosmos DB account.')
param secondaryRegion string

@description('The default consistency level of the Cosmos DB account.')
@allowed([
  'Eventual'
  'ConsistentPrefix'
  'Session'
  'BoundedStaleness'
  'Strong'
])
param defaultConsistencyLevel string = 'Session'

@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.')
@minValue(10)
@maxValue(2147483647)
param maxStalenessPrefix int = 100000

@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
@minValue(5)
@maxValue(86400)
param maxIntervalInSeconds int = 300

@description('Enable system managed failover for regions')
param systemManagedFailover bool = true

@description('The name for the table')
param tableName string

@description('Maximum autoscale throughput for the table')
@minValue(1000)
@maxValue(1000000)
param autoscaleMaxThroughput int = 4000

var consistencyPolicy = {
  Eventual: {
    defaultConsistencyLevel: 'Eventual'
  }
  ConsistentPrefix: {
    defaultConsistencyLevel: 'ConsistentPrefix'
  }
  Session: {
    defaultConsistencyLevel: 'Session'
  }
  BoundedStaleness: {
    defaultConsistencyLevel: 'BoundedStaleness'
    maxStalenessPrefix: maxStalenessPrefix
    maxIntervalInSeconds: maxIntervalInSeconds
  }
  Strong: {
    defaultConsistencyLevel: 'Strong'
  }
}
var locations = [
  {
    locationName: primaryRegion
    failoverPriority: 0
    isZoneRedundant: false
  }
  {
    locationName: secondaryRegion
    failoverPriority: 1
    isZoneRedundant: false
  }
]

resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
  name: toLower(accountName)
  ___location: ___location
  kind: 'GlobalDocumentDB'
  properties: {
    capabilities: [
      {
        name: 'EnableTable'
      }
    ]
    consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
    locations: locations
    databaseAccountOfferType: 'Standard'
    enableAutomaticFailover: systemManagedFailover
  }
}

resource table 'Microsoft.DocumentDB/databaseAccounts/tables@2022-05-15' = {
  parent: account
  name: tableName
  properties: {
    resource: {
      id: tableName
    }
    options: {
      autoscaleSettings: {
        maxThroughput: autoscaleMaxThroughput
      }
    }
  }
}

표준 프로비전된 처리량이 있는 Table에 대한 Azure Cosmos DB 계정

표준 처리량이 있는 하나의 테이블이 있는 API for Table에 대한 Azure Cosmos DB 계정을 만듭니다.

@description('Cosmos DB account name')
param accountName string = 'table-${uniqueString(resourceGroup().id)}'

@description('Location for the Cosmos DB account.')
param ___location string = resourceGroup().___location

@description('The primary region for the Cosmos DB account.')
param primaryRegion string

@description('The secondary region for the Cosmos DB account.')
param secondaryRegion string

@description('The default consistency level of the Cosmos DB account.')
@allowed([
  'Eventual'
  'ConsistentPrefix'
  'Session'
  'BoundedStaleness'
  'Strong'
])
param defaultConsistencyLevel string = 'Session'

@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.')
@minValue(10)
@maxValue(2147483647)
param maxStalenessPrefix int = 100000

@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
@minValue(5)
@maxValue(86400)
param maxIntervalInSeconds int = 300

@description('Enable system managed failover for regions')
param systemManagedFailover bool = true

@description('The name for the table')
param tableName string

@minValue(400)
@maxValue(1000000)
@description('The throughput for the table')
param throughput int = 400

var consistencyPolicy = {
  Eventual: {
    defaultConsistencyLevel: 'Eventual'
  }
  ConsistentPrefix: {
    defaultConsistencyLevel: 'ConsistentPrefix'
  }
  Session: {
    defaultConsistencyLevel: 'Session'
  }
  BoundedStaleness: {
    defaultConsistencyLevel: 'BoundedStaleness'
    maxStalenessPrefix: maxStalenessPrefix
    maxIntervalInSeconds: maxIntervalInSeconds
  }
  Strong: {
    defaultConsistencyLevel: 'Strong'
  }
}
var locations = [
  {
    locationName: primaryRegion
    failoverPriority: 0
    isZoneRedundant: false
  }
  {
    locationName: secondaryRegion
    failoverPriority: 1
    isZoneRedundant: false
  }
]

resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
  name: toLower(accountName)
  ___location: ___location
  kind: 'GlobalDocumentDB'
  properties: {
    capabilities: [
      {
        name: 'EnableTable'
      }
    ]
    consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
    locations: locations
    databaseAccountOfferType: 'Standard'
    enableAutomaticFailover: systemManagedFailover
  }
}

resource table 'Microsoft.DocumentDB/databaseAccounts/tables@2022-05-15' = {
  parent: account
  name: tableName
  properties: {
    resource: {
      id: tableName
    }
    options: {
      throughput: throughput
    }
  }
}

다음 단계

다음은 몇 가지 추가 리소스입니다.