Skip to content

kevin-fitlg/terraform-azurerm-cosmos-db

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure CosmosDB

Changelog Notice Apache V2 License TF Registry

This terraform module creates an Azure CosmosDB. Diagnostic settings are also deployed.

Global versioning rule for Claranet Azure modules

Module version Terraform version AzureRM version
>= 7.x.x 1.3.x >= 3.0
>= 6.x.x 1.x >= 3.0
>= 5.x.x 0.15.x >= 2.0
>= 4.x.x 0.13.x / 0.14.x >= 2.0
>= 3.x.x 0.12.x >= 2.0
>= 2.x.x 0.12.x < 2.0
< 2.x.x 0.11.x < 2.0

Contributing

If you want to contribute to this repository, feel free to use our pre-commit git hook configuration which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices.

More details are available in the CONTRIBUTING.md file.

Usage

This module is optimized to work with the Claranet terraform-wrapper tool which set some terraform variables in the environment needed by this module. More details about variables set by the terraform-wrapper available in the documentation.

module "azure_region" {
  source  = "claranet/regions/azurerm"
  version = "x.x.x"

  azure_region = var.azure_region
}

module "rg" {
  source  = "claranet/rg/azurerm"
  version = "x.x.x"

  location    = module.azure_region.location
  client_name = var.client_name
  environment = var.environment
  stack       = var.stack
}

module "logs" {
  source  = "claranet/run-common/azurerm//modules/logs"
  version = "x.x.x"

  client_name         = var.client_name
  environment         = var.environment
  stack               = var.stack
  location            = module.azure_region.location
  location_short      = module.azure_region.location_short
  resource_group_name = module.rg.resource_group_name
}

module "cosmosdb" {
  source  = "claranet/cosmos-db/azurerm"
  version = "x.x.x"

  environment    = var.environment
  location       = module.azure_region.location
  location_short = module.azure_region.location_short
  client_name    = var.client_name
  stack          = var.stack

  resource_group_name = module.rg.resource_group_name

  logs_destinations_ids = [module.logs.log_analytics_workspace_id]

  backup = {
    type                = "Periodic"
    interval_in_minutes = 60 * 3 # 3 hours
    retention_in_hours  = 24
  }

  extra_tags = {
    managed_by            = "Terraform"
    foo                   = "bar"
    monitor_autoscale_max = 2
  }
}

Providers

Name Version
azurecaf ~> 1.2, >= 1.2.22
azurerm ~> 3.22

Modules

Name Source Version
diagnostics claranet/diagnostic-settings/azurerm 6.2.0

Resources

Name Type
azurerm_cosmosdb_account.db resource
azurecaf_name.cosmosdb data source

Inputs

