Microsoft。DocumentDB mongoClusters 2026-06-01

Bicep リソース定義

mongoClusters リソースの種類は、次をターゲットとする操作でデプロイできます。

  • リソース グループの - リソース グループのデプロイ コマンド 参照

各 API バージョンで変更されたプロパティの一覧については、変更ログの参照してください。

使用例

Azure 検証済みモジュール

以下のAzure検証済みモジュールはこのリソースタイプの展開に使用できます。

モジュール Description
Cosmos DB for MongoDB (仮想コア) Cosmos DB for MongoDB (仮想コア) 用 AVM リソース モジュール

リソース形式

Microsoft.DocumentDB/mongoClusters リソースを作成するには、次の Bicep をテンプレートに追加します。

resource symbolicname 'Microsoft.DocumentDB/mongoClusters@2026-06-01' = {
  identity: {
    type: 'string'
    userAssignedIdentities: {
      {customized property}: {}
    }
  }
  location: 'string'
  name: 'string'
  properties: {
    administrator: {
      password: 'string'
      userName: 'string'
    }
    authConfig: {
      allowedModes: [
        'string'
      ]
    }
    backup: {}
    compute: {
      tier: 'string'
    }
    createMode: 'string'
    dataApi: {
      mode: 'string'
    }
    encryption: {
      customerManagedKeyEncryption: {
        keyEncryptionKeyIdentity: {
          identityType: 'string'
          userAssignedIdentityResourceId: 'string'
        }
        keyEncryptionKeyUrl: 'string'
      }
    }
    highAvailability: {
      targetMode: 'string'
    }
    networkBypassMode: 'string'
    previewFeatures: [
      'string'
    ]
    publicNetworkAccess: 'string'
    replicaParameters: {
      sourceLocation: 'string'
      sourceResourceId: 'string'
    }
    restoreParameters: {
      pointInTimeUTC: 'string'
      sourceResourceId: 'string'
    }
    serverVersion: 'string'
    sharding: {
      shardCount: int
    }
    storage: {
      sizeGb: int
      type: 'string'
    }
  }
  tags: {
    {customized property}: 'string'
  }
}

プロパティ値

Microsoft.DocumentDB/mongoClusters

名前 Description Value
ID このリソースに割り当てられているマネージド サービス ID。 ManagedServiceIdentity の
位置 リソースが存在する地理的な場所 string (必須)
名前 リソース名 string

制約:
最小長 = 3
最大長 = 40
パターン = ^[a-z0-9]+(-[a-z0-9]+)* (必須)
properties このリソースのリソース固有のプロパティ。 MongoClusterProperties の
tags リソース タグ タグ名と値のディクショナリ。 テンプレート の タグを参照してください

AdministratorProperties

名前 Description Value
パスワード 管理者パスワード。 string

制約:
機密値。 セキュリティで保護されたパラメーターとして渡します。
userName 管理者ユーザー名。 文字列

AuthConfigプロパティ

名前 Description Value
allowedModes(allowedModes) クラスター上のデータ アクセスに許可される認証モード。 次のいずれかを含む文字列配列:
「MicrosoftEntraID」
「ネイティブ認証」

バックアッププロパティ

名前 Description Value

ComputeProperties

名前 Description Value
レベル クラスターに割り当てるコンピューティング レベル。各層は仮想コアとメモリ サイズにマップされます。 値の例: 'M30'、'M40'。 文字列

CustomerManagedKeyEncryptionProperties

名前 Description Value
keyEncryptionKeyIdentity キー暗号化キーへのアクセスに使用される ID。 キー暗号化キーアイデンティティ
キー暗号化キーURL 暗号化に使用されるキー コンテナー キーの URI。 文字列

DataApiプロパティ

名前 Description Value
mode クラスターに対して Mongo Data API が有効になっているかどうかを示すモード。 'Disabled'
'Enabled'

EncryptionProperties (暗号化プロパティ)

名前 Description Value
customerManagedKey暗号化 カスタマー マネージド キー暗号化設定。 CustomerManagedKey暗号化プロパティ

HighAvailabilityProperties

名前 Description Value
ターゲットモード クラスターに対して要求されたターゲット高可用性モード。 'Disabled'
「SameZone」
'ZoneRedundantPreferred' (ゾーン冗長優先)

KeyEncryptionKeyIdentity

名前 Description Value
identityType ID の種類。 'UserAssignedIdentity' のみがサポートされています。 'UserAssignedIdentity'
userAssignedIdentityリソースID ユーザーが割り当てたアイデンティティ・リソースID。 文字列

