From 8e5f0cbf23a87ef701086a568b26afd83797e5a6 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 10 Jul 2020 18:26:19 -0400 Subject: [PATCH] Removed hardcoded AMI IDs from AutoscalingAttachment --- ...esource_aws_autoscaling_attachment_test.go | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_autoscaling_attachment_test.go b/aws/resource_aws_autoscaling_attachment_test.go index 7046b47b126..ce4888f0b69 100644 --- a/aws/resource_aws_autoscaling_attachment_test.go +++ b/aws/resource_aws_autoscaling_attachment_test.go @@ -176,7 +176,16 @@ func testAccCheckAWSAutocalingAlbAttachmentExists(asgname string, targetGroupCou } func testAccAWSAutoscalingAttachment_alb(rInt int) string { - return fmt.Sprintf(` + return testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(` +data "aws_availability_zones" "available" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} + resource "aws_lb_target_group" "test" { name = "test-alb-%d" port = 443 @@ -236,7 +245,7 @@ resource "aws_lb_target_group" "another_test" { } resource "aws_autoscaling_group" "asg" { - availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] + availability_zones = data.aws_availability_zones.available.names name = "asg-lb-assoc-terraform-test_%d" max_size = 1 min_size = 0 @@ -254,7 +263,7 @@ resource "aws_autoscaling_group" "asg" { resource "aws_launch_configuration" "as_conf" { name = "test_config_%d" - image_id = "ami-f34032c3" + image_id = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t1.micro" } @@ -269,9 +278,18 @@ resource "aws_vpc" "test" { } func testAccAWSAutoscalingAttachment_elb(rInt int) string { - return fmt.Sprintf(` + return testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(` +data "aws_availability_zones" "available" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} + resource "aws_elb" "foo" { - availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] + availability_zones = data.aws_availability_zones.available.names listener { instance_port = 8000 @@ -282,7 +300,7 @@ resource "aws_elb" "foo" { } resource "aws_elb" "bar" { - availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] + availability_zones = data.aws_availability_zones.available.names listener { instance_port = 8000 @@ -294,12 +312,12 @@ resource "aws_elb" "bar" { resource "aws_launch_configuration" "as_conf" { name = "test_config_%d" - image_id = "ami-f34032c3" + image_id = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t1.micro" } resource "aws_autoscaling_group" "asg" { - availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] + availability_zones = data.aws_availability_zones.available.names name = "asg-lb-assoc-terraform-test_%d" max_size = 1 min_size = 0