akshaykarle / terraform-provider-mongodbatlas

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

Error on subsequent terraform plan/apply when no changes #32

Closed mmindenhall closed 5 years ago

mmindenhall commented 5 years ago

I'm creating the following cluster (nearly identical to the example):

# Create a Cluster
resource "mongodbatlas_cluster" "mongo_env_cluster" {
  name = "vendavo-${lower(var.ENV)}"
  group = "${data.mongodbatlas_project.mongo_env_prj.id}"
  mongodb_major_version = "3.6"
  provider_name = "TENANT"
  backing_provider = "AWS"
  region = "${upper(replace(var.REGION, "-", "_"))}"
  size = "M2"
  backup = false
  disk_gb_enabled = false
}

The cluster is created successfully on the first invocation of terraform apply. However, a subsequent execution of terraform plan/apply results in an error, even when the cluster declaration has not changed:

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place
Terraform will perform the following actions:

  ~ mongodbatlas_cluster.mongo_env_cluster
      disk_size_gb: "2" => "0"

...

terraform: apply
Acquiring state lock. This may take a few moments...

...

Error: Error applying plan:

1 error(s) occurred:

* mongodbatlas_cluster.mongo_env_cluster: 1 error(s) occurred:

* mongodbatlas_cluster.mongo_env_cluster: Error reading MongoDB Cluster vendavo-dev: MongoDB Atlas: 400 Cannot update a M0/M2/M5 cluster through the public API.

It seems that the optional "disk_size_db" property is set to 0 when not provided. Then the current state is read from Atlas, which correctly reports "2" as the value, so it wants to change the value from "2" to "0".

mmindenhall commented 5 years ago

Have implemented a fix, but will take a while to rebuild docker container and test in CI/CD pipeline. PR to come.

akshaykarle commented 5 years ago

Not sure this is limited to just the shared clusters. I've seen this happen with any sized clusters. Will look at your PR, thank you!

akshaykarle commented 5 years ago

Closed by #39