マネージドサービスアイデンティティ

名前 Description Value
マネージド サービス ID の種類 (SystemAssigned 型と UserAssigned 型の両方が許可されます)。 'None'
'SystemAssigned'
'SystemAssigned,UserAssigned'
'UserAssigned' (必須)
userAssignedIdentities リソースに関連付けられているユーザー割り当て ID のセット。 userAssignedIdentitiesの辞書キーは、次の形でARMリソースIDとなります:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. ディクショナリ値は、要求内の空のオブジェクト ({}) にすることができます。 UserAssignedIdentities

MongoClusterプロパティ

名前 Description Value
管理者 mongo クラスターのローカル管理者プロパティ。 AdministratorProperties
authConfigの クラスタの認証設定。 AuthConfigプロパティ
バックアップ Mongo クラスターのバックアップ プロパティ。 バックアッププロパティ
コンピューティング mongo クラスターのコンピューティング プロパティ。 コンピュートプロパティ
クリエイトモード Mongo クラスターを作成するモード。 'Default'
「ジオレプリカ」
「PointInTimeRestore」
「レプリカ」
データAPI Mongo クラスターの Data API プロパティ。 DataApiプロパティ
暗号化 クラスターの暗号化構成。 構成されている ID によって異なります。 EncryptionProperties (暗号化プロパティ)
高い可用性 Mongo クラスターの高可用性プロパティ。 HighAvailabilityProperties の
ネットワークバイパスモード クラスターのネットワークバイパスモードです。 「AzureCosmosDB」に設定すると、Azure Cosmos DBサービスがネットワーク制限を回避できます。 『AzureCosmosDB』
'None'
プレビュー機能 プライベート エンドポイント接続の一覧。 次のいずれかを含む文字列配列:
「ジオレプリカ」
publicNetworkAccess この Mongo クラスターに対してパブリック エンドポイント アクセスが許可されているかどうか。 'Disabled'
'Enabled'
replicaParameters (レプリカパラメータ) レプリカ Mongo クラスターを作成するためのパラメーター。 MongoClusterReplicaParameters (英語)
restoreParameters (リストアパラメータ) ポイントインタイム リストア Mongo クラスターを作成するためのパラメーター。 MongoClusterRestoreParameters (モンゴクラスタ復元パラメータ)
サーバーバージョン Mongo DB サーバーのバージョン。 指定されていない場合は、既定で使用可能な最新バージョンが使用されます。 文字列
シャーディング mongo クラスターのシャーディング プロパティ。 シャーディングプロパティ
ストレージ mongo クラスターのストレージ プロパティ。 ストレージプロパティ

MongoClusterReplicaParameters

名前 Description Value
sourceLocation ソース クラスターの場所 string (必須)
ソースリソースID レプリケーション ソース クラスターの ID。 string (必須)

MongoClusterRestoreParameters (モンゴクラスタ復元パラメータ)

名前 Description Value
ポイントインタイムUTC MONGO クラスターを復元する UTC ポイント イン タイム 文字列
ソースリソースID 復元するソース クラスターを検索するリソース ID 文字列

ShardingProperties

名前 Description Value
シャードカウント クラスターにプロビジョニングするシャードの数。 int

StorageProperties

名前 Description Value
サイズGB 各サーバーに割り当てられているデータ ディスクのサイズ。 int
クラスタ サーバをプロビジョニングするストレージのタイプ。 「プレミアムSSD」
「プレミアムSSDv2」

TrackedResourceTags

名前 Description Value

UserAssignedIdentities

名前 Description Value

UserAssignedIdentity

名前 Description Value

ARM テンプレート リソース定義

mongoClusters リソースの種類は、次をターゲットとする操作でデプロイできます。

使用例

リソース形式

Microsoft.DocumentDB/mongoClusters リソースを作成するには、次の JSON をテンプレートに追加します。

