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

produced an unexpected new value: Root resource was present, but now │ absent #1160

Closed joshworktango closed 1 year ago

joshworktango commented 1 year ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.4.6

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

Terraform Configuration File

resource "mongodbatlas_cluster" "automated_backup_test" {
    project_id   = local.project_id
    name         = "automated-backup-test"

  //Provider Settings "block"
    provider_name               = "GCP"
    provider_region_name        = "US_EAST_4"
    provider_instance_size_name = "M30"
    cloud_backup                = false   // enable cloud backup snapshots
    mongo_db_major_version       = "4.2"
    disk_size_gb = "350"
  }

  resource "mongodbatlas_cloud_backup_snapshot_restore_job" "automated_backup_test" {
    project_id      = local.project_id
    cluster_name    = mongodbatlas_cluster.automated_backup_test.name
    snapshot_id     = data.mongodbatlas_cloud_backup_snapshots.latest_snapshot.results[0].id
    delivery_type_config   {
      automated           = true
      target_cluster_name = mongodbatlas_cluster.automated_backup_test.name
      target_project_id   = local.project_id
    }
  }

data "mongodbatlas_cloud_backup_snapshots" "latest_snapshot" {
project_id = local.project_id
  cluster_name = "<>"
  page_num = 1
  items_per_page = 1
}

output "snapshot_results" {
  value = data.mongodbatlas_cloud_backup_snapshots.latest_snapshot.results[0].id
}
# Copy-paste your configuration info here

Steps to Reproduce

terraform init

terraform apply -auto-approve

Expected Behavior

Expected to fully apply which creates a cluster and restores a backup from a snapshot. Works when run manually on my local laptop

Actual Behavior

mongodbatlas_cluster.automated_backup_test: Creation complete after 16m55s
mongodbatlas_cloud_backup_snapshot_restore_job.automated_backup_test: Creating...
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ mongodbatlas_cloud_backup_snapshot_restore_job.automated_backup_test,
│ provider "provider[\"registry.terraform.io/mongodb/mongodbatlas\"]"
│ produced an unexpected new value: Root resource was present, but now
│ absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Debug Output

Crash Output

Additional Context

This is happening inside a debain docker container running on a mac M1 MBP with docker desktop. Plan is GKE on x86 but for now M1 local testing

References

andreaangiolillo commented 1 year ago

Hello @joshworktango

I was able to reproduce the issue in my local environment using the provided configuration file. The issue lies in the fact that the same cluster name is being used for both the cluster_name and target_cluster_name fields in the "mongodbatlas_cloud_backup_snapshot_restore_job" resource.

To resolve this, you need to update the cluster_name field with the name of the cluster where the snapshot was taken. After making this change, the Terraform apply command should successfully apply your modifications. Here's the updated configuration:

resource "mongodbatlas_cloud_backup_snapshot_restore_job" "automated_backup_test" {
    project_id      = local.project_id
    cluster_name    = <UPDATE THIS WITH THE NAME OF THE CLUSTER USED TO TAKE THE SNAPSHOT>
    snapshot_id     = data.mongodbatlas_cloud_backup_snapshots.latest_snapshot.results[0].id
    delivery_type_config   {
      automated           = true
      target_cluster_name = mongodbatlas_cluster.automated_backup_test.name
      target_project_id   = local.project_id
    }
  }

Please let me know if you encounter any further issues. Thanks

Zuhairahmed commented 1 year ago

@joshworktango just checking if this helps? if so feel free to close out this issue, thank you

joshworktango commented 1 year ago

@joshworktango just checking if this helps? if so feel free to close out this issue, thank you

Hi sorry just tested this, this morning. Was off work for a few days. That seems to have resolved the issue though interesting it only happens inside the docker container not on my Mac