From 2d045a330218dabc962d1256ec67b32598c815e9 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Fri, 3 Mar 2017 11:18:30 -0600 Subject: [PATCH] provider/aws: Update Autoscaling attachment test --- ...esource_aws_autoscaling_attachment_test.go | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_attachment_test.go b/builtin/providers/aws/resource_aws_autoscaling_attachment_test.go index c9eb2c951d..cf1a239e3b 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_attachment_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_attachment_test.go @@ -6,45 +6,49 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/autoscaling" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAwsAutoscalingAttachment_basic(t *testing.T) { + + rInt := acctest.RandInt() + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSAutoscalingAttachment_basic, + Config: testAccAWSAutoscalingAttachment_basic(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0), ), }, // Add in one association resource.TestStep{ - Config: testAccAWSAutoscalingAttachment_associated, + Config: testAccAWSAutoscalingAttachment_associated(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1), ), }, // Test adding a 2nd resource.TestStep{ - Config: testAccAWSAutoscalingAttachment_double_associated, + Config: testAccAWSAutoscalingAttachment_double_associated(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 2), ), }, // Now remove that newest one resource.TestStep{ - Config: testAccAWSAutoscalingAttachment_associated, + Config: testAccAWSAutoscalingAttachment_associated(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1), ), }, // Now remove them both resource.TestStep{ - Config: testAccAWSAutoscalingAttachment_basic, + Config: testAccAWSAutoscalingAttachment_basic(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0), ), @@ -79,7 +83,8 @@ func testAccCheckAWSAutocalingAttachmentExists(asgname string, loadBalancerCount } } -const testAccAWSAutoscalingAttachment_basic = ` +func testAccAWSAutoscalingAttachment_basic(rInt int) string { + return fmt.Sprintf(` resource "aws_elb" "foo" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] @@ -103,14 +108,14 @@ resource "aws_elb" "bar" { } resource "aws_launch_configuration" "as_conf" { - name = "test_config" + name = "test_config_%d" image_id = "ami-f34032c3" instance_type = "t1.micro" } resource "aws_autoscaling_group" "asg" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] - name = "asg-lb-assoc-terraform-test" + name = "asg-lb-assoc-terraform-test_%d" max_size = 1 min_size = 0 desired_capacity = 0 @@ -123,22 +128,21 @@ resource "aws_autoscaling_group" "asg" { value = "terraform-asg-lg-assoc-test" propagate_at_launch = true } +}`, rInt, rInt) } -` - -const testAccAWSAutoscalingAttachment_associated = testAccAWSAutoscalingAttachment_basic + ` +func testAccAWSAutoscalingAttachment_associated(rInt int) string { + return testAccAWSAutoscalingAttachment_basic(rInt) + ` resource "aws_autoscaling_attachment" "asg_attachment_foo" { autoscaling_group_name = "${aws_autoscaling_group.asg.id}" elb = "${aws_elb.foo.id}" +}` } -` - -const testAccAWSAutoscalingAttachment_double_associated = testAccAWSAutoscalingAttachment_associated + ` +func testAccAWSAutoscalingAttachment_double_associated(rInt int) string { + return testAccAWSAutoscalingAttachment_associated(rInt) + ` resource "aws_autoscaling_attachment" "asg_attachment_bar" { autoscaling_group_name = "${aws_autoscaling_group.asg.id}" elb = "${aws_elb.bar.id}" +}` } - -`