{
  "type": "Microsoft.DocumentDB/mongoClusters",
  "apiVersion": "2026-06-01",
  "name": "string",
  "identity": {
    "type": "string",
    "userAssignedIdentities": {
      "{customized property}": {
      }
    }
  },
  "location": "string",
  "properties": {
    "administrator": {
      "password": "string",
      "userName": "string"
    },
    "authConfig": {
      "allowedModes": [ "string" ]
    },
    "backup": {
    },
    "compute": {
      "tier": "string"
    },
    "createMode": "string",
    "dataApi": {
      "mode": "string"
    },
    "encryption": {
      "customerManagedKeyEncryption": {
        "keyEncryptionKeyIdentity": {
          "identityType": "string",
          "userAssignedIdentityResourceId": "string"
        },
        "keyEncryptionKeyUrl": "string"
      }
    },
    "highAvailability": {
      "targetMode": "string"
    },
    "networkBypassMode": "string",
    "previewFeatures": [ "string" ],
    "publicNetworkAccess": "string",
    "replicaParameters": {
      "sourceLocation": "string",
      "sourceResourceId": "string"
    },
    "restoreParameters": {
      "pointInTimeUTC": "string",
      "sourceResourceId": "string"
    },
    "serverVersion": "string",
    "sharding": {
      "shardCount": "int"
    },
    "storage": {
      "sizeGb": "int",
      "type": "string"
    }
  },
  "tags": {
    "{customized property}": "string"
  }
}

プロパティ値

Microsoft.DocumentDB/mongoClusters

名前 Description Value
apiVersion API のバージョン '2026-06-01'
ID このリソースに割り当てられているマネージド サービス ID。 ManagedServiceIdentity の
位置 リソースが存在する地理的な場所 string (必須)
名前 リソース名 string

制約:
最小長 = 3
最大長 = 40
パターン = ^[a-z0-9]+(-[a-z0-9]+)* (必須)
properties このリソースのリソース固有のプロパティ。 MongoClusterProperties の
tags リソース タグ タグ名と値のディクショナリ。 テンプレート の タグを参照してください
リソースの種類 'Microsoft.DocumentDB/mongoClusters'

AdministratorProperties

名前 Description Value
パスワード 管理者パスワード。 string

制約:
機密値。 セキュリティで保護されたパラメーターとして渡します。
userName 管理者ユーザー名。 文字列

AuthConfigプロパティ

名前 Description Value
allowedModes(allowedModes) クラスター上のデータ アクセスに許可される認証モード。 次のいずれかを含む文字列配列:
「MicrosoftEntraID」
「ネイティブ認証」

バックアッププロパティ

名前 Description Value

ComputeProperties

名前 Description Value
レベル クラスターに割り当てるコンピューティング レベル。各層は仮想コアとメモリ サイズにマップされます。 値の例: 'M30'、'M40'。 文字列

CustomerManagedKeyEncryptionProperties

名前 Description Value
keyEncryptionKeyIdentity キー暗号化キーへのアクセスに使用される ID。 キー暗号化キーアイデンティティ
キー暗号化キーURL 暗号化に使用されるキー コンテナー キーの URI。 文字列

DataApiプロパティ

名前 Description Value
mode クラスターに対して Mongo Data API が有効になっているかどうかを示すモード。 'Disabled'
'Enabled'

EncryptionProperties (暗号化プロパティ)

名前 Description Value
customerManagedKey暗号化 カスタマー マネージド キー暗号化設定。 CustomerManagedKey暗号化プロパティ

HighAvailabilityProperties

名前 Description Value
ターゲットモード クラスターに対して要求されたターゲット高可用性モード。 'Disabled'
「SameZone」
'ZoneRedundantPreferred' (ゾーン冗長優先)

KeyEncryptionKeyIdentity

名前 Description Value
identityType ID の種類。 'UserAssignedIdentity' のみがサポートされています。 'UserAssignedIdentity'
userAssignedIdentityリソースID ユーザーが割り当てたアイデンティティ・リソースID。 文字列

マネージドサービスアイデンティティ

名前 Description Value
マネージド サービス ID の種類 (SystemAssigned 型と UserAssigned 型の両方が許可されます)。 'None'
'SystemAssigned'
'SystemAssigned,UserAssigned'
'UserAssigned' (必須)
userAssignedIdentities リソースに関連付けられているユーザー割り当て ID のセット。 userAssignedIdentitiesの辞書キーは、次の形でARMリソースIDとなります:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. ディクショナリ値は、要求内の空のオブジェクト ({}) にすることができます。 UserAssignedIdentities

MongoClusterプロパティ