Name Description Type Default Required
allowed_cidrs CosmosDB Firewall Support: This value specifies the set of IP addresses or IP address ranges in CIDR form to be included as the allowed list of client IP's for a given database account. list(string) [] no
analytical_storage_enabled Enable Analytical Storage option for this Cosmos DB account. Defaults to false. Changing this forces a new resource to be created. bool false no
analytical_storage_type The schema type of the Analytical Storage for this Cosmos DB account. Possible values are FullFidelity and WellDefined. string null no
backup Backup block with type (Continuous / Periodic), interval_in_minutes and retention_in_hours keys
object({
type = string
interval_in_minutes = number
retention_in_hours = number
})
{
"interval_in_minutes": 180,
"retention_in_hours": 168,
"type": "Periodic"
}
no
capabilities Configures the capabilities to enable for this Cosmos DB account:
Possible values are
AllowSelfServeUpgradeToMongo36, DisableRateLimitingResponses,
EnableAggregationPipeline, EnableCassandra, EnableGremlin,EnableMongo, EnableTable, EnableServerless,
MongoDBv3.4 and mongoEnableDocLevelTTL.
list(string) [] no
client_name Client name string n/a yes
consistency_policy_level Consistency policy level. Allowed values are BoundedStaleness, Eventual, Session, Strong or ConsistentPrefix string "BoundedStaleness" no
consistency_policy_max_interval_in_seconds When used with the Bounded Staleness consistency level, this value represents the time amount of staleness (in seconds) tolerated. Accepted range for this value is 5 - 86400 (1 day). Defaults to 5. Required when consistency_level is set to BoundedStaleness. number 10 no
consistency_policy_max_staleness_prefix When used with the Bounded Staleness consistency level, this value represents the number of stale requests tolerated. Accepted range for this value is 10 – 2147483647. Defaults to 100. Required when consistency_level is set to BoundedStaleness. number 200 no
custom_diagnostic_settings_name Custom name of the diagnostics settings, name will be 'default' if not set. string "default" no
custom_server_name Custom Server Name identifier string "" no
default_tags_enabled Option to enable or disable default tags. bool true no
environment Environment name string n/a yes
extra_tags Map of custom tags. map(string) {} no
failover_locations The name of the Azure region to host replicated data and their priority. map(map(string)) null no
identity_type CosmosDB identity type. Possible values for type are: null and SystemAssigned. string "SystemAssigned" no
is_virtual_network_filter_enabled Enables virtual network filtering for this Cosmos DB account bool false no
kind Specifies the Kind of CosmosDB to create - possible values are GlobalDocumentDB and MongoDB. string "GlobalDocumentDB" no
location Azure location for CosmosDB. string n/a yes
location_short Short string for Azure location. string n/a yes
logs_categories Log categories to send to destinations. list(string) null no
logs_destinations_ids List of destination resources IDs for logs diagnostic destination.
Can be Storage Account, Log Analytics Workspace and Event Hub. No more than one of each can be set.
If you want to specify an Azure EventHub to send logs and metrics to, you need to provide a formated string with both the EventHub Namespace authorization send ID and the EventHub name (name of the queue to use in the Namespace) separated by the `
` character. list(string) n/a
logs_metrics_categories Metrics categories to send to destinations. list(string) null no
logs_retention_days Number of days to keep logs on storage account. number 30 no
mongo_server_version The Server Version of a MongoDB account. See possible values https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_account#mongo_server_version string "4.2" no
name_prefix Optional prefix for the generated name string "" no
name_suffix Optional suffix for the generated name string "" no
network_acl_bypass_for_azure_services If azure services can bypass ACLs. bool false no
network_acl_bypass_ids The list of resource Ids for Network Acl Bypass for this Cosmos DB account. list(string) null no
offer_type Specifies the Offer Type to use for this CosmosDB Account - currently this can only be set to Standard. string "Standard" no
public_network_access_enabled Whether or not public network access is allowed for this CosmosDB account. bool true no
resource_group_name Resource Group the resources will belong to string n/a yes
stack Stack name string n/a yes
use_caf_naming Use the Azure CAF naming provider to generate default resource name. custom_server_name override this if set. Legacy default name is used if this is set to false. bool true no
virtual_network_rule Specifies a virtual_network_rules resource used to define which subnets are allowed to access this CosmosDB account
list(object({
id = string,
ignore_missing_vnet_service_endpoint = bool
}))
null no
zone_redundancy_enabled True to enabled zone redundancy on default primary location bool true no

Outputs

Name Description
cosmosdb_connection_strings A list of connection strings available for this CosmosDB account.
cosmosdb_endpoint The endpoint used to connect to the CosmosDB account.
cosmosdb_id The CosmosDB Account ID.
cosmosdb_name The CosmosDB Account Name.
cosmosdb_primary_master_key The Primary master key for the CosmosDB Account.
cosmosdb_primary_readonly_master_key The Primary read-only master Key for the CosmosDB Account.
cosmosdb_read_endpoints A list of read endpoints available for this CosmosDB account.
cosmosdb_secondary_master_key The Secondary master key for the CosmosDB Account.
cosmosdb_secondary_readonly_master_key The Secondary read-only master key for the CosmosDB Account.
cosmosdb_write_endpoints A list of write endpoints available for this CosmosDB account.
identity Identity block with principal ID
resource_group_name Resource group name

Related documentation

About

Terraform module for CosmosDB account and databases

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 100.0%