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

fix(opensearchserverless): security_policy policy attribute doesn't normalize json strings #38604

Merged

Conversation

corymhall
Copy link
Contributor

The policy attribute is a string type, but requires the string to be valid json. The user can input json with the keys in any order, but the value stored in state will have the keys in order causing an error message on apply (see linked issue for details).

This resource is very similar to the access_policy resource which uses jsontypes.Normalize as the type instead of types.String. I have copied most of the implementation from access_policy and added tests which test using a string value instead of jsonencode.

closes #38603

Output from Acceptance Testing

% make testacc TESTS=TestAccOpenSearchServerlessSecurityPolicy PKG=opensearchserverless
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/opensearchserverless/... -v -count 1 -parallel 20 -run='TestAccOpenSearchServerlessSecurityPolicy'  -timeout 360m
=== RUN   TestAccOpenSearchServerlessSecurityPolicyDataSource_basic
=== PAUSE TestAccOpenSearchServerlessSecurityPolicyDataSource_basic
=== RUN   TestAccOpenSearchServerlessSecurityPolicy_basic
=== PAUSE TestAccOpenSearchServerlessSecurityPolicy_basic
=== RUN   TestAccOpenSearchServerlessSecurityPolicy_string
=== PAUSE TestAccOpenSearchServerlessSecurityPolicy_string
=== RUN   TestAccOpenSearchServerlessSecurityPolicy_update
=== PAUSE TestAccOpenSearchServerlessSecurityPolicy_update
=== RUN   TestAccOpenSearchServerlessSecurityPolicy_string_update
=== PAUSE TestAccOpenSearchServerlessSecurityPolicy_string_update
=== RUN   TestAccOpenSearchServerlessSecurityPolicy_disappears
=== PAUSE TestAccOpenSearchServerlessSecurityPolicy_disappears
=== CONT  TestAccOpenSearchServerlessSecurityPolicyDataSource_basic
=== CONT  TestAccOpenSearchServerlessSecurityPolicy_update
=== CONT  TestAccOpenSearchServerlessSecurityPolicy_disappears
=== CONT  TestAccOpenSearchServerlessSecurityPolicy_basic
=== CONT  TestAccOpenSearchServerlessSecurityPolicy_string_update
=== CONT  TestAccOpenSearchServerlessSecurityPolicy_string
--- PASS: TestAccOpenSearchServerlessSecurityPolicyDataSource_basic (8.78s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_disappears (9.07s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_basic (10.38s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_string (12.68s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_string_update (13.52s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_update (13.61s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/opensearchserverless       17.472s

…ormalize json strings

The `policy` attribute is a string type, but requires the string to be
valid json. The user can input json with the keys in any order, but the
value stored in state will have the keys in order causing an error
message on apply (see linked issue for details).

This resource is very similar to the `access_policy` resource which uses
`jsontypes.Normalize` as the type instead of `types.String`. I have
copied most of the implementation from `access_policy` and added tests
which test using a string value instead of `jsonencode`.

fixes hashicorp#38603
@corymhall corymhall requested a review from a team as a code owner July 30, 2024 19:56
Copy link

Community Note

Voting for Prioritization

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

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/opensearchserverless Issues and PRs that pertain to the opensearchserverless service. needs-triage Waiting for first response or review from a maintainer. labels Jul 30, 2024
@jar-b jar-b removed the needs-triage Waiting for first response or review from a maintainer. label Jul 31, 2024
Validators: []validator.String{
stringvalidator.LengthBetween(1, 20480),
},
},
"policy_version": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This was useful or needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was needed. Without it the update test failed with missing required field, UpdateSecurityPolicyInput.PolicyVersion.

… tests

```console
% make testacc PKG=opensearchserverless TESTS="TestAccOpenSearchServerlessSecurityPolicy_"
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/opensearchserverless/... -v -count 1 -parallel 20 -run='TestAccOpenSearchServerlessSecurityPolicy_'  -timeout 360m

--- PASS: TestAccOpenSearchServerlessSecurityPolicy_disappears (12.95s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_basic (14.98s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_string (18.38s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_update (19.96s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_stringUpdate (21.87s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/opensearchserverless       27.933s
```
Copy link
Member

@jar-b jar-b 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 PKG=opensearchserverless TESTS="TestAccOpenSearchServerlessSecurityPolicy_"
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/opensearchserverless/... -v -count 1 -parallel 20 -run='TestAccOpenSearchServerlessSecurityPolicy_'  -timeout 360m

--- PASS: TestAccOpenSearchServerlessSecurityPolicy_disappears (12.95s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_basic (14.98s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_string (18.38s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_update (19.96s)
--- PASS: TestAccOpenSearchServerlessSecurityPolicy_stringUpdate (21.87s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/opensearchserverless       27.933s

@jar-b
Copy link
Member

jar-b commented Jul 31, 2024

Thanks for your contribution, @corymhall! 👍

@jar-b jar-b merged commit 894d7aa into hashicorp:main Jul 31, 2024
34 checks passed
@github-actions github-actions bot added this to the v5.61.0 milestone Jul 31, 2024
Copy link

github-actions bot commented Aug 2, 2024

This functionality has been released in v5.61.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

github-actions bot commented Sep 1, 2024

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 Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/opensearchserverless Issues and PRs that pertain to the opensearchserverless service. 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.

[Bug]: aws_opensearchserverless_security_policy.policy fails to normalize json strings
3 participants