名前 Description Value
管理者 mongo クラスターのローカル管理者プロパティ。 AdministratorProperties
authConfigの クラスタの認証設定。 AuthConfigプロパティ
バックアップ Mongo クラスターのバックアップ プロパティ。 バックアッププロパティ
コンピューティング mongo クラスターのコンピューティング プロパティ。 コンピュートプロパティ
クリエイトモード Mongo クラスターを作成するモード。 'Default'
「ジオレプリカ」
「PointInTimeRestore」
「レプリカ」
データAPI Mongo クラスターの Data API プロパティ。 DataApiプロパティ
暗号化 クラスターの暗号化構成。 構成されている ID によって異なります。 EncryptionProperties (暗号化プロパティ)
高い可用性 Mongo クラスターの高可用性プロパティ。 HighAvailabilityProperties の
ネットワークバイパスモード クラスターのネットワークバイパスモードです。 「AzureCosmosDB」に設定すると、Azure Cosmos DBサービスがネットワーク制限を回避できます。 『AzureCosmosDB』
'None'
プレビュー機能 プライベート エンドポイント接続の一覧。 次のいずれかを含む文字列配列:
「ジオレプリカ」
publicNetworkAccess この Mongo クラスターに対してパブリック エンドポイント アクセスが許可されているかどうか。 'Disabled'
'Enabled'
replicaParameters (レプリカパラメータ) レプリカ Mongo クラスターを作成するためのパラメーター。 MongoClusterReplicaParameters (英語)
restoreParameters (リストアパラメータ) ポイントインタイム リストア Mongo クラスターを作成するためのパラメーター。 MongoClusterRestoreParameters (モンゴクラスタ復元パラメータ)
サーバーバージョン Mongo DB サーバーのバージョン。 指定されていない場合は、既定で使用可能な最新バージョンが使用されます。 文字列
シャーディング mongo クラスターのシャーディング プロパティ。 シャーディングプロパティ
ストレージ mongo クラスターのストレージ プロパティ。 ストレージプロパティ

MongoClusterReplicaParameters

名前 Description Value
sourceLocation ソース クラスターの場所 string (必須)
ソースリソースID レプリケーション ソース クラスターの ID。 string (必須)

MongoClusterRestoreParameters (モンゴクラスタ復元パラメータ)

名前 Description Value
ポイントインタイムUTC MONGO クラスターを復元する UTC ポイント イン タイム 文字列
ソースリソースID 復元するソース クラスターを検索するリソース ID 文字列

ShardingProperties

名前 Description Value
シャードカウント クラスターにプロビジョニングするシャードの数。 int

StorageProperties

名前 Description Value
サイズGB 各サーバーに割り当てられているデータ ディスクのサイズ。 int
クラスタ サーバをプロビジョニングするストレージのタイプ。 「プレミアムSSD」
「プレミアムSSDv2」

TrackedResourceTags

名前 Description Value

UserAssignedIdentities

名前 Description Value

UserAssignedIdentity

名前 Description Value

Terraform (AzAPI プロバイダー) リソース定義

mongoClusters リソースの種類は、次をターゲットとする操作でデプロイできます。

  • リソースグループ 各APIバージョンの変更プロパティ一覧については、 変更ログをご覧ください。

使用例

Terraform サンプル

MongoDB(vCore)向けにAzure Cosmos DBをデプロイする基本的な例です。

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
    time = {
      source = "hashicorp/time"
    }
  }
}

provider "azapi" {
  skip_provider_registration = false
}

variable "resource_name" {
  type    = string
  default = "acctest0001"
}

variable "location" {
  type    = string
  default = "westus3"
}

variable "replica_location" {
  type    = string
  default = "centralus"
}

variable "mongo_admin_username" {
  type    = string
  default = "mongoAdmin"
}

variable "mongo_admin_password" {
  type        = string
  description = "The administrator password for the MongoDB cluster"
  sensitive   = true
}

variable "mongo_restore_admin_password" {
  type        = string
  description = "The administrator password for the restored MongoDB cluster"
  sensitive   = true
}

resource "azapi_resource" "resourceGroup" {
  type     = "Microsoft.Resources/resourceGroups@2020-06-01"
  name     = var.resource_name
  location = var.location
}

