Home

Awesome

terraform-aws-mongodbatlas

Terraform module which creates a MongoDB Atlas cluster on AWS

These types of resources are supported:

Terraform versions

Terraform versions >=0.12 are supported

Usage

module "atlas_cluster" {
  source = ".//terraform-aws-mongodbatlas"

  project_name = "my-project"
  org_id = "5edf67f9b9b528996228111"

  teams = {
    Devops: {
      users: ["example@mail.io", "user@mail.io"]
      role: "GROUP_OWNER"
    },
    DevTeam: {
      users: ["developer@mail.io",]
      role: "GROUP_READ_ONLY"
    }
  }

  white_lists = {
    "example comment": "10.0.0.1/32",
    "second example": "10.10.10.8/32"
  }

  region = "EU_WEST_1"

  cluster_name = "MyCluster"

  instance_type = "M30"
  mongodb_major_ver = 4.2
  cluster_type = "REPLICASET"
  num_shards = 1
  replication_factor = 3
  provider_backup = true
  pit_enabled = false

}

Prerequisites

Manual tasks:

Create Teams:

In case you want to create Teams and associate them with the project, users must be added in advance and making sure they have accepted the invitation. Users who have not accepted an invitation to join the organization cannot be added as team members.

VPC Peering

In case vpc peering is required, AWS provider will be used, the following information is required:

You can add them manually, or through other Terraform resources, and pass it to the module via vpc_peer variable:

  vpc_peer = {
    vpc_peer1 : {
      aws_account_id : "020201234877"
      region : "eu-west-1"
      vpc_id : "vpc-0240c8a47312svc3e"
      route_table_cidr_block : "172.16.0.0/16"
    },
    vpc_peer2 : {
      aws_account_id : "0205432147877"
      region : "eu-central-1"
      vpc_id : "vpc-0f0dd82430bhv0e1a"
      route_table_cidr_block : "172.17.0.0/16"
    }
  }

You can see this example in the examples folder.

Requirements

NameVersion
terraform>= 0.12

Providers

NameVersion
mongodbatlas

Inputs

NameDescriptionTypeDefaultRequired
auto_scaling_disk_gb_enabledIndicating if disk auto-scaling is enabled.booltrueno
cluster_nameThe cluster name.string""yes
cluster_typeThe MongoDB Atlas cluster type - SHARDED/REPLICASET/GEOSHARDED.string""yes
disk_size_gbCapacity,in gigabytes,of the host’s root volume.numberno
instance_typeThe Atlas instance-type name.string""yes
mongodb_major_verThe MongoDB cluster major version.number""no
num_shardsnumber of shards.number""no
org_idThe ID of the Atlas organization you want to create the project within.string""yes
pit_enabledIndicating if the cluster uses Continuous Cloud Backup.boolfalseno
project_nameThe name of the project you want to create.string""yes
provider_backupIndicating if the cluster uses Cloud Backup for backups.booltrueno
provider_disk_iopsThe maximum IOPS the system can perform.numberno
provider_encrypt_ebs_volumeIndicating if the AWS EBS encryption feature encrypts the server’s root volume.boolfalseno
regionThe AWS region-name that the cluster will be deployed on.string""yes
replication_factorThe Number of replica set members, possible values are 3/5/7.numberno
teamsAn object that contains all the groups that should be created in the project.map(any){}no
volume_typeSTANDARD or PROVISIONED for IOPS higher than the default instance IOPS.stringSTANDARDno
vpc_peerAn object that contains all VPC peering requests from the cluster to AWS VPC'smap(any){}no
white_listsAn object that contains all the network white-lists that should be created in the project.map(any){}no

Outputs

NameDescription
cluster_idThe cluster ID.
connection_stringsSet of connection strings that your applications use to connect to this cluster.
container_idhe Network Peering Container ID.
mongo_db_versionVersion of MongoDB the cluster runs, in major-version.minor-version format.
mongo_uriBase connection string for the cluster.
mongo_uri_updatedLists when the connection string was last updated.
mongo_uri_with_optionsconnection string for connecting to the Atlas cluster. Includes the replicaSet, ssl, and authSource query parameters in the connection string with values appropriate for the cluster.
pausedFlag that indicates whether the cluster is paused or not.
srv_addressConnection string for connecting to the Atlas cluster, +srv modifier forces the connection to use TLS/SSL
state_nameCurrent state of the cluster.