mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
241 stars 167 forks source link

Issues upgrading cluster to an AWS NVME tier. #132

Closed mattt416 closed 4 years ago

mattt416 commented 4 years ago

Hey folks,

My config originally contained the following resource:

resource "mongodbatlas_cluster" "terraform_cluster" {
  project_id = <PROJECT_ID>
  name       = "terraform-cluster"

  provider_name                = "AWS"
  provider_region_name         = "US_EAST_1"
  provider_backup_enabled      = true
  provider_instance_size_name  = "M10"
  provider_volume_type         = "STANDARD"
  provider_disk_iops           = 100
  disk_size_gb                 = 10
  mongo_db_major_version       = "4.2"
  auto_scaling_disk_gb_enabled = false
}

I then attempted to scale it to the M40_NVME tier:

resource "mongodbatlas_cluster" "terraform_cluster" {
  project_id = <PROJECT_ID>
  name       = "terraform-cluster"

  provider_name                = "AWS"
  provider_region_name         = "US_EAST_1"
  provider_backup_enabled      = true
  provider_instance_size_name  = "M40_NVME"
  provider_disk_iops          = 3000
  provider_volume_type         = "PROVISIONED"
  mongo_db_major_version       = "4.2"
  auto_scaling_disk_gb_enabled = false
}

Re-applying my config results in the API returning the following error (despite my cluster already having Cloud Provider Snapshots enabled (provider_backup_enabled set to true):

Error: error updating MongoDB Cluster (terraform-cluster): PATCH https://cloud.mongodb.com/api/atlas/v1.0/groups/redacted/clusters/terraform-cluster: 400 (request "Bad Request") Cloud Provider Snapshot backups must be enabled for deployments with NVMe storage.

The only way I could get the upgrade to go through via the Terraform provider was to first set provider_backup_enabled to false and re-apply, and then flip everything to the M40_NVME tier with provider_backup_enabled set back to true.

Testing this through the API directly, I do have explicitly set providerBackupEnabled in my PATCH request:

curl --user "user:pass" --digest \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --include \
  --request PATCH "https://cloud.mongodb.com/api/atlas/v1.0/groups/redacted/clusters/terraform-cluster" \
  --data '
    {
      "providerBackupEnabled" : true,
      "providerSettings" : {
        "providerName" : "AWS",
        "instanceSizeName" : "M40_NVME"
      }
    }'

... and the issue is likely that Terraform isn't explicitly passing providerBackupEnabled when performing the tier update since providerBackupEnabled has already been set.

Any thoughts on how we can get around this particular issue?

Thanks, Matt

themantissa commented 4 years ago

Summary of the bug - ensure new parameter is passed when upgrading an existing cluster, specifically provider_backup_enabled (should be false by default)

mattt416 commented 4 years ago

For anyone stumbling across this bug, note that disabling backups will result in your existing snapshots getting terminated, so obviously only do that as a last resort.

themantissa commented 4 years ago

@mattt416 - if you have a chance ensure https://github.com/terraform-providers/terraform-provider-mongodbatlas/pull/236 fixes your issue. Thanks!