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_ecr_repository: handle err, nil output on read #30067

Merged
merged 2 commits into from Mar 16, 2023

Conversation

jar-b
Copy link
Member

@jar-b jar-b commented Mar 16, 2023

Description

Fix to properly handle errors that aren't ResourceNotFound and nil output values.

Relations

Closes #30068

Output from Acceptance Testing

$ make testacc PKG=ecr TESTS=TestAccECRRepository_
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ecr/... -v -count 1 -parallel 20 -run='TestAccECRRepository_'  -timeout 180m
=== RUN   TestAccECRRepository_basic
=== PAUSE TestAccECRRepository_basic
=== RUN   TestAccECRRepository_disappears
=== PAUSE TestAccECRRepository_disappears
=== RUN   TestAccECRRepository_tags
=== PAUSE TestAccECRRepository_tags
=== RUN   TestAccECRRepository_immutability
=== PAUSE TestAccECRRepository_immutability
=== RUN   TestAccECRRepository_Image_scanning
=== PAUSE TestAccECRRepository_Image_scanning
=== RUN   TestAccECRRepository_Encryption_kms
=== PAUSE TestAccECRRepository_Encryption_kms
=== RUN   TestAccECRRepository_Encryption_aes256
=== PAUSE TestAccECRRepository_Encryption_aes256
=== CONT  TestAccECRRepository_basic
=== CONT  TestAccECRRepository_Image_scanning
=== CONT  TestAccECRRepository_Encryption_aes256
=== CONT  TestAccECRRepository_Encryption_kms
=== CONT  TestAccECRRepository_tags
=== CONT  TestAccECRRepository_disappears
=== CONT  TestAccECRRepository_immutability
--- PASS: TestAccECRRepository_disappears (26.36s)
--- PASS: TestAccECRRepository_basic (34.35s)
--- PASS: TestAccECRRepository_immutability (34.42s)
--- PASS: TestAccECRRepository_Encryption_kms (48.77s)
--- PASS: TestAccECRRepository_Encryption_aes256 (49.34s)
--- PASS: TestAccECRRepository_tags (53.78s)
--- PASS: TestAccECRRepository_Image_scanning (56.39s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/ecr        59.599s

@github-actions
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/ecr Issues and PRs that pertain to the ecr service. size/XS Managed by automation to categorize the size of a PR. and removed service/ecr Issues and PRs that pertain to the ecr service. labels Mar 16, 2023
@github-actions github-actions bot added service/ecr Issues and PRs that pertain to the ecr service. and removed service/ecr Issues and PRs that pertain to the ecr service. labels Mar 16, 2023
@jar-b jar-b added the service/ecr Issues and PRs that pertain to the ecr service. label Mar 16, 2023
@jar-b jar-b marked this pull request as ready for review March 16, 2023 18:34
Comment on lines +195 to +197
if outputRaw == nil {
return create.DiagError(names.ECR, create.ErrActionReading, ResNameRepository, d.Id(), errors.New("empty output"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't be necessary as FindRepository already does the nil check.

Copy link
Member Author

Choose a reason for hiding this comment

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

In theory the added err check should prevent this nil check from ever executing, but since we do an unchecked type assertion immediately following (which caused the reported panic) it felt reasonable to add for absolute safety.

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=TestAccECRRepository_' PKG=ecr ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ecr/... -v -count 1 -parallel 2  -run=TestAccECRRepository_ -timeout 180m
=== RUN   TestAccECRRepository_basic
=== PAUSE TestAccECRRepository_basic
=== RUN   TestAccECRRepository_disappears
=== PAUSE TestAccECRRepository_disappears
=== RUN   TestAccECRRepository_tags
=== PAUSE TestAccECRRepository_tags
=== RUN   TestAccECRRepository_immutability
=== PAUSE TestAccECRRepository_immutability
=== RUN   TestAccECRRepository_Image_scanning
=== PAUSE TestAccECRRepository_Image_scanning
=== RUN   TestAccECRRepository_Encryption_kms
=== PAUSE TestAccECRRepository_Encryption_kms
=== RUN   TestAccECRRepository_Encryption_aes256
=== PAUSE TestAccECRRepository_Encryption_aes256
=== CONT  TestAccECRRepository_basic
=== CONT  TestAccECRRepository_Image_scanning
--- PASS: TestAccECRRepository_basic (19.42s)
=== CONT  TestAccECRRepository_tags
--- PASS: TestAccECRRepository_Image_scanning (45.75s)
=== CONT  TestAccECRRepository_immutability
--- PASS: TestAccECRRepository_tags (40.29s)
=== CONT  TestAccECRRepository_Encryption_aes256
--- PASS: TestAccECRRepository_immutability (17.03s)
=== CONT  TestAccECRRepository_Encryption_kms
--- PASS: TestAccECRRepository_Encryption_aes256 (43.93s)
=== CONT  TestAccECRRepository_disappears
--- PASS: TestAccECRRepository_Encryption_kms (42.76s)
--- PASS: TestAccECRRepository_disappears (13.41s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ecr	123.098s

@jar-b jar-b merged commit c004809 into main Mar 16, 2023
39 checks passed
@jar-b jar-b deleted the b-aws_ecr_repository-panic branch March 16, 2023 19:05
@github-actions github-actions bot added this to the v4.59.0 milestone Mar 16, 2023
github-actions bot pushed a commit that referenced this pull request Mar 16, 2023
@github-actions
Copy link

This functionality has been released in v4.59.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
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 Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ecr Issues and PRs that pertain to the ecr service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Provider crash when reading state of an ECR repository
2 participants