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

awsproviderlint: New Check: Prefer aws_ami data source instead of hardcoded Amazon Machine Image identifiers #12994

Closed
17 tasks done
breathingdust opened this issue Apr 24, 2020 · 6 comments · Fixed by #15143
Closed
17 tasks done
Assignees
Labels
linter Pertains to changes to or issues with the various linters. partition/aws-us-gov Pertains to the aws-us-gov partition. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. technical-debt Addresses areas of the codebase that need refactoring or redesign.

Comments

@breathingdust
Copy link
Member

breathingdust commented Apr 24, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

To ensure test configurations are region and partition agnostic, any hardcoded AMI identifiers (ami-[a-f0-9]{8,17}) should be replaced with the aws_ami data source.

This check was added in #14031 and is AWSAT002. We'll keep this issue open while fixes are made that are identified by the check.

Flagged Code

In test configuration:

ami-123456

Passing Code

In test configuration:

data "aws_ami" "example" {
  # ... configuration ...
}

To Do

@breathingdust breathingdust added technical-debt Addresses areas of the codebase that need refactoring or redesign. provider Pertains to the provider itself, rather than any interaction with AWS. labels Apr 24, 2020
@ghost ghost added the service/ec2 Issues and PRs that pertain to the ec2 service. label Apr 24, 2020
@ewbankkit
Copy link
Contributor

There are some configuration generator functions available for common AMIs:

https://github.com/terraform-providers/terraform-provider-aws/blob/dcb00966d9ec8383883ad62750cb2455fedd96f9/aws/resource_aws_instance_test.go#L4379-L4440

@bflad
Copy link
Contributor

bflad commented Sep 8, 2020

@YakDriver this looks really close to complete, do you think we could get this turned on this week?

$ awsproviderlint -AWSAT002 ./aws
/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_instance_test.go:3836:46: AWSAT002: AMI IDs should not be hardcoded
/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_instance_test.go:4308:53: AWSAT002: AMI IDs should not be hardcoded
/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/validators_test.go:1182:14: AWSAT002: AMI IDs should not be hardcoded

@YakDriver
Copy link
Member

@bflad validators_test is ready for review #15142. 2 of the 3 instance tests are easy but the other is an AMI in us-west-2 with RootDeviceName: /dev/sda1; but actual root: /dev/sda (ami-ef5b69df). I'll need more investigation into how/why such an AMI exists.

@bflad
Copy link
Contributor

bflad commented Sep 14, 2020

@YakDriver I feel like there may have been one very special instance test that was setup to cover a very specific regression due to the block setup of a specific AMI, which might be that one -- if I'm remembering that correctly (or git blame can verify), then that one test can be setup to run just in us-west-2 and ignored in the linter since trying to find other similar AMIs is likely more work than benefit. 👍

@YakDriver
Copy link
Member

YakDriver commented Sep 14, 2020

@bflad The exciting #15143 PR fixes:

  1. ignore the specific regression (TestAccAWSInstance_rootBlockDeviceMismatch),
  2. reworked the other test for either partition (TestAccAWSInstance_multipleRegions),
  3. removed testAccPartitionPreCheck() since this is the only place it was used (deadcode lint), and
  4. enabled AWSAT002

@ghost
Copy link

ghost commented Oct 16, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2020
@breathingdust breathingdust added the linter Pertains to changes to or issues with the various linters. label Oct 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linter Pertains to changes to or issues with the various linters. partition/aws-us-gov Pertains to the aws-us-gov partition. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. technical-debt Addresses areas of the codebase that need refactoring or redesign.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants