Microsoft。DocumentDB mongoClusters

Bicep リソース定義

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

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

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

使用例

Azure 検証済みモジュール

次の Azure 検証済みモジュール を使用して、このリソースの種類をデプロイできます。

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

リソースの形式

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

resource symbolicname 'Microsoft.DocumentDB/mongoClusters@2026-10-15-preview' = {
  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'
    serviceManagedFailover: {
      mode: 'string'
    }
    sharding: {
      shardCount: int
    }
    storage: {
      sizeGb: int
      type: 'string'
    }
  }
  tags: {
    {customized property}: 'string'
  }
}

プロパティ値

Microsoft.DocumentDB/mongoClusters

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

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

管理者プロパティ

名前 形容 価値
パスワード 管理者パスワード。 糸

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

AuthConfigプロパティ

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

バックアッププロパティ

名前 形容 価値

コンピュートプロパティ

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

CustomerManagedKeyEncryptionProperties

名前 形容 価値
keyEncryptionKeyIdentity キー暗号化キーへのアクセスに使用される ID。 KeyEncryptionKeyIdentity
keyEncryptionKeyUrl 暗号化に使用されるキー コンテナー キーの URI。 文字列

DataApiプロパティ

名前 形容 価値
モード クラスターに対して Mongo Data API が有効になっているかどうかを示すモード。 「無効」
「有効」

EncryptionProperties

名前 形容 価値
customerManagedKeyEncryption カスタマー マネージド キー暗号化設定。 CustomerManagedKeyEncryptionProperties

HighAvailabilityProperties (高可用性プロパティ)

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

KeyEncryptionKeyIdentity

名前 形容 価値
アイデンティティタイプ ID の種類。 'UserAssignedIdentity' のみがサポートされています。 'UserAssignedIdentity'
userAssignedIdentityResourceId ユーザーが割り当てたアイデンティティ・リソースID。 文字列

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

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

MongoClusterプロパティ

名前 形容 価値
管理者 DocumentDBクラスターのローカル管理者プロパティです。 AdministratorProperties
authConfigの クラスタの認証設定。 AuthConfigProperties
バックアップ DocumentDBクラスターのバックアッププロパティ。 BackupProperties
コンピューティング DocumentDBクラスターの計算プロパティ。 ComputeProperties
クリエイトモード DocumentDBクラスタを作成するモード。 デフォルト
「ジオレプリカ」
「PointInTimeRestore」
「レプリカ」
データAPI DocumentDBクラスターのData APIプロパティ。 DataApiProperties
暗号化 クラスターの暗号化構成。 構成されている ID によって異なります。 EncryptionProperties
高い可用性 DocumentDBクラスターの高可用性特性。 高可用性プロパティ
ネットワークバイパスモード クラスターのネットワークバイパスモードです。 「AzureCosmosDB」に設定すると、Azure Cosmos DBサービスがネットワーク制限を回避できます。 『AzureCosmosDB』
「なし」
プレビュー機能 プライベート エンドポイント接続の一覧。 次のいずれかを含む文字列配列:
「ジオレプリカ」
publicNetworkAccess (パブリックネットワークアクセス) このDocumentDBクラスタでパブリックエンドポイントアクセスが許可されているかどうか。 「無効」
「有効」
replicaParameters (レプリカパラメータ) レプリカのDocumentDBクラスタを作成するためのパラメータ。 MongoClusterReplicaParameters
restoreParameters (リストアパラメータ) ポイントインタイム復元DocumentDBクラスタを作成するパラメータ。 MongoClusterRestoreParameters
サーバーバージョン Mongo DB サーバーのバージョン。 指定されていない場合は、既定で使用可能な最新バージョンが使用されます。 文字列
serviceManagedFailover クラスタのサービス管理型フェイルオーバー構成。 ServiceManagedFailoverProperties
シャーディング DocumentDBクラスターのシャーディングプロパティ。 ShardingProperties
ストレージ DocumentDBクラスタのストレージプロパティ。 StorageProperties

MongoClusterReplicaParameters (英語)

名前 形容 価値
ソースロケーション ソース クラスターの場所 string (必須)
ソースリソースID レプリケーション ソース クラスターの ID。 string (必須)

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

名前 形容 価値
ポイントインタイムUTC UTCのDocumentDBクラスタを復元するための時点 文字列
ソースリソースID 復元するソース クラスターを検索するリソース ID 文字列

ServiceManagedFailoverProperties

名前 形容 価値
モード クラスタでサービス管理フェイルオーバーが有効になっているかどうか。 「無効」
「有効」

シャーディングプロパティ

名前 形容 価値
シャードカウント クラスターにプロビジョニングするシャードの数。 整数 (int)

ストレージプロパティ

名前 形容 価値
サイズGB 各サーバーに割り当てられているデータ ディスクのサイズ。 整数 (int)
型 クラスタ サーバをプロビジョニングするストレージのタイプ。 クラスタ作成時に省略した場合、デフォルトで「PremiumSSDv2」となります。 更新時にこのプロパティを省略しても、ストレージタイプは変更されません。 「プレミアムSSD」
「プレミアムSSDv2」

追跡リソースタグ

名前 形容 価値

UserAssignedIdentities

名前 形容 価値

ユーザー割り当て識別子

名前 形容 価値

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

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

使用例

リソースの形式

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

{
  "type": "Microsoft.DocumentDB/mongoClusters",
  "apiVersion": "2026-10-15-preview",
  "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",
    "serviceManagedFailover": {
      "mode": "string"
    },
    "sharding": {
      "shardCount": "int"
    },
    "storage": {
      "sizeGb": "int",
      "type": "string"
    }
  },
  "tags": {
    "{customized property}": "string"
  }
}

プロパティ値

Microsoft.DocumentDB/mongoClusters

名前 形容 価値
apiVersion (英語) API のバージョン 『2026年10月15日プレビュー』
ID このリソースに割り当てられているマネージド サービス ID。 ManagedServiceIdentity
位置 リソースが存在する地理的な場所 string (必須)
名前 リソース名 糸

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

管理者プロパティ

名前 形容 価値
パスワード 管理者パスワード。 糸

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

AuthConfigプロパティ

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

バックアッププロパティ

名前 形容 価値

コンピュートプロパティ

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

CustomerManagedKeyEncryptionProperties

名前 形容 価値
keyEncryptionKeyIdentity キー暗号化キーへのアクセスに使用される ID。 KeyEncryptionKeyIdentity
keyEncryptionKeyUrl 暗号化に使用されるキー コンテナー キーの URI。 文字列

DataApiプロパティ

名前 形容 価値
モード クラスターに対して Mongo Data API が有効になっているかどうかを示すモード。 「無効」
「有効」

EncryptionProperties

名前 形容 価値
customerManagedKeyEncryption カスタマー マネージド キー暗号化設定。 CustomerManagedKeyEncryptionProperties

HighAvailabilityProperties (高可用性プロパティ)

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

KeyEncryptionKeyIdentity

名前 形容 価値
アイデンティティタイプ ID の種類。 'UserAssignedIdentity' のみがサポートされています。 'UserAssignedIdentity'
userAssignedIdentityResourceId ユーザーが割り当てたアイデンティティ・リソースID。 文字列

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

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

MongoClusterプロパティ

