Skip to content

[Bug]: mongodbatlas_advanced_cluster keeps previous mongo_db_major_version in state after out-of-band major upgrade #4398

@mkusaka

Description

@mkusaka

Is there an existing issue for this?

  • I have searched the existing issues

Provider Version

v2.10.0

Terraform Version

v1.14.8

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

After upgrading an Atlas cluster out-of-band from MongoDB 7.0 to 8.0 and unpinning FCV, Atlas API returns:

  • featureCompatibilityVersion = "8.0"
  • mongoDBMajorVersion = "8.0"
  • mongoDBVersion = "8.0.21"

However, mongodbatlas_advanced_cluster appears to keep the previous mongo_db_major_version value from Terraform state ("7.0"), which causes a persistent diff when the configuration is updated to "8.0".

In my case:

  • setting mongo_db_major_version = "8.0" produces a plan with mongo_db_major_version = "7.0" -> "8.0"
  • setting mongo_db_major_version = "7.0" with pinned_fcv = null results in No changes

This makes it look like the provider state is retaining the old major version even though Atlas API reports 8.0.

I believe the issue may be related to this logic in internal/service/advancedcluster/resource_compatiblity.go:

beforeVersion := conversion.NilForUnknown(modelIn.MongoDBMajorVersion, modelIn.MongoDBMajorVersion.ValueStringPointer())
if beforeVersion != nil && !modelIn.MongoDBMajorVersion.Equal(modelOut.MongoDBMajorVersion) {
	modelOut.MongoDBMajorVersion = types.StringPointerValue(beforeVersion)
}

That seems to overwrite the API value with the previous state value whenever they differ. This may have been intended to smooth over formatting differences such as 8 vs 8.0, but it also masks a real 7.0 -> 8.0 transition.

Terraform configuration to reproduce the issue

resource "mongodbatlas_advanced_cluster" "test" {
  project_id   = var.project_id
  name         = var.cluster_name
  cluster_type = "REPLICASET"

  mongo_db_major_version = "8.0"

  pinned_fcv = null

  replication_specs = [{
    region_configs = [{
      provider_name = "AWS"
      region_name   = "AP_NORTHEAST_1"
      priority      = 7

      electable_specs = {
        instance_size = "M10"
        node_count    = 3
        disk_size_gb  = 15
      }

      auto_scaling = {
        compute_enabled            = true
        compute_scale_down_enabled = true
        compute_min_instance_size  = "M10"
        compute_max_instance_size  = "M40"
        disk_gb_enabled            = true
      }
    }]
  }]

  backup_enabled                 = true
  pit_enabled                    = true
  termination_protection_enabled = true
  version_release_system         = "LTS"
}

variable "project_id" {
  type = string
}

variable "cluster_name" {
  type = string
}

Steps To Reproduce

  1. Create and apply the cluster with mongo_db_major_version = "7.0".
  2. Upgrade the cluster out-of-band in Atlas UI (or Atlas API) from MongoDB 7.0 to 8.0.
  3. Unpin FCV so that the cluster is fully on 8.0.
  4. Verify Atlas API returns:
    • featureCompatibilityVersion = "8.0"
    • mongoDBMajorVersion = "8.0"
    • mongoDBVersion = "8.0.21"
  5. Update Terraform config to:
    • mongo_db_major_version = "8.0"
    • pinned_fcv = null
  6. Run terraform plan.
  7. Observe that Terraform still proposes:
    • mongo_db_major_version = "7.0" -> "8.0"
      even though Atlas API already reports 8.0.
  8. Optionally, change mongo_db_major_version back to "7.0" while keeping pinned_fcv = null and run terraform plan again.
  9. Observe that the plan becomes No changes, which suggests the provider is preserving the old state value rather than the API value.

Logs

Atlas CLI / Atlas Admin API result:

"featureCompatibilityVersion":"8.0"
"mongoDBMajorVersion":"8.0"
"mongoDBVersion":"8.0.21"

terraform plan excerpt when config uses mongo_db_major_version = "8.0":

~ mongo_db_major_version = "7.0" -> "8.0"
~ mongo_db_version       = "8.0.21" -> (known after apply)

terraform plan result when config uses mongo_db_major_version = "7.0" and pinned_fcv = null:

No changes. Your infrastructure matches the configuration.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions