azurerm_cosmosdb_account

Manages a CosmosDB (formally DocumentDB) Account.

Example Usage

resource "azurerm_resource_group" "example" {
  name     = "example-resource-group"
  location = "West Europe"
}

resource "random_integer" "ri" {
  min = 10000
  max = 99999
}

resource "azurerm_cosmosdb_account" "db" {
  name                = "tfex-cosmos-db-${random_integer.ri.result}"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  offer_type          = "Standard"
  kind                = "MongoDB"

  enable_automatic_failover = true

  capabilities {
    name = "EnableAggregationPipeline"
  }

  capabilities {
    name = "mongoEnableDocLevelTTL"
  }

  capabilities {
    name = "MongoDBv3.4"
  }

  capabilities {
    name = "EnableMongo"
  }

  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }

  geo_location {
    location          = "eastus"
    failover_priority = 1
  }

  geo_location {
    location          = "westus"
    failover_priority = 0
  }
}

User Assigned Identity Example Usage

resource "azurerm_user_assigned_identity" "example" {
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  name                = "example-resource"
}

resource "azurerm_cosmosdb_account" "example" {
  name                  = "example-resource"
  location              = azurerm_resource_group.example.location
  resource_group_name   = azurerm_resource_group.example.name
  default_identity_type = join("=", ["UserAssignedIdentity", azurerm_user_assigned_identity.example.id])
  offer_type            = "Standard"
  kind                  = "MongoDB"

  capabilities {
    name = "EnableMongo"
  }

  consistency_policy {
    consistency_level = "Strong"
  }

  geo_location {
    location          = "westus"
    failover_priority = 0
  }

  identity {
    type         = "UserAssigned"
    identity_ids = [azurerm_user_assigned_identity.example.id]
  }
}

Argument Reference

The following arguments are supported:


The consistency_policy block Configures the database consistency and supports the following:


The geo_location block Configures the geographic locations the data is replicated to and supports the following:


A capabilities block Configures the capabilities to be enabled for this Cosmos DB account:


The virtual_network_rule block Configures the virtual network subnets allowed to access this Cosmos DB account and supports the following:


An analytical_storage block supports the following:


A capacity block supports the following:


A backup block supports the following:


A cors_rule block supports the following:


An identity block supports the following:


A restore block supports the following:


A database block supports the following:


A gremlin_database block supports the following:

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:


An identity block exports the following:

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

Import

CosmosDB Accounts can be imported using the resource id, e.g.

terraform import azurerm_cosmosdb_account.account1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DocumentDB/databaseAccounts/account1