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

Cannot import export bucket - bad state id encoding #708

Closed ghost closed 2 years ago

ghost commented 2 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.1.7
on darwin_amd64
+ provider registry.terraform.io/mongodb/mongodbatlas v1.3.1

Terraform Configuration File

resource "mongodbatlas_cloud_backup_snapshot_export_bucket" "this" {
  project_id     = var.atlas_project_id
  iam_role_id    = mongodbatlas_cloud_provider_access_setup.this.role_id
  bucket_name    = module.s3_bucket.s3_bucket_id
  cloud_provider = "AWS"

  depends_on = [
    mongodbatlas_cloud_provider_access_authorization.this
  ]
}

Steps to Reproduce

terraform import "module.atlas_backup_export[0].mongodbatlas_cloud_backup_snapshot_export_bucket.this" someProjectId-someBucketId

Expected Behavior

The existing export bucket should have been successfully imported into state.

Actual Behavior

module.atlas_backup_export[0].mongodbatlas_cloud_backup_snapshot_export_bucket.this: Importing from ID "someProjectId-someBucketId"...
module.atlas_backup_export[0].mongodbatlas_cloud_backup_snapshot_export_bucket.this: Import prepared!
  Prepared mongodbatlas_cloud_backup_snapshot_export_bucket for import
module.atlas_backup_export[0].mongodbatlas_cloud_backup_snapshot_export_bucket.this: Refreshing state... [id=theBase64EncodedStateId]

│ Error: error getting snapshot export backup information: bucketID is invalid because must be set
│ 
│ 

I believe the import fails because the import state function passes the wrong map keys to the encodeStateID function here: https://github.com/mongodb/terraform-provider-mongodbatlas/blob/778064bb2aabc2a018e8c44f9ae467a840575711/mongodbatlas/resource_mongodbatlas_cloud_backup_snapshot_export_bucket.go#L158-L161

And the read function is looking for bucketID in the key id in the decoded id map? https://github.com/mongodb/terraform-provider-mongodbatlas/blob/778064bb2aabc2a018e8c44f9ae467a840575711/mongodbatlas/resource_mongodbatlas_cloud_backup_snapshot_export_bucket.go#L89-L108

Debug Output

References

themantissa commented 2 years ago

Thank you @sophos-daniels for the complete issue. We will look into it.

Internal ticket: INTMDB-315

themantissa commented 2 years ago

@sophos-daniels this is corrected in version 1.4.0, which is now available as a pre-release version in this repo. We will release it tomorrow.

themantissa commented 2 years ago

@sophos-daniels this is now out in 1.4.1.

ghost commented 2 years ago

Thank you!