resource "azapi_resource" "userAssignedIdentity" {
  type                      = "Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31"
  parent_id                 = azapi_resource.resourceGroup.id
  name                      = var.resource_name
  location                  = var.location
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

data "azapi_client_config" "current" {}

resource "azapi_resource" "vault" {
  type      = "Microsoft.KeyVault/vaults@2023-02-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = "${var.resource_name}-kv"
  location  = var.location
  body = {
    properties = {
      createMode                   = "default"
      enablePurgeProtection        = true
      enableSoftDelete             = true
      enableRbacAuthorization      = true
      enabledForDeployment         = true
      enabledForDiskEncryption     = true
      enabledForTemplateDeployment = true
      publicNetworkAccess          = "Enabled"
      accessPolicies               = []
      sku = {
        family = "A"
        name   = "standard"
      }
      tenantId = data.azapi_client_config.current.tenant_id
    }
  }
}

data "azapi_resource_list" "kvCertificatesOfficerRoleDefinition" {
  type      = "Microsoft.Authorization/roleDefinitions@2022-04-01"
  parent_id = azapi_resource.vault.id
  response_export_values = {
    definition_id = "value[?properties.roleName == 'Key Vault Crypto Officer'].id | [0]"
  }
}

resource "azapi_resource" "kvRoleAssignmentTf" {
  type      = "Microsoft.Authorization/roleAssignments@2022-04-01"
  parent_id = azapi_resource.vault.id
  name      = uuid()
  body = {
    properties = {
      principalId      = data.azapi_client_config.current.object_id
      roleDefinitionId = data.azapi_resource_list.kvCertificatesOfficerRoleDefinition.output.definition_id
    }
  }
  lifecycle {
    ignore_changes = [name]
  }
}

data "azapi_resource_list" "kvCertificatesUserRoleDefinition" {
  type      = "Microsoft.Authorization/roleDefinitions@2022-04-01"
  parent_id = azapi_resource.vault.id
  response_export_values = {
    definition_id = "value[?properties.roleName == 'Key Vault Crypto Service Encryption User'].id | [0]"
  }
}

resource "azapi_resource" "kvRoleAssignmentIdentity" {
  type      = "Microsoft.Authorization/roleAssignments@2022-04-01"
  parent_id = azapi_resource.vault.id
  name      = uuid()
  body = {
    properties = {
      principalId      = azapi_resource.userAssignedIdentity.output.properties.principalId
      roleDefinitionId = data.azapi_resource_list.kvCertificatesUserRoleDefinition.output.definition_id
    }
  }
  lifecycle {
    ignore_changes = [name]
  }
}

data "azapi_resource_id" "key" {
  type      = "Microsoft.KeyVault/vaults/keys@2023-02-01"
  parent_id = azapi_resource.vault.id
  name      = var.resource_name
}

resource "azapi_resource_action" "key" {
  type        = "Microsoft.KeyVault/vaults/keys@2023-02-01"
  resource_id = data.azapi_resource_id.key.id
  method      = "PUT"
  body = {
    properties = {
      keySize = 2048
      kty     = "RSA"
      keyOps  = ["encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey"]
    }
  }
  response_export_values = ["*"]
  depends_on = [
    azapi_resource.kvRoleAssignmentTf,
    azapi_resource.kvRoleAssignmentIdentity,
  ]
}

# replica key vault

resource "azapi_resource" "vault_replica" {
  type      = "Microsoft.KeyVault/vaults@2023-02-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = "${var.resource_name}-kv-replica"
  location  = var.replica_location
  body = {
    properties = {
      createMode                   = "default"
      enablePurgeProtection        = true
      enableSoftDelete             = true
      enableRbacAuthorization      = true
      enabledForDeployment         = true
      enabledForDiskEncryption     = true
      enabledForTemplateDeployment = true
      publicNetworkAccess          = "Enabled"
      accessPolicies               = []
      sku = {
        family = "A"
        name   = "standard"
      }
      tenantId = data.azapi_client_config.current.tenant_id
    }
  }
}

data "azapi_resource_list" "kvCertificatesOfficerRoleDefinition_replica" {
  type      = "Microsoft.Authorization/roleDefinitions@2022-04-01"
  parent_id = azapi_resource.vault_replica.id
  response_export_values = {
    definition_id = "value[?properties.roleName == 'Key Vault Crypto Officer'].id | [0]"
  }
}

resource "azapi_resource" "kvRoleAssignmentTf_replica" {
  type      = "Microsoft.Authorization/roleAssignments@2022-04-01"
  parent_id = azapi_resource.vault_replica.id
  name      = uuid()
  body = {
    properties = {
      principalId      = data.azapi_client_config.current.object_id
      roleDefinitionId = data.azapi_resource_list.kvCertificatesOfficerRoleDefinition.output.definition_id
    }
  }
  lifecycle {
    ignore_changes = [name]
  }
}

data "azapi_resource_list" "kvCertificatesUserRoleDefinition_replica" {
  type      = "Microsoft.Authorization/roleDefinitions@2022-04-01"
  parent_id = azapi_resource.vault_replica.id
  response_export_values = {
    definition_id = "value[?properties.roleName == 'Key Vault Crypto Service Encryption User'].id | [0]"
  }
}

resource "azapi_resource" "kvRoleAssignmentIdentity_replica" {
  type      = "Microsoft.Authorization/roleAssignments@2022-04-01"
  parent_id = azapi_resource.vault_replica.id
  name      = uuid()
  body = {
    properties = {
      principalId      = azapi_resource.userAssignedIdentity.output.properties.principalId
      roleDefinitionId = data.azapi_resource_list.kvCertificatesUserRoleDefinition.output.definition_id
    }
  }
  lifecycle {
    ignore_changes = [name]
  }
}

data "azapi_resource_id" "key_replica" {
  type      = "Microsoft.KeyVault/vaults/keys@2023-02-01"
  parent_id = azapi_resource.vault_replica.id
  name      = var.resource_name
}

resource "azapi_resource_action" "key_replica" {
  type        = "Microsoft.KeyVault/vaults/keys@2023-02-01"
  resource_id = data.azapi_resource_id.key_replica.id
  method      = "PUT"
  body = {
    properties = {
      keySize = 2048
      kty     = "RSA"
      keyOps  = ["encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey"]
    }
  }
  response_export_values = ["*"]
  depends_on = [
    azapi_resource.kvRoleAssignmentTf_replica,
    azapi_resource.kvRoleAssignmentIdentity_replica,
  ]
}

resource "azapi_resource" "mongoCluster" {
  type      = "Microsoft.DocumentDB/mongoClusters@2025-09-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = var.resource_name
  location  = var.location
  identity {
    type         = "UserAssigned"
    identity_ids = [azapi_resource.userAssignedIdentity.id]
  }
  body = {
    properties = {
      administrator = {
        userName = var.mongo_admin_username
      }
      authConfig = {
        allowedModes = ["MicrosoftEntraID", "NativeAuth"]
      }
      compute = {
        tier = "M30"
      }
      encryption = {
        customerManagedKeyEncryption = {
          keyEncryptionKeyIdentity = {
            identityType                   = "UserAssignedIdentity"
            userAssignedIdentityResourceId = azapi_resource.userAssignedIdentity.id
          }
          keyEncryptionKeyUrl = azapi_resource_action.key.output.properties.keyUri
        }
      }
      highAvailability = {
        targetMode = "Disabled"
      }
      previewFeatures = [
        "ShardRebalancer"
      ]
      publicNetworkAccess = "Enabled"
      serverVersion       = "5.0"
      sharding = {
        shardCount = 1
      }
      storage = {
        sizeGb = 32
      }
    }
  }
  sensitive_body = {
    properties = {
      administrator = {
        password = var.mongo_admin_password
      }
    }
  }
  tags = {
    Environment = "Test"
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

# Wait for the MongoDB cluster to have backup capability available
resource "time_sleep" "wait_for_backup_ready" {
  depends_on = [azapi_resource.mongoCluster]

  # Wait 5 minutes for backup to be available - MongoDB clusters typically need time to enable backup
  create_duration = "300s"
}

# Data source to get the updated cluster info with backup details
data "azapi_resource" "mongoCluster_backup_check" {
  type        = "Microsoft.DocumentDB/mongoClusters@2025-09-01"
  resource_id = azapi_resource.mongoCluster.id

  response_export_values = ["properties.backup.earliestRestoreTime"]
  depends_on             = [time_sleep.wait_for_backup_ready]
}

resource "azapi_resource" "mongoCluster_PointInTimeRestore" {
  type      = "Microsoft.DocumentDB/mongoClusters@2025-09-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = "${var.resource_name}-restore"
  location  = var.location
  identity {
    type         = "UserAssigned"
    identity_ids = [azapi_resource.userAssignedIdentity.id]
  }
  body = {
    properties = {
      createMode = "PointInTimeRestore"
      administrator = {
        userName = var.mongo_admin_username
      }
      encryption = {
        customerManagedKeyEncryption = {
          keyEncryptionKeyIdentity = {
            identityType                   = "UserAssignedIdentity"
            userAssignedIdentityResourceId = azapi_resource.userAssignedIdentity.id
          }
          keyEncryptionKeyUrl = azapi_resource_action.key.output.properties.keyUri
        }
      }
      restoreParameters = {
        pointInTimeUTC   = data.azapi_resource.mongoCluster_backup_check.output.properties.backup.earliestRestoreTime
        sourceResourceId = azapi_resource.mongoCluster.id
      }
    }
  }
  sensitive_body = {
    properties = {
      administrator = {
        password = var.mongo_restore_admin_password
      }
    }
  }
  schema_validation_enabled = false
  ignore_casing             = false
  ignore_missing_property   = false

  depends_on = [
    data.azapi_resource.mongoCluster_backup_check
  ]
}

resource "azapi_resource" "mongoCluster_GeoReplica" {
  type      = "Microsoft.DocumentDB/mongoClusters@2025-09-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = "${var.resource_name}-repl"
  location  = var.replica_location
  identity {
    type         = "UserAssigned"
    identity_ids = [azapi_resource.userAssignedIdentity.id]
  }
  body = {
    properties = {
      createMode = "GeoReplica"
      encryption = {
        customerManagedKeyEncryption = {
          keyEncryptionKeyIdentity = {
            identityType                   = "UserAssignedIdentity"
            userAssignedIdentityResourceId = azapi_resource.userAssignedIdentity.id
          }
          keyEncryptionKeyUrl = azapi_resource_action.key_replica.output.properties.keyUri
        }
      }
      replicaParameters = {
        sourceLocation   = var.location # Source location matches the primary cluster
        sourceResourceId = azapi_resource.mongoCluster.id
      }
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

Azure 検証済みモジュール

以下のAzure検証済みモジュールはこのリソースタイプの展開に使用できます。

モジュール Description
Cosmos DB for MongoDB (仮想コア) Cosmos DB for MongoDB (仮想コア) 用 AVM リソース モジュール

リソース形式

Microsoft.DocumentDB/mongoClusters リソースを作成するには、次の Terraform をテンプレートに追加します。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.DocumentDB/mongoClusters@2026-06-01"
  name = "string"
  parent_id = "string"
  identity {
    type = "string"
    identity_ids = [
      "string"
    ]
  }
  location = "string"
  tags = {
    {customized property} = "string"
  }
  body = {
    properties = {
      administrator = {
        password = "string"
        userName = "string"
      }
      authConfig = {
        allowedModes = [
          "string"
        ]
      }
      backup = {
      }
      compute = {
        tier = "string"
      }
      createMode = "string"
      dataApi = {
        mode = "string"
      }
      encryption = {
        customerManagedKeyEncryption = {
          keyEncryptionKeyIdentity = {
            identityType = "string"
            userAssignedIdentityResourceId = "string"
          }
          keyEncryptionKeyUrl = "string"
        }
      }
      highAvailability = {
        targetMode = "string"
      }
      networkBypassMode = "string"
      previewFeatures = [
        "string"
      ]
      publicNetworkAccess = "string"
      replicaParameters = {
        sourceLocation = "string"
        sourceResourceId = "string"
      }
      restoreParameters = {
        pointInTimeUTC = "string"
        sourceResourceId = "string"
      }
      serverVersion = "string"
      sharding = {
        shardCount = int
      }
      storage = {
        sizeGb = int
        type = "string"
      }
    }
  }
}

プロパティ値

Microsoft.DocumentDB/mongoClusters

名前 Description Value
ID このリソースに割り当てられているマネージド サービス ID。 ManagedServiceIdentity の
位置 リソースが存在する地理的な場所 string (必須)
名前 リソース名 string

制約:
最小長 = 3
最大長 = 40
パターン = ^[a-z0-9]+(-[a-z0-9]+)* (必須)
properties このリソースのリソース固有のプロパティ。 MongoClusterProperties の
tags リソース タグ タグ名と値のディクショナリ。
リソースの種類 「Microsoft。DocumentDB/mongoClusters@2026-06-01"

AdministratorProperties

名前 Description Value
パスワード 管理者パスワード。 string

制約:
機密値。 セキュリティで保護されたパラメーターとして渡します。
userName 管理者ユーザー名。 文字列

AuthConfigプロパティ

名前 Description Value
allowedModes(allowedModes) クラスター上のデータ アクセスに許可される認証モード。 次のいずれかを含む文字列配列:
「MicrosoftEntraID」
「ネイティブ認証」

バックアッププロパティ

名前 Description Value

ComputeProperties

名前 Description Value
レベル クラスターに割り当てるコンピューティング レベル。各層は仮想コアとメモリ サイズにマップされます。 値の例: 'M30'、'M40'。 文字列

CustomerManagedKeyEncryptionProperties

名前 Description Value
keyEncryptionKeyIdentity キー暗号化キーへのアクセスに使用される ID。 キー暗号化キーアイデンティティ
キー暗号化キーURL 暗号化に使用されるキー コンテナー キーの URI。 文字列

DataApiプロパティ

名前 Description Value
mode クラスターに対して Mongo Data API が有効になっているかどうかを示すモード。 'Disabled'
'Enabled'

EncryptionProperties (暗号化プロパティ)

名前 Description Value
customerManagedKey暗号化 カスタマー マネージド キー暗号化設定。 CustomerManagedKey暗号化プロパティ

HighAvailabilityProperties

名前 Description Value
ターゲットモード クラスターに対して要求されたターゲット高可用性モード。 'Disabled'
「SameZone」
'ZoneRedundantPreferred' (ゾーン冗長優先)

KeyEncryptionKeyIdentity

名前 Description Value
identityType ID の種類。 'UserAssignedIdentity' のみがサポートされています。 'UserAssignedIdentity'
userAssignedIdentityリソースID ユーザーが割り当てたアイデンティティ・リソースID。 文字列

マネージドサービスアイデンティティ

名前 Description Value
マネージド サービス ID の種類 (SystemAssigned 型と UserAssigned 型の両方が許可されます)。 'None'
'SystemAssigned'
'SystemAssigned,UserAssigned'
'UserAssigned' (必須)
userAssignedIdentities リソースに関連付けられているユーザー割り当て ID のセット。 userAssignedIdentitiesの辞書キーは、次の形でARMリソースIDとなります:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. ディクショナリ値は、要求内の空のオブジェクト ({}) にすることができます。 UserAssignedIdentities

MongoClusterプロパティ

名前 Description Value
管理者 mongo クラスターのローカル管理者プロパティ。 AdministratorProperties
authConfigの クラスタの認証設定。 AuthConfigプロパティ
バックアップ Mongo クラスターのバックアップ プロパティ。 バックアッププロパティ
コンピューティング mongo クラスターのコンピューティング プロパティ。 コンピュートプロパティ
クリエイトモード Mongo クラスターを作成するモード。 'Default'
「ジオレプリカ」
「PointInTimeRestore」
「レプリカ」
データAPI Mongo クラスターの Data API プロパティ。 DataApiプロパティ
暗号化 クラスターの暗号化構成。 構成されている ID によって異なります。 EncryptionProperties (暗号化プロパティ)
高い可用性 Mongo クラスターの高可用性プロパティ。 HighAvailabilityProperties の
ネットワークバイパスモード クラスターのネットワークバイパスモードです。 「AzureCosmosDB」に設定すると、Azure Cosmos DBサービスがネットワーク制限を回避できます。 『AzureCosmosDB』
'None'
プレビュー機能 プライベート エンドポイント接続の一覧。 次のいずれかを含む文字列配列:
「ジオレプリカ」
publicNetworkAccess この Mongo クラスターに対してパブリック エンドポイント アクセスが許可されているかどうか。 'Disabled'
'Enabled'
replicaParameters (レプリカパラメータ) レプリカ Mongo クラスターを作成するためのパラメーター。 MongoClusterReplicaParameters (英語)
restoreParameters (リストアパラメータ) ポイントインタイム リストア Mongo クラスターを作成するためのパラメーター。 MongoClusterRestoreParameters (モンゴクラスタ復元パラメータ)
サーバーバージョン Mongo DB サーバーのバージョン。 指定されていない場合は、既定で使用可能な最新バージョンが使用されます。 文字列
シャーディング mongo クラスターのシャーディング プロパティ。 シャーディングプロパティ
ストレージ mongo クラスターのストレージ プロパティ。 ストレージプロパティ

MongoClusterReplicaParameters

名前 Description Value
sourceLocation ソース クラスターの場所 string (必須)
ソースリソースID レプリケーション ソース クラスターの ID。 string (必須)

MongoClusterRestoreParameters (モンゴクラスタ復元パラメータ)

名前 Description Value
ポイントインタイムUTC MONGO クラスターを復元する UTC ポイント イン タイム 文字列
ソースリソースID 復元するソース クラスターを検索するリソース ID 文字列

ShardingProperties

名前 Description Value
シャードカウント クラスターにプロビジョニングするシャードの数。 int

StorageProperties

名前 Description Value
サイズGB 各サーバーに割り当てられているデータ ディスクのサイズ。 int
クラスタ サーバをプロビジョニングするストレージのタイプ。 「プレミアムSSD」
「プレミアムSSDv2」

TrackedResourceTags

名前 Description Value

UserAssignedIdentities

名前 Description Value

UserAssignedIdentity

名前 Description Value