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

Linter: Add acceptance test hardcoded instance type lint #23101

Closed
YakDriver opened this issue Feb 10, 2022 · 2 comments
Closed

Linter: Add acceptance test hardcoded instance type lint #23101

YakDriver opened this issue Feb 10, 2022 · 2 comments
Labels
linter Pertains to changes to or issues with the various linters. service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@YakDriver
Copy link
Member

YakDriver commented Feb 10, 2022

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

Hardcoding instance types in tests often leads to failed tests due to lack of availability of a given type in either GovCloud/AWS Commercial. This should be doable with semgrep.

This is good (for instance types) and should pass:

func testAccSpotInstanceRequestConfig(rInt int) string {
	return acctest.ConfigCompose(
		acctest.AvailableEC2InstanceTypeForRegion("t3.micro", "t2.micro"),
		fmt.Sprintf(`
resource "aws_spot_instance_request" "test" {
  instance_type        = data.aws_ec2_instance_type_offering.available.instance_type
  spot_price           = "0.05"
  wait_for_fulfillment = true
}
`, rInt))
}

This is good (for instance types) and should pass:

data "aws_rds_orderable_db_instance" "test" {
  engine                     = "mysql"
  engine_version             = "5.7.31"
  preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t3.small"]
}

resource "aws_db_instance" "test" {
  engine              = data.aws_rds_orderable_db_instance.test.engine
  engine_version      = data.aws_rds_orderable_db_instance.test.engine_version
  instance_class      = data.aws_rds_orderable_db_instance.test.instance_class
  skip_final_snapshot = true
  username            = "test"
}

This is bad and should fail linting:

func testAccSpotInstanceRequestConfig(rInt int) string {
	return `
resource "aws_spot_instance_request" "test" {
  instance_type        = "t2.micro"
  spot_price           = "0.05"
  wait_for_fulfillment = true
}
`
}

This is also bad and should fail linting:

resource "aws_db_instance" "test" {
  engine              = "mysql"
  engine_version      = "5.7.31"
  instance_class      = "db.t3.micro"
  skip_final_snapshot = true
  username            = "test"
}

References

@YakDriver YakDriver added the enhancement Requests to existing resources that expand the functionality or scope. label Feb 10, 2022
@github-actions github-actions bot added service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. labels Feb 10, 2022
@YakDriver YakDriver changed the title Add acceptance test hardcoded instance type lint Linter: Add acceptance test hardcoded instance type lint Feb 10, 2022
@ewbankkit ewbankkit added linter Pertains to changes to or issues with the various linters. and removed enhancement Requests to existing resources that expand the functionality or scope. labels Feb 10, 2022
Copy link

github-actions bot commented Feb 1, 2024

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Feb 1, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2024
Copy link

github-actions bot commented Apr 2, 2024

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 have found a problem that seems similar to this, 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 2, 2024
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. service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

2 participants