Skip to content

fix: Terraform encryption at rest error when upgrading to 1.12.2 #1617

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

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented Nov 10, 2023

Description

Ticket: INTMDB-1277

This issue came from HELP-52173 where customers are getting the following error when upgrading from v1.11.0 to v1.12.3.

│ Error: Provider produced inconsistent result after apply
--
│
│ When applying changes to mongodbatlas_encryption_at_rest.test, provider "provider[\"registry.terraform.io/mongodb/mongodbatlas\"]"
│ produced an unexpected new value: .aws_kms_config[0].secret_access_key: inconsistent values for sensitive attribute.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Root Cause:

Context:

  • The encryption at rest resource was migrated to the new framework in v1.12.0
  • The user did not define the secret_access_key in the encryption at rest resource but provided the role_id
  • the secret_access_key is never returned by the API response so we added a logic in the TF resource that stores the value of secret_access_key in the TF configuration file inside the state file.

Issue: When upgrading from old framework to the new framework, the state file saves the empty secret_access_key string with the state ValueStateKnown with the empty string instead of using the ValueStateUnKnown which is what is returned with the new framework.
Screenshot 2023-11-10 at 17 32 13

Fix: I updated the logic to update the value of secret_access_key in the state file only it is not empty.

Testing

I tested the logic locally with and without the change and checked that the issue is gone.

2023-11-10T15:55:01.017Z [DEBUG] pruneUnusedNodes: provider["registry.terraform.io/mongodb/mongodbatlas"] is no longer needed, removing
2023-11-10T15:55:01.017Z [DEBUG] pruneUnusedNodes: provider["registry.terraform.io/hashicorp/aws"] is no longer needed, removing
2023-11-10T15:55:01.017Z [DEBUG] Starting graph walk: walkApply

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

I added a migration test to check that is possible to migrate from v1.11.0 to the latest release.
I checked that the test fails when running without the changes

Running tool: /Users/andrea.angiolillo/.asdf/shims/go test -timeout 300000s -run ^TestAccMigrationAdvRS_EncryptionAtRest_basicAWS_from_v1_11_0$ github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas
FAIL    github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 32.276s

and it is successful with my changes

Running tool: /Users/andrea.angiolillo/.asdf/shims/go test -timeout 300000s -run ^TestAccMigrationAdvRS_EncryptionAtRest_basicAWS_from_v1_11_0$ github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas

ok      github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 35.599s

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

@andreaangiolillo andreaangiolillo changed the title INTMDB-1277: Terraform encryption at rest error when upgrading to 1.12.2 fix: Terraform encryption at rest error when upgrading to 1.12.2 Nov 10, 2023
Copy link
Contributor

Code Coverage

Package Line Rate Health
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 2%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/validator 68%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/util 17%
Summary 3% (272 / 10333)

@andreaangiolillo andreaangiolillo marked this pull request as ready for review November 10, 2023 18:00
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner November 10, 2023 18:00
Copy link
Member

@lantoli lantoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great to have a test for it!

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

Successfully merging this pull request may close these issues.

2 participants