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
242 stars 168 forks source link

[Bug]: mongodbatlas_search_deployment on multi region setup state corrupted #2612

Open victorswed opened 1 month ago

victorswed commented 1 month ago

Is there an existing issue for this?

Provider Version

v.1.15.3

Terraform Version

v1.0.9

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

I am trying to add the mongodbatlas_search_deployment into my multi-region setup.

resource "mongodbatlas_search_deployment" "search_nodes" {
  count        = var.search_node ? 1 : 0 
  project_id   = mongodbatlas_project.atlas_project.id
  cluster_name = mongodbatlas_advanced_cluster.atlas_cluster.name
  specs = [
    {
      instance_size = var.search_node_size
      node_count    = var.search_node_count
    }
  ]
  depends_on = [mongodbatlas_advanced_cluster.atlas_cluster]
}

This is my current cluster configuration for multi region

  replication_specs {
    region_configs {
      electable_specs {
        instance_size = M50
        node_count    = 2
      }
      provider_name = "GCP"
      priority      = 7
      region_name   = CENTRAL_US
    }
    region_configs {
      electable_specs {
        instance_size = M50
        node_count    = 2
      }
      provider_name = "GCP"
      priority      = 6
      region_name   = US_WEST_2
    }
    region_configs {
      electable_specs {
        instance_size = M50
        node_count    = 1
      }
      provider_name = "GCP"
      priority      = 5
      region_name   = EASTERN_US
    }
  }

here's how the state looks after apply not sure why this tripled

            "specs": [
              {
                "instance_size": "S30_HIGHCPU_NVME",
                "node_count": 2
              },
              {
                "instance_size": "S30_HIGHCPU_NVME",
                "node_count": 2
              },
              {
                "instance_size": "S30_HIGHCPU_NVME",
                "node_count": 2
              }
            ],
            "state_name": "IDLE",
            "timeouts": null
          },

after apply on the next plan

  # module.mymodule_name.mongodbatlas_search_deployment.search_nodes[0] is tainted, so must be replaced
-/+ resource "mongodbatlas_search_deployment" "search_nodes" {
      ~ id           = "xxxxxxxxxxxxxxxxx" -> (known after apply)
      ~ specs        = [
          ~ {
            - instance_size = "S30_HIGHCPU_NVME" -> null
            - node_count    = 2 -> null

            - instance_size = "S30_HIGHCPU_NVME" -> null
            - node_count    = 2 -> null
          },
          # (1 unchanged element hidden)
        ]
      ~ state_name   = "IDLE" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

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

In a different setup with a single region cluster this not reporduces

Terraform configuration to reproduce the issue

resource "mongodbatlas_search_deployment" "search_nodes" {
  count        = var.search_node ? 1 : 0 
  project_id   = mongodbatlas_project.atlas_project.id
  cluster_name = mongodbatlas_advanced_cluster.atlas_cluster.name
  specs = [
    {
      instance_size = var.search_node_size
      node_count    = var.search_node_count
    }
  ]
  depends_on = [mongodbatlas_advanced_cluster.atlas_cluster]
}

Steps To Reproduce

setup multi region cluster add the search deployment configuration apply, run plan again.

Logs

No response

Code of Conduct

github-actions[bot] commented 1 month ago

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

The ticket CLOUDP-274519 was created for internal tracking.

EspenAlbert commented 1 month ago

Hi @victorswed Thank you for reporting this issue. I was able to reproduce it. We'll keep you posted on our progress to fix it.