Search code examples
mongodbterraformterraform-provider-gcp

How to create mongo network access using gcp terraform


I have created mongo database deployment (M0 cluster) on gcp using terraform. Even I can able to create user below is my code

resource "mongodbatlas_cluster" "cluster-test" {
  project_id              = "xxxx"
  name                    = "terraform-cluster"
  # Provider Settings "block"
  provider_name = "TENANT"
  provider_region_name = "CENTRAL_US"
  backing_provider_name = "GCP"
  provider_instance_size_name = "M0"
}

resource "mongodbatlas_database_user" "test" {
  username           = "test"
  password           = "abcqvx768"
  project_id         = "xxxx"
  auth_database_name = "admin"

  roles {
     role_name     = "readWriteAnyDatabase"
     database_name = "admin"
  }
}

Now I am trying create network access with ip address (0.0.0.0/0) I am not getting exact resource to create network access.

DB deployment created on GCP. How can I create network access with ip address (0.0.0.0/0) using terraform ?


Solution

  • I assume you would like to whitelist 0.0.0.0/0 interface so that your atlas cluster could access connections from all n/w interfaces.

    If that's the case I think you could use the resource available here

    resource "mongodbatlas_project_ip_access_list" "test" {
      project_id = "xxxx"
      cidr_block = "0.0.0.0/0"
      comment    = "whitelisting 0.0.0.0/0 for all inbound connections"
    }
    

    Just to highlight, 0.0.0.0/0 let's your mongo atlast cluster to listen to all inbound connections which is recommended when you have a firewall in between blocking inbound traffic from internet.