akshaykarle / terraform-provider-mongodbatlas

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

Upgrading a cluster destroys and recreates the resource #44

Closed dbamohsin closed 5 years ago

dbamohsin commented 5 years ago

Hi,

Thanks for all your efforts on this provider so far!

Im not sure if i have missed something but i'm finding that when attempting to upgrade the mongoDBMajorVersion of a cluster resource, terraform destroys the existing resource and then creates a new resource on the new version.

terraform:

resource "mongodbatlas_cluster" "sandbox" {
  name = "sandbox"
  group = "${var.projectid}"
  mongodb_major_version = "3.6"
  provider_name = "GCP"
  # backing_provider = "GCP"
  region = "EUROPE_WEST_4"
  size = "M10"
  replication_factor = 3
  disk_size_gb = 5
  num_shards = 1
  paused = false
  backup = false
  disk_gb_enabled = false

  # depends_on = ["mongodbatlas_project.platform_project"]

  timeouts {
    create = "20m"
    delete = "40m"
    update = "24h"
  }
}

This presents the following plan:

-/+ mongodbatlas_cluster.sandbox (new resource required)
      id:                     "xxxx" => <computed> (forces new resource)
      backup:                 "false" => "false"
      disk_gb_enabled:        "false" => "false"
      disk_size_gb:           "5" => "5"
      group:                  "xxxx" => "xxxx"
      identifier:             "xxxx" => <computed>
      mongo_uri:              "mongodb://myreplicaset0.gcp.mongodb.net:27017,myreplicaset1.gcp.mongodb.net:27017,myreplicaset2.gcp.mongodb.net:27017" => <computed>
      mongo_uri_updated:      "2018-09-18T14:46:00Z" => <computed>
      mongo_uri_with_options: "mongodb://myreplicaset0.gcp.mongodb.net:27017,myreplicaset1.gcp.mongodb.net:27017,myreplicaset2.gcp.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=sandbox-shard-0" => <computed>
      mongodb_major_version:  "3.4" => "3.6" (forces new resource)
      mongodb_version:        "3.4.16" => <computed>
      name:                   "sandbox" => "sandbox"
      num_shards:             "1" => "1"
      paused:                 "false" => "false"
      provider_name:          "GCP" => "GCP"
      region:                 "EUROPE_WEST_4" => "EUROPE_WEST_4"
      replication_factor:     "3" => "3"
      replication_spec.#:     "1" => <computed>
      size:                   "M10" => "M10"
      state:                  "IDLE" => <computed>

Plan: 1 to add, 0 to change, 1 to destroy.

Is this expected behaviour? The API does look like it allows cluster modification of mongoDBMajorVersion - https://docs.atlas.mongodb.com/reference/api/clusters-modify-one/#

Thanks

Mos

dbamohsin commented 5 years ago

Just some additional info on this. i've just tested the Mongo API moving from 3.4 to 3.6 and this works fine.

curl -i -u "user:key" --digest -H "Content-Type: application/json" -X PATCH "https://cloud.mongodb.com/api/atlas/v1.0/groups/groupid/clusters/myreplicaset" --data '
{
  "mongoDBMajorVersion" : 3.6
}'

the above upgrades the cluster successfully.

akshaykarle commented 5 years ago

Thanks for filing that issue. Should be simple to fix this. Will do it soon :)