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/aws_resourcegroups_resource: fix crash when attempting to parse arn #40579

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

jar-b
Copy link
Member

@jar-b jar-b commented Dec 16, 2024

Description

Previously the group_arn and resource_arn values were assumed to be ARNs in a format which could always be split by a / into at least two parts. The provider did no validation of these inputs prior to attempting to split the value, causing index out of range crashes when values were provided that did not match these assumptions.

Instead of attempting to split ARNs of varying formatting to construct the id attribute, id will now be composed of a comma-delimited string combining group_arn and resource_arn in their entirety. This removes the logic and assumptions around splitting the ARN and should prevent future crashes regardless of the format provided. The more complete content of the id attribute will also enable supporting import for this resource (also added as part of this PR).

Relations

Closes #40504
Closes #40458

Output from Acceptance Testing

% make testacc PKG=resourcegroups TESTS=TestAccResourceGroupsResource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/resourcegroups/... -v -count 1 -parallel 20 -run='TestAccResourceGroupsResource_'  -timeout 360m
2024/12/16 11:04:35 Initializing Terraform AWS Provider...

--- PASS: TestAccResourceGroupsResource_basic (21.88s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups     28.172s

Previously the `group_arn` and `resource_arn` values were assumed to be ARNs in a format which could always be split by a `/` into at least two parts. The provider did no validation of these inputs prior to attempting to split the value, causing `index out of range` crashes when values were provided that did not match these assumptions.

Instead of attempting to split ARNs of varying formatting to construct the `id` attribute, `id` will now be composed of a comma-delimited string combining `group_arn` and `resource_arn` in their entirety. This removes the logic and assumptions around splitting the ARN and should prevent future crashes regardless of the format provided. The more complete content of the `id` attribute will also enable supporting import for this resource, if desired.

```console
% make testacc PKG=resourcegroups TESTS=TestAccResourceGroupsResource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/resourcegroups/... -v -count 1 -parallel 20 -run='TestAccResourceGroupsResource_'  -timeout 360m
2024/12/13 16:29:28 Initializing Terraform AWS Provider...

--- PASS: TestAccResourceGroupsResource_basic (198.52s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups     203.664s
```
An `aws_resourcegroups_resource` resource can now be imported using a comma-delimited string combining `group_arn` and `resource_arn`.

```console
% make testacc PKG=resourcegroups TESTS=TestAccResourceGroupsResource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/resourcegroups/... -v -count 1 -parallel 20 -run='TestAccResourceGroupsResource_'  -timeout 360m
2024/12/16 11:04:35 Initializing Terraform AWS Provider...

--- PASS: TestAccResourceGroupsResource_basic (21.88s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups     28.172s
```
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 documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/resourcegroups Issues and PRs that pertain to the resourcegroups service. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Dec 16, 2024
@jar-b jar-b marked this pull request as ready for review December 16, 2024 17:12
@jar-b jar-b requested a review from a team as a code owner December 16, 2024 17:12
@jar-b jar-b added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. labels Dec 16, 2024
The state upgrader will allow for migration of the pre-existing `id`
format to the new comma-delimited format. An acceptance test was also
added to cover the provider version upgrade workflow.

```console
% make testacc PKG=resourcegroups TESTS=TestAccResourceGroupsResource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/resourcegroups/... -v -count 1 -parallel 20 -run='TestAccResourceGroupsResource_'  -timeout 360m
2024/12/17 16:33:36 Initializing Terraform AWS Provider...

--- PASS: TestAccResourceGroupsResource_basic (22.66s)
--- PASS: TestAccResourceGroupsResource_v5_82_0_upgrade (48.45s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups     54.879s
```
@jar-b
Copy link
Member Author

jar-b commented Dec 17, 2024

Acceptance tests after adding a state upgrader and including a new case for upgrading beyond v5.81.0 (the last with the previous id format).

% make testacc PKG=resourcegroups TESTS=TestAccResourceGroupsResource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/resourcegroups/... -v -count 1 -parallel 20 -run='TestAccResourceGroupsResource_'  -timeout 360m
2024/12/17 16:33:36 Initializing Terraform AWS Provider...

--- PASS: TestAccResourceGroupsResource_basic (22.66s)
--- PASS: TestAccResourceGroupsResource_v5_82_0_upgrade (48.45s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups     54.879s

@jar-b jar-b requested a review from ewbankkit December 17, 2024 21:41
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=TestAccResourceGroupsResource_' PKG=resourcegroups
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/resourcegroups/... -v -count 1 -parallel 20  -run=TestAccResourceGroupsResource_ -timeout 360m
2024/12/18 10:10:41 Initializing Terraform AWS Provider...
=== RUN   TestAccResourceGroupsResource_basic
=== PAUSE TestAccResourceGroupsResource_basic
=== RUN   TestAccResourceGroupsResource_v5_82_0_upgrade
=== PAUSE TestAccResourceGroupsResource_v5_82_0_upgrade
=== CONT  TestAccResourceGroupsResource_basic
=== CONT  TestAccResourceGroupsResource_v5_82_0_upgrade
--- PASS: TestAccResourceGroupsResource_basic (26.51s)
--- PASS: TestAccResourceGroupsResource_v5_82_0_upgrade (54.69s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups	60.585s

@jar-b jar-b merged commit 7d71370 into main Dec 18, 2024
42 checks passed
@jar-b jar-b deleted the b-resourcegroups_resource-crash branch December 18, 2024 15:25
@github-actions github-actions bot added this to the v5.82.0 milestone Dec 18, 2024
terraform-aws-provider bot pushed a commit that referenced this pull request Dec 18, 2024
Copy link

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

@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Dec 19, 2024
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 Jan 19, 2025
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. crash Results from or addresses a Terraform crash or kernel panic. documentation Introduces or discusses updates to documentation. service/resourcegroups Issues and PRs that pertain to the resourcegroups service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
2 participants