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
245 stars 172 forks source link

400 (request "INVALID_ATTRIBUTE") Invalid attribute providerBackupEnabled specified. #1245

Closed codesmithtech closed 1 year ago

codesmithtech commented 1 year ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

v1.3.7

Terraform Configuration File

resource "mongodbatlas_cluster" "managed" {
  project_id                                      = REMOVED_FOR_PRIVACY
  provider_name                                   = local.provider_name
  backing_provider_name                           = "AWS"
  name                                            = "${var.environment}-${var.project}-managed"
  provider_instance_size_name                     = var.initial_provider_instance_size_name
  disk_size_gb                                    = var.initial_disk_size
  auto_scaling_disk_gb_enabled                    = true
  auto_scaling_compute_enabled                    = true
  auto_scaling_compute_scale_down_enabled         = true
  provider_auto_scaling_compute_min_instance_size = var.initial_provider_instance_size_name
  provider_auto_scaling_compute_max_instance_size = local.max_instance_size
  cloud_backup                                    = true
  pit_enabled                                     = true
  cluster_type                                    = "REPLICASET"
  mongo_db_major_version                          = "6.0"
  provider_region_name                            = "EU_WEST_1"
  termination_protection_enabled                  = true
  provider_backup_enabled                         = null

  lifecycle {
    ignore_changes = [
      provider_instance_size_name,
      disk_size_gb
    ]
  }
}

terraform {
  backend "s3" {}
  required_version = ">= 1.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.9"
    }

    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "1.10.0"
    }
  }
}

provider "mongodbatlas" {
  public_key  = var.mongo_db_public_key
  private_key = var.mongo_db_private_key
}

Steps to Reproduce

Expected Behavior

Cluster should have provisioned in Mongo Atlas

Actual Behavior

Error reported by terraform during cluster creation.

Apply output was:

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # mongodbatlas_cluster.managed will be created
  + resource "mongodbatlas_cluster" "managed" {
      + auto_scaling_compute_enabled                    = true
      + auto_scaling_compute_scale_down_enabled         = true
      + auto_scaling_disk_gb_enabled                    = true
      + backing_provider_name                           = "AWS"
      + backup_enabled                                  = false
      + cloud_backup                                    = true
      + cluster_id                                      = (known after apply)
      + cluster_type                                    = "REPLICASET"
      + connection_strings                              = (known after apply)
      + container_id                                    = (known after apply)
      + disk_size_gb                                    = 2
      + encryption_at_rest_provider                     = (known after apply)
      + id                                              = (known after apply)
      + mongo_db_major_version                          = "6.0"
      + mongo_db_version                                = (known after apply)
      + mongo_uri                                       = (known after apply)
      + mongo_uri_updated                               = (known after apply)
      + mongo_uri_with_options                          = (known after apply)
      + name                                            = "REMOVED_FOR_PRIVACY"
      + num_shards                                      = 1
      + paused                                          = false
      + pit_enabled                                     = true
      + project_id                                      = "REMOVED_FOR_PRIVACY"
      + provider_auto_scaling_compute_max_instance_size = "M5"
      + provider_auto_scaling_compute_min_instance_size = "M2"
      + provider_backup_enabled                         = false
      + provider_disk_iops                              = (known after apply)
      + provider_disk_type_name                         = (known after apply)
      + provider_encrypt_ebs_volume                     = (known after apply)
      + provider_encrypt_ebs_volume_flag                = (known after apply)
      + provider_instance_size_name                     = "M2"
      + provider_name                                   = "TENANT"
      + provider_region_name                            = "EU_WEST_1"
      + provider_volume_type                            = (known after apply)
      + replication_factor                              = (known after apply)
      + retain_backups_enabled                          = false
      + snapshot_backup_policy                          = (known after apply)
      + srv_address                                     = (known after apply)
      + state_name                                      = (known after apply)
      + termination_protection_enabled                  = true
      + version_release_system                          = "LTS"

      + advanced_configuration {
          + default_read_concern                 = (known after apply)
          + default_write_concern                = (known after apply)
          + fail_index_key_too_long              = (known after apply)
          + javascript_enabled                   = (known after apply)
          + minimum_enabled_tls_protocol         = (known after apply)
          + no_table_scan                        = (known after apply)
          + oplog_min_retention_hours            = (known after apply)
          + oplog_size_mb                        = (known after apply)
          + sample_refresh_interval_bi_connector = (known after apply)
          + sample_size_bi_connector             = (known after apply)
        }

      + bi_connector_config {
          + enabled         = (known after apply)
          + read_preference = (known after apply)
        }

      + labels {
          + key   = (known after apply)
          + value = (known after apply)
        }

      + replication_specs {
          + id         = (known after apply)
          + num_shards = (known after apply)
          + zone_name  = (known after apply)

          + regions_config {
              + analytics_nodes = (known after apply)
              + electable_nodes = (known after apply)
              + priority        = (known after apply)
              + read_only_nodes = (known after apply)
              + region_name     = (known after apply)
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
mongodbatlas_cluster.managed: Creating...
╷
│ Error: error creating MongoDB Cluster: POST https://cloud.mongodb.com/api/atlas/v1.0/groups/REMOVED_FOR_PRIVACY/clusters: 400 (request "INVALID_ATTRIBUTE") Invalid attribute providerBackupEnabled specified.
│ 
│   with mongodbatlas_cluster.managed,
│   on mongo_db.tf line 77, in resource "mongodbatlas_cluster" "managed":
│   77: resource "mongodbatlas_cluster" "managed" {
│ 
╵
Releasing state lock. This may take a few moments...

Debug Output

Crash Output

Additional Context

This looks like a problem whereby the API is not accepting a parameter that the terraform provider is sending. It seems the attribute the API is complaining about (providerBackupEnabled) is set when the cloud_backup parameter is provided as a parameter to the mongodbatlas_cluster resource. Seen here: https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/mongodbatlas/resource_mongodbatlas_cluster.go#L492

References

Zuhairahmed commented 1 year ago

@codesmithtech reviewing your terraform script (mongo_db.tf file) it appears you have provider_backup_enabled = null. however per our documentation, the provider_backup_enabled parameter has been deprecated and should therefore be removed from your terraform script. It appears you are already correctly calling cloud_backup instead which is great. can you try removing provider_backup_enabled and see if this helps resolving issue?

codesmithtech commented 1 year ago

Thanks, but the issue persists even when provider_backup_enabled is not passed.

The source code of the provider includes that parameter in its API call to Atlas when the newer cloud_backup parameter is provided... I assume this is the root cause of the bug and included a link to this in the initial bug report.

I can only assume that the Atlas backend API has now fully dropped support for the provider_backup_enabled param, rather than just marking it as deprecated.

martinstibbe commented 1 year ago

@codesmithtech @Zuhairahmed I am not able to replicate this error using v1.10.0 using parameter = null or skipping all together The SDK below and TF still push this value to API but I do not see this error.

github-actions[bot] commented 1 year ago

This issue has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

andreaangiolillo commented 1 year ago

Hello @codesmithtech, We are not able to reproduce this issue with v1.10.2. Please, try to upgrade to v1.10.2 and feel free to reopen this issue if you are still facing the same error.

Thanks