-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
fix(opensearchserverless): security_policy policy attribute doesn't normalize json strings #38604
Conversation
…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
Community NoteVoting for Prioritization
For Submitters
|
Validators: []validator.String{ | ||
stringvalidator.LengthBetween(1, 20480), | ||
}, | ||
}, | ||
"policy_version": schema.StringAttribute{ | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ```
There was a problem hiding this 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
Thanks for your contribution, @corymhall! 👍 |
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! |
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. |
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 usesjsontypes.Normalize
as the type instead oftypes.String
. I have copied most of the implementation fromaccess_policy
and added tests which test using a string value instead ofjsonencode
.closes #38603
Output from Acceptance Testing