名前 形容 価値
管理者 DocumentDBクラスターのローカル管理者プロパティです。 AdministratorProperties
authConfigの クラスタの認証設定。 AuthConfigProperties
バックアップ DocumentDBクラスターのバックアッププロパティ。 BackupProperties
コンピューティング DocumentDBクラスターの計算プロパティ。 ComputeProperties
クリエイトモード DocumentDBクラスタを作成するモード。 デフォルト
「ジオレプリカ」
「PointInTimeRestore」
「レプリカ」
データAPI DocumentDBクラスターのData APIプロパティ。 DataApiProperties
暗号化 クラスターの暗号化構成。 構成されている ID によって異なります。 EncryptionProperties
高い可用性 DocumentDBクラスターの高可用性特性。 高可用性プロパティ
ネットワークバイパスモード クラスターのネットワークバイパスモードです。 「AzureCosmosDB」に設定すると、Azure Cosmos DBサービスがネットワーク制限を回避できます。 『AzureCosmosDB』
「なし」
プレビュー機能 プライベート エンドポイント接続の一覧。 次のいずれかを含む文字列配列:
「ジオレプリカ」
publicNetworkAccess (パブリックネットワークアクセス) このDocumentDBクラスタでパブリックエンドポイントアクセスが許可されているかどうか。 「無効」
「有効」
replicaParameters (レプリカパラメータ) レプリカのDocumentDBクラスタを作成するためのパラメータ。 MongoClusterReplicaParameters
restoreParameters (リストアパラメータ) ポイントインタイム復元DocumentDBクラスタを作成するパラメータ。 MongoClusterRestoreParameters
サーバーバージョン Mongo DB サーバーのバージョン。 指定されていない場合は、既定で使用可能な最新バージョンが使用されます。 文字列
serviceManagedFailover クラスタのサービス管理型フェイルオーバー構成。 ServiceManagedFailoverProperties
シャーディング DocumentDBクラスターのシャーディングプロパティ。 ShardingProperties
ストレージ DocumentDBクラスタのストレージプロパティ。 StorageProperties

MongoClusterReplicaParameters (英語)

名前 形容 価値
ソースロケーション ソース クラスターの場所 string (必須)
ソースリソースID レプリケーション ソース クラスターの ID。 string (必須)

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

名前 形容 価値
ポイントインタイムUTC UTCのDocumentDBクラスタを復元するための時点 文字列
ソースリソースID 復元するソース クラスターを検索するリソース ID 文字列

ServiceManagedFailoverProperties

名前 形容 価値
モード クラスタでサービス管理フェイルオーバーが有効になっているかどうか。 「無効」
「有効」

シャーディングプロパティ

名前 形容 価値
シャードカウント クラスターにプロビジョニングするシャードの数。 整数 (int)

ストレージプロパティ

名前 形容 価値
サイズGB 各サーバーに割り当てられているデータ ディスクのサイズ。 整数 (int)
型 クラスタ サーバをプロビジョニングするストレージのタイプ。 クラスタ作成時に省略した場合、デフォルトで「PremiumSSDv2」となります。 更新時にこのプロパティを省略しても、ストレージタイプは変更されません。 「プレミアムSSD」
「プレミアムSSDv2」

追跡リソースタグ

名前 形容 価値

UserAssignedIdentities

名前 形容 価値

ユーザー割り当て識別子

名前 形容 価値

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 検証済みモジュール を使用して、このリソースの種類をデプロイできます。

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

リソースの形式

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

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.DocumentDB/mongoClusters@2026-10-15-preview"
  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"
      serviceManagedFailover = {
        mode = "string"
      }
      sharding = {
        shardCount = int
      }
      storage = {
        sizeGb = int
        type = "string"
      }
    }
  }
}

プロパティ値

Microsoft.DocumentDB/mongoClusters

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

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

管理者プロパティ

名前 形容 価値
パスワード 管理者パスワード。 糸

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

AuthConfigプロパティ

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

バックアッププロパティ

名前 形容 価値

コンピュートプロパティ

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

CustomerManagedKeyEncryptionProperties

名前 形容 価値
keyEncryptionKeyIdentity キー暗号化キーへのアクセスに使用される ID。 KeyEncryptionKeyIdentity
keyEncryptionKeyUrl 暗号化に使用されるキー コンテナー キーの URI。 文字列

DataApiプロパティ

名前 形容 価値
モード クラスターに対して Mongo Data API が有効になっているかどうかを示すモード。 「無効」
「有効」

