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

[#19212] Fix secretsmanager_secret_version update #19943

Merged

Conversation

syndbg
Copy link
Contributor

@syndbg syndbg commented Jun 24, 2021

Fixes the AWS SecretsManager API call failing when there's a drift
between the Terraform state and SecretsManager "state".

The drift is caused by someone/something updating outside of Terraform the given resource.
E.g AWS SecretsManager CLI or AWS SecretsManager Web UI/Console

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #19212.

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAwsSecretsManagerSecretVersion_VersionStages_external_update'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAwsSecretsManagerSecretVersion_VersionStages_external_update -timeout 180m
=== RUN   TestAccAwsSecretsManagerSecretVersion_VersionStages_external_update
=== PAUSE TestAccAwsSecretsManagerSecretVersion_VersionStages_external_update
=== CONT  TestAccAwsSecretsManagerSecretVersion_VersionStages_external_update
--- PASS: TestAccAwsSecretsManagerSecretVersion_VersionStages_external_update (61.19s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       61.246s
...

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/secretsmanager Issues and PRs that pertain to the secretsmanager service. size/S Managed by automation to categorize the size of a PR. labels Jun 24, 2021
@syndbg syndbg force-pushed the gh-19212-fix-secrets-manager-version-update branch 2 times, most recently from 01fd86a to 6510566 Compare June 24, 2021 14:51
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @syndbg 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@syndbg syndbg changed the title [GH-#19212] Fix secretsmanager_secret_version update [#19212] Fix secretsmanager_secret_version update Jun 25, 2021
@syndbg syndbg force-pushed the gh-19212-fix-secrets-manager-version-update branch from 6510566 to bb12b21 Compare June 25, 2021 09:40
@github-actions github-actions bot added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Jun 25, 2021
@syndbg syndbg marked this pull request as ready for review June 25, 2021 10:30
@syndbg syndbg force-pushed the gh-19212-fix-secrets-manager-version-update branch from bb12b21 to a66e804 Compare June 25, 2021 10:40
Fixes the AWS SecretsManager API call failing when there's a drift
between the Terraform state and SecretsManager "state".

The drift is caused by someone/something updating outside of Terraform the given resource.
E.g AWS SecretsManager CLI or AWS SecretsManager Web UI/Console
@syndbg syndbg force-pushed the gh-19212-fix-secrets-manager-version-update branch from a66e804 to 89d24dd Compare June 25, 2021 10:43
@syndbg
Copy link
Contributor Author

syndbg commented Jun 28, 2021

Any chance you can take a look at this? @ewbankkit @bill-rich 👀

@syndbg
Copy link
Contributor Author

syndbg commented Jul 22, 2021

Is there anything missing/done wrong in the PR?

We (https:/sumup) kinda need this fix.

@breathingdust breathingdust added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 3, 2021
@zhelding
Copy link
Contributor

Pull request #21306 has significantly refactored the AWS Provider codebase. As a result, most PRs opened prior to the refactor now have merge conflicts that must be resolved before proceeding.

Specifically, PR #21306 relocated the code for all AWS resources and data sources from a single aws directory to a large number of separate directories in internal/service, each corresponding to a particular AWS service. This separation of code has also allowed for us to simplify the names of underlying functions -- while still avoiding namespace collisions.

We recognize that many pull requests have been open for some time without yet being addressed by our maintainers. Therefore, we want to make it clear that resolving these conflicts in no way affects the prioritization of a particular pull request. Once a pull request has been prioritized for review, the necessary changes will be made by a maintainer -- either directly or in collaboration with the pull request author.

For a more complete description of this refactor, including examples of how old filepaths and function names correspond to their new counterparts: please refer to issue #20000.

For a quick guide on how to amend your pull request to resolve the merge conflicts resulting from this refactor and bring it in line with our new code patterns: please refer to our Service Package Refactor Pull Request Guide.

@X-Guardian
Copy link

@syndbg, are you able to resolve the conflicts on this PR, as this issue still exists.

% make testacc TESTARGS='-run=TestAccSecretsManagerSecretVersion_multipleVersions' PKG=secretsmanager
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/secretsmanager/... -v -count 1 -parallel 20  -run=TestAccSecretsManagerSecretVersion_multipleVersions -timeout 360m
=== RUN   TestAccSecretsManagerSecretVersion_multipleVersions
=== PAUSE TestAccSecretsManagerSecretVersion_multipleVersions
=== CONT  TestAccSecretsManagerSecretVersion_multipleVersions
--- PASS: TestAccSecretsManagerSecretVersion_multipleVersions (18.29s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager	24.282s
% make testacc TESTARGS='-run=TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate' PKG=secretsmanager
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/secretsmanager/... -v -count 1 -parallel 20  -run=TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate -timeout 360m
=== RUN   TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate
=== PAUSE TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate
=== CONT  TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate
    secret_version_test.go:148: Step 2/2 error: Error running apply: exit status 1

        Error: adding Secrets Manager Secret Version (arn:aws:secretsmanager:us-west-2:187416307283:secret:tf-acc-test-6730888995458695428-SDqgH6|terraform-20240117143626546000000002) stage (AWSCURRENT): operation error Secrets Manager: UpdateSecretVersionStage, https response error StatusCode: 400, RequestID: ca7aa42b-4d72-4bf3-80f4-ba679691182e, InvalidParameterException: The parameter RemoveFromVersionId can't be empty. Staging label AWSCURRENT is currently attached to version e307a6be-8c34-400a-9154-c6908e71788b, so you must explicitly reference that version in RemoveFromVersionId.

          with aws_secretsmanager_secret_version.test,
          on terraform_plugin_test.tf line 16, in resource "aws_secretsmanager_secret_version" "test":
          16: resource "aws_secretsmanager_secret_version" "test" {

--- FAIL: TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate (20.48s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager	25.941s
FAIL
make: *** [testacc] Error 1
…The parameter RemoveFromVersionId can't be empty. Staging label AWSCURRENT is currently attached to version ..., so you must explicitly reference that version in RemoveFromVersionId` errors when a secret is updated outside Terraform.
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccSecretsManagerSecretVersion_' PKG=secretsmanager ACCTEST_PARALLELISM=3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/secretsmanager/... -v -count 1 -parallel 3  -run=TestAccSecretsManagerSecretVersion_ -timeout 360m
=== RUN   TestAccSecretsManagerSecretVersion_basicString
=== PAUSE TestAccSecretsManagerSecretVersion_basicString
=== RUN   TestAccSecretsManagerSecretVersion_base64Binary
=== PAUSE TestAccSecretsManagerSecretVersion_base64Binary
=== RUN   TestAccSecretsManagerSecretVersion_versionStages
=== PAUSE TestAccSecretsManagerSecretVersion_versionStages
=== RUN   TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate
=== PAUSE TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate
=== RUN   TestAccSecretsManagerSecretVersion_disappears
=== PAUSE TestAccSecretsManagerSecretVersion_disappears
=== RUN   TestAccSecretsManagerSecretVersion_Disappears_secret
=== PAUSE TestAccSecretsManagerSecretVersion_Disappears_secret
=== RUN   TestAccSecretsManagerSecretVersion_multipleVersions
=== PAUSE TestAccSecretsManagerSecretVersion_multipleVersions
=== CONT  TestAccSecretsManagerSecretVersion_basicString
=== CONT  TestAccSecretsManagerSecretVersion_disappears
=== CONT  TestAccSecretsManagerSecretVersion_versionStages
--- PASS: TestAccSecretsManagerSecretVersion_disappears (19.03s)
=== CONT  TestAccSecretsManagerSecretVersion_multipleVersions
--- PASS: TestAccSecretsManagerSecretVersion_basicString (22.62s)
=== CONT  TestAccSecretsManagerSecretVersion_base64Binary
--- PASS: TestAccSecretsManagerSecretVersion_multipleVersions (20.49s)
=== CONT  TestAccSecretsManagerSecretVersion_Disappears_secret
--- PASS: TestAccSecretsManagerSecretVersion_base64Binary (21.78s)
=== CONT  TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate
--- PASS: TestAccSecretsManagerSecretVersion_versionStages (49.04s)
--- PASS: TestAccSecretsManagerSecretVersion_Disappears_secret (18.05s)
--- PASS: TestAccSecretsManagerSecretVersion_versionStagesExternalUpdate (27.47s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager	81.236s

@ewbankkit
Copy link
Contributor

@syndbg Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit 3329431 into hashicorp:main Jan 17, 2024
36 checks passed
@github-actions github-actions bot added this to the v5.33.0 milestone Jan 17, 2024
Copy link

This functionality has been released in v5.33.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/secretsmanager Issues and PRs that pertain to the secretsmanager service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_secretsmanager_secret_version fails to move the AWSCURRENT label
7 participants