Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import export bucket - bad state id encoding #708

Closed
ghost opened this issue Apr 5, 2022 · 4 comments
Closed

Cannot import export bucket - bad state id encoding #708

ghost opened this issue Apr 5, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 5, 2022

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:

d.SetId(encodeStateID(map[string]string{
"project_id": *projectID,
"name": *id,
}))

And the read function is looking for bucketID in the key id in the decoded id map?

func resourceMongoDBAtlasCloudBackupSnapshotExportBucketRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
// Get client connection.
conn := meta.(*MongoDBClient).Atlas
ids := decodeStateID(d.Id())
projectID := ids["project_id"]
bucketID := ids["id"]
exportBackup, _, err := conn.CloudProviderSnapshotExportBuckets.Get(ctx, projectID, bucketID)
if err != nil {
// case 404
// deleted in the backend case
reset := strings.Contains(err.Error(), "404") && !d.IsNewResource()
if reset {
d.SetId("")
return nil
}
return diag.Errorf("error getting snapshot export backup information: %s", err)
}

Debug Output

References

@themantissa
Copy link
Collaborator

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

Internal ticket: INTMDB-315

@themantissa
Copy link
Collaborator

@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
Copy link
Collaborator

@sophos-daniels this is now out in 1.4.1.

@ghost
Copy link
Author

ghost commented Jul 7, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant