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

r/role_policy_attachments_exclusive: Fix 'Value Conversion Error' on … #40076

Conversation

MS99-9
Copy link

@MS99-9 MS99-9 commented Nov 10, 2024

Description

Error raised here: https://github.com/hashicorp/terraform-plugin-framework/blob/c9bbe5e02cfc78b6efe82a227a55c26dc2a1daa9/internal/reflect/into.go#L130-L149. As Allowing Unhandled Nulls was set to false here: https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/iam/role_policy_attachments_exclusive.go#L71

Please find attached a screenshot for the new error message after building the development provider and running it locally.

Screenshot 2024-11-10 at 6 59 41 PM

Relations

Closes #39786

References

Output from Acceptance Testing

% make testacc PKG=iam TESTS=TestAccIAMRolePolicyAttachmentsExclusive_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.2 test ./internal/service/iam/... -v -count 1 -parallel 20 -run='TestAccIAMRolePolicyAttachmentsExclusive_'  -timeout 360m
2024/11/10 17:28:20 Initializing Terraform AWS Provider...
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_basic
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_basic
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_disappears_Role
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_disappears_Role
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_disappears_Policy
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_disappears_Policy
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_multiple
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_multiple
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_empty
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_empty
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_outOfBandRemoval
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_outOfBandRemoval
=== RUN   TestAccIAMRolePolicyAttachmentsExclusive_outOfBandAddition
=== PAUSE TestAccIAMRolePolicyAttachmentsExclusive_outOfBandAddition
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_basic
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_empty
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_disappears_Policy
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_multiple
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_disappears_Role
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_outOfBandAddition
=== CONT  TestAccIAMRolePolicyAttachmentsExclusive_outOfBandRemoval
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_empty (116.08s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_disappears_Role (116.62s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_disappears_Policy (122.91s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_basic (123.43s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_outOfBandAddition (159.84s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_outOfBandRemoval (160.92s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_multiple (172.18s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/iam        173.497s
...

…Create.

Signed-off-by: Mohamed Medhat Mohamed Ibrahim Shalaby <[email protected]>
@MS99-9 MS99-9 requested a review from a team as a code owner November 10, 2024 17:00
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 service/iam Issues and PRs that pertain to the iam service. needs-triage Waiting for first response or review from a maintainer. labels Nov 10, 2024
Signed-off-by: Mohamed Medhat Mohamed Ibrahim Shalaby <[email protected]>
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 @MS99-9 👋

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 CONTRIBUTOR 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! 😃

@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Nov 11, 2024
This custom validator checks for the presence of null values within a set, raising a plan time validation error if detected.

```console
% go test ./internal/framework/validators/...
ok      github.com/hashicorp/terraform-provider-aws/internal/framework/validators       0.773s
```
@jar-b jar-b self-assigned this Nov 11, 2024
@github-actions github-actions bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Nov 11, 2024
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=iam TESTS="TestAccIAM.*PolicyAttachmentsExclusive_"
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.2 test ./internal/service/iam/... -v -count 1 -parallel 20 -run='TestAccIAM.*PolicyAttachmentsExclusive_'  -timeout 360m
2024/11/11 15:31:02 Initializing Terraform AWS Provider...

--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_basic (27.53s)
=== CONT  TestAccIAMGroupPolicyAttachmentsExclusive_empty
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_basic (27.64s)
--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_disappears_Policy (35.79s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_disappears_Role (35.82s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_disappears_Policy (35.84s)
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_disappears_User (36.03s)
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_empty (37.76s)
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_disappears_Policy (40.78s)
--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_disappears_Group (40.80s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_empty (42.78s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_basic (45.26s)
--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_multiple (46.06s)
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_multiple (46.32s)
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_outOfBandAddition (48.83s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_outOfBandAddition (49.06s)
--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_outOfBandRemoval (49.82s)
--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_outOfBandAddition (49.96s)
--- PASS: TestAccIAMUserPolicyAttachmentsExclusive_outOfBandRemoval (49.97s)
--- PASS: TestAccIAMGroupPolicyAttachmentsExclusive_empty (22.48s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_outOfBandRemoval (52.07s)
--- PASS: TestAccIAMRolePolicyAttachmentsExclusive_multiple (54.38s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/iam        59.389s
% make testacc PKG=iam TESTS="TestAccIAM.*PoliciesExclusive_"
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.2 test ./internal/service/iam/... -v -count 1 -parallel 20 -run='TestAccIAM.*PoliciesExclusive_'  -timeout 360m
2024/11/11 15:35:35 Initializing Terraform AWS Provider...

--- PASS: TestAccIAMUserPoliciesExclusive_empty (29.75s)
--- PASS: TestAccIAMRolePoliciesExclusive_empty (30.14s)
--- PASS: TestAccIAMGroupPoliciesExclusive_disappears_Group (31.95s)
--- PASS: TestAccIAMGroupPoliciesExclusive_basic (33.12s)
--- PASS: TestAccIAMUserPoliciesExclusive_basic (33.23s)
--- PASS: TestAccIAMRolePoliciesExclusive_basic (34.02s)
--- PASS: TestAccIAMUserPoliciesExclusive_disappears_User (34.02s)
--- PASS: TestAccIAMGroupPoliciesExclusive_empty (35.27s)
--- PASS: TestAccIAMRolePoliciesExclusive_disappears_Role (35.30s)
--- PASS: TestAccIAMGroupPoliciesExclusive_outOfBandAddition (43.21s)
--- PASS: TestAccIAMGroupPoliciesExclusive_outOfBandRemoval (43.65s)
--- PASS: TestAccIAMRolePoliciesExclusive_outOfBandRemoval (43.94s)
--- PASS: TestAccIAMUserPoliciesExclusive_outOfBandRemoval (44.03s)
--- PASS: TestAccIAMUserPoliciesExclusive_multiple (44.14s)
--- PASS: TestAccIAMGroupPoliciesExclusive_multiple (44.15s)
--- PASS: TestAccIAMUserPoliciesExclusive_outOfBandAddition (44.27s)
--- PASS: TestAccIAMRolePoliciesExclusive_outOfBandAddition (44.37s)
--- PASS: TestAccIAMRolePoliciesExclusive_multiple (46.41s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/iam        51.423s

@jar-b
Copy link
Member

jar-b commented Nov 11, 2024

Thanks for your contribution, @MS99-9 ! 👍

I modified the change slightly to use a custom set validator which checks for the presence of null values. I also applied this validator to the other _exclusive IAM resources (role, group, and user variants of both customer managed and inline policies). The resulting error still looks similar to the screenshot in the PR body:

│ Error: Null Set Value
│
│   with aws_iam_role_policy_attachments_exclusive.test,
│   on main.tf line 27, in resource "aws_iam_role_policy_attachments_exclusive" "test":
│   27:   policy_arns = [
│   28:     aws_iam_policy.test.arn,
│   29:     null, # test should trigger a plan time validation failure
│   30:   ]
│
│ This attribute contains a null value.

Appreciate you picking this up!

@MS99-9
Copy link
Author

MS99-9 commented Nov 11, 2024

This is my first contribution so your feedback is really appreciated @jar-b, I also learned from the commits you added to make the validator more dynamic so we can re-use it for other resources. I will take this into consideration for my next contributions.
Thanks

@jar-b jar-b merged commit 0c6d8bc into hashicorp:main Nov 11, 2024
30 checks passed
@github-actions github-actions bot added this to the v5.76.0 milestone Nov 11, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Nov 14, 2024
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Value Conversion Error with aws_iam_role_policy_attachments_exclusive and null values for policy_arns
3 participants