Did you know you can define MongoDB Atlas infrastructure in Terraform?


Did you know you can define MongoDB Atlas infrastructure in Terraform?

Recently I added Payload CMS to my stack for Schematical and Cloud War Games so my team can quickly add new content with mixed results… Payload is far from perfect.

Payload CMS has several options for data sources and Dynamo DB isn’t one of them but Mongo is so I dusted off my old MongoDB Atlas account and pointed Payload at it.

Me, being somewhat obsessive about maintaining my IoC was blown away when I found they had a section in the Atlas dashboard to define your cluster as IoC.

I have started to play around with their starter example but have not had time to completely port my setup over.

It seems simple enough to define a cluster:

resource "mongodbatlas_advanced_cluster" "cluster" {
  project_id     = mongodbatlas_project.project.id
  name           = var.cluster_name
  cluster_type   = "REPLICASET"
  backup_enabled = true

  replication_specs {
    region_configs {
      priority      = 7
      provider_name = var.cloud_provider
      region_name   = var.region
      electable_specs {
        instance_size = "M10"
        node_count    = 3
      }
    }
  }
}

output "connection_strings" {
  value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].standard_srv
}

Authentication just uses a simple private public key:

export MONGODB_ATLAS_PUBLIC_KEY="<ATLAS_PUBLIC_KEY>"
export MONGODB_ATLAS_PRIVATE_KEY="<ATLAS_PRIVATE_KEY>"

So if you have IoC OCD like I do and use MongoDB it's good to have this on your radar.

Question For You:

What other interesting Terraform providers outside of the big ones have you used?

PS: If you have questions you want answered, hop on this Friday’s Live Q&A.

Can’t make it feel free to submit your question ahead of time and we will send you a video of us answering it.