EncryptionProperties

名前 形容 価値
customerManagedKeyEncryption カスタマー マネージド キー暗号化設定。 CustomerManagedKeyEncryptionProperties

HighAvailabilityProperties (高可用性プロパティ)

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

KeyEncryptionKeyIdentity

名前 形容 価値
アイデンティティタイプ ID の種類。 'UserAssignedIdentity' のみがサポートされています。 'UserAssignedIdentity'
userAssignedIdentityResourceId ユーザーが割り当てたアイデンティティ・リソースID。 文字列

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

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

MongoClusterプロパティ

名前 形容 価値
管理者 DocumentDBクラスターのローカル管理者プロパティです。 AdministratorProperties
authConfigの クラスタの認証設定。 AuthConfigProperties
バックアップ DocumentDBクラスターのバックアッププロパティ。 BackupProperties
コンピューティング DocumentDBクラスターの計算プロパティ。 ComputeProperties
クリエイトモード DocumentDBクラスタを作成するモード。 デフォルト
「ジオレプリカ」
「PointInTimeRestore」
「レプリカ」
データAPI DocumentDBクラスターのData APIプロパティ。 DataApiProperties
暗号化 クラスターの暗号化構成。 構成されている ID によって異なります。 EncryptionProperties
高い可用性 DocumentDBクラスターの高可用性特性。 高可用性プロパティ
ネットワークバイパスモード クラスターのネットワークバイパスモードです。 「AzureCosmosDB」に設定すると、Azure Cosmos DBサービスがネットワーク制限を回避できます。 『AzureCosmosDB』
「なし」
プレビュー機能 プライベート エンドポイント接続の一覧。 次のいずれかを含む文字列配列:
「ジオレプリカ」
publicNetworkAccess (パブリックネットワークアクセス) このDocumentDBクラスタでパブリックエンドポイントアクセスが許可されているかどうか。 「無効」
「有効」
replicaParameters (レプリカパラメータ) レプリカのDocumentDBクラスタを作成するためのパラメータ。 MongoClusterReplicaParameters
restoreParameters (リストアパラメータ) ポイントインタイム復元DocumentDBクラスタを作成するパラメータ。 MongoClusterRestoreParameters
サーバーバージョン Mongo DB サーバーのバージョン。 指定されていない場合は、既定で使用可能な最新バージョンが使用されます。 文字列
serviceManagedFailover クラスタのサービス管理型フェイルオーバー構成。 ServiceManagedFailoverProperties
シャーディング DocumentDBクラスターのシャーディングプロパティ。 ShardingProperties
ストレージ DocumentDBクラスタのストレージプロパティ。 StorageProperties

MongoClusterReplicaParameters (英語)

名前 形容 価値
ソースロケーション ソース クラスターの場所 string (必須)
ソースリソースID レプリケーション ソース クラスターの ID。 string (必須)

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

名前 形容 価値
ポイントインタイムUTC UTCのDocumentDBクラスタを復元するための時点 文字列
ソースリソースID 復元するソース クラスターを検索するリソース ID 文字列

ServiceManagedFailoverProperties

名前 形容 価値
モード クラスタでサービス管理フェイルオーバーが有効になっているかどうか。 「無効」
「有効」

シャーディングプロパティ

名前 形容 価値
シャードカウント クラスターにプロビジョニングするシャードの数。 整数 (int)

ストレージプロパティ

名前 形容 価値
サイズGB 各サーバーに割り当てられているデータ ディスクのサイズ。 整数 (int)
型 クラスタ サーバをプロビジョニングするストレージのタイプ。 クラスタ作成時に省略した場合、デフォルトで「PremiumSSDv2」となります。 更新時にこのプロパティを省略しても、ストレージタイプは変更されません。 「プレミアムSSD」
「プレミアムSSDv2」

追跡リソースタグ

名前 形容 価値

UserAssignedIdentities

名前 形容 価値

ユーザー割り当て識別子

名前 形容 価値