Back to Terraform Provider Aws

AWSAT002

.ci/providerlint/passes/AWSAT002/README.md

6.43.01.4 KB
Original Source
<!-- Copyright IBM Corp. 2014, 2026 --> <!-- SPDX-License-Identifier: MPL-2.0 -->

AWSAT002

The AWSAT002 analyzer reports hardcoded AMI IDs. AMI IDs are region dependent and tests will fail in any region or partition other than where the AMI was created.

Flagged Code

go
func testAccEC2SpotFleetRequestConfig(rName string, rInt int, validUntil string) string {
	return testAccEC2SpotFleetRequestConfigBase(rName, rInt) + fmt.Sprintf(`
resource "aws_spot_fleet_request" "test" {
    launch_specification {
        instance_type = "m1.small"
        ami = "ami-516b9131"
    }
}
`, validUntil)
}

Passing Code

go
func testAccEC2SpotFleetRequestConfig(rName string, rInt int, validUntil string) string {
    return testAccEC2SpotFleetRequestConfigBase(rName, rInt) + fmt.Sprintf(`
data "aws_ami" "amzn-ami-minimal-hvm-ebs" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn-ami-minimal-hvm-*"]
  }

  filter {
    name   = "root-device-type"
    values = ["ebs"]
  }
}

resource "aws_spot_fleet_request" "test" {
    launch_specification {
        instance_type = "m1.small"
        ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
    }
}
`, validUntil)
}

Ignoring Reports

Singular reports can be ignored by adding the a //lintignore:AWSAT002 Go code comment at the end of the offending line or on the line immediately proceding, e.g.

go
ami = "ami-516b9131" //lintignore:AWSAT002