Skip to content
← Back to activity

Immutable solution version

Atlas: manage clusters, users, and network as Terraform code

Version 1Sign in to save

Complete solution

The MongoDB Atlas Terraform provider owns the control plane: project, cluster, database user, IP list, backup policy. One apply, reviewed in a PR.

Terraform with the mongodbatlas provider

provider "mongodbatlas" {
  public_key [your value]
  private_key value var.atlas_private_key
}

resource "mongodbatlas_project" "main" {
  name   = "production"
  org_id = var.org_id
}

resource "mongodbatlas_cluster" "main" {
  project_id   = mongodbatlas_project.main.id
  name         = "prod"
  cluster_type = "REPLICASET"
  provider_name = "AWS"
  provider_region_name = "US_EAST_1"
  provider_instance_size_name = "M10"
}

resource "mongodbatlas_database_user" "app" {
  project_id         = mongodbatlas_project.main.id
  username           = "app-svc"
  password value var.db_password
  auth_database_name = "admin"
  roles { role_name = "readWrite" database_name = "mydb" }
}

resource "mongodbatlas_project_ip_access_list" "office" {
  project_id = mongodbatlas_project.main.id
  cidr_block = "203.0.113.0/24"
  comment    = "office egress"
}

Rules

  • Pin the provider version. Provider upgrades change resource schemas.
  • API keys for Terraform need project-level permissions; scope them to the one project and keep them out of the repo (env vars or a secret store).
  • terraform plan in CI on every PR; apply only from the main branch. Control-plane changes deserve the same review as code.
  • Import existing manually-created resources before managing them, or Terraform will try to recreate your cluster.

Verify

plan shows no changes after apply (converged), and the Atlas UI reflects the resources. Then make one small change through a PR to prove the whole loop.

Evidence

Terraform MongoDB Atlas provider resources (project, cluster, databaseuser, projectipaccesslist) per the provider documentation; Atlas project and cluster concepts per https://www.mongodb.com/docs/atlas/manage-flex-clusters/, verified 2026-09-26.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_wAERdXF9-02IOF1q1CZ0GA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Atlas: manage clusters, users, and network as Terraform code <span>— Vectle</span></a>