akshaykarle / terraform-provider-mongodbatlas

Terraform provider for MongoDB Atlas
Mozilla Public License 2.0
122 stars 54 forks source link

Race condition between container and cluster #89

Closed aarongorka closed 5 years ago

aarongorka commented 5 years ago

It looks like there is a race condition when creating a container and a cluster, as the cluster will create a "default" container which prevents you from creating your own container.

$ terraform apply
# group, whitelist, etc. created...
mongodbatlas_cluster.main: Creating...
  backup:                 "" => "false"
  disk_gb_enabled:        "" => "true"
  disk_size_gb:           "" => "10"
  group:                  "" => "xxxxxxxxxxxxxxxxxxxxxxxx"
  identifier:             "" => "<computed>"
  mongo_uri:              "" => "<computed>"
  mongo_uri_updated:      "" => "<computed>"
  mongo_uri_with_options: "" => "<computed>"
  mongodb_major_version:  "" => "4.0"
  mongodb_version:        "" => "<computed>"
  name:                   "" => "mymongo"
  num_shards:             "" => "1"
  paused:                 "" => "false"
  provider_backup:        "" => "false"
  provider_name:          "" => "AWS"
  region:                 "" => "AP_SOUTHEAST_2"
  replication_factor:     "" => "3"
  replication_spec.#:     "" => "<computed>"
  size:                   "" => "M10"
  state: "" => "<computed>"
# ...
mongodbatlas_cluster.main: Still creating... (6m20s elapsed)
mongodbatlas_cluster.main: Creation complete after 6m26s (ID: xxxxxxxxxxxxxxxxx)
mongodbatlas_container.main: Creating...
  atlas_cidr_block: "" => "172.16.16.0/21"
  group:            "" => "xxxxxxxxxxxxxxxxxxx"
  identifier:       "" => "<computed>"
  provider_name:    "" => "AWS"
  provisioned:      "" => "<computed>"
  region:           "" => "AP_SOUTHEAST_2"
  vpc_id:           "" => "<computed>"

Error: Error applying plan:

1 error(s) occurred:

* mongodbatlas_container.main: 1 error(s) occurred:

* mongodbatlas_container.main: Error creating MongoDB Container: MongoDB Atlas: 409 A container already exists for group xxxxxxxxxxxxxxx.

I am using the "basic" example along with the "peering" example in the same Terraform stack as well as some AWS resources to accept + configure the peering.

Adding a depends_on = ["mongodbatlas_container.main"] to the cluster fixes the issue.