From f473c2a6d42a12de5bf41ca1f99b3668b8a84a54 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 21 Dec 2015 17:41:55 -0600 Subject: [PATCH] provider/aws: don't set static ELB names in tests Prevents ELB name collisions during test runs --- .../resource_aws_autoscaling_group_test.go | 7 +-- .../aws/resource_aws_ecs_service_test.go | 1 - .../providers/aws/resource_aws_elb_test.go | 56 +++---------------- 3 files changed, 12 insertions(+), 52 deletions(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index d9268f692..8c2b934f3 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -161,7 +161,7 @@ func TestAccAWSAutoScalingGroup_WithLoadBalancer(t *testing.T) { CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSAutoScalingGroupConfigWithLoadBalancer, + Config: fmt.Sprintf(testAccAWSAutoScalingGroupConfigWithLoadBalancer), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group), testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(&group), @@ -280,8 +280,8 @@ func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.Group) resourc func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.Group) resource.TestCheckFunc { return func(s *terraform.State) error { - if *group.LoadBalancerNames[0] != "foobar-terraform-test" { - return fmt.Errorf("Bad load_balancers: %#v", group.LoadBalancerNames[0]) + if len(group.LoadBalancerNames) != 1 { + return fmt.Errorf("Bad load_balancers: %v", group.LoadBalancerNames) } return nil @@ -513,7 +513,6 @@ resource "aws_security_group" "foo" { } resource "aws_elb" "bar" { - name = "foobar-terraform-test" subnets = ["${aws_subnet.foo.id}"] security_groups = ["${aws_security_group.foo.id}"] diff --git a/builtin/providers/aws/resource_aws_ecs_service_test.go b/builtin/providers/aws/resource_aws_ecs_service_test.go index a2f71ad2f..c77f87435 100644 --- a/builtin/providers/aws/resource_aws_ecs_service_test.go +++ b/builtin/providers/aws/resource_aws_ecs_service_test.go @@ -356,7 +356,6 @@ EOF } resource "aws_elb" "main" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { diff --git a/builtin/providers/aws/resource_aws_elb_test.go b/builtin/providers/aws/resource_aws_elb_test.go index 6ccc5cd66..15f40b6d9 100644 --- a/builtin/providers/aws/resource_aws_elb_test.go +++ b/builtin/providers/aws/resource_aws_elb_test.go @@ -2,11 +2,12 @@ package aws import ( "fmt" - "os" + "math/rand" "reflect" "regexp" "sort" "testing" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -17,7 +18,6 @@ import ( func TestAccAWSELB_basic(t *testing.T) { var conf elb.LoadBalancerDescription - ssl_certificate_id := os.Getenv("AWS_SSL_CERTIFICATE_ID") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -29,8 +29,6 @@ func TestAccAWSELB_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBAttributes(&conf), - resource.TestCheckResourceAttr( - "aws_elb.bar", "name", "foobar-terraform-test"), resource.TestCheckResourceAttr( "aws_elb.bar", "availability_zones.2487133097", "us-west-2a"), resource.TestCheckResourceAttr( @@ -41,8 +39,6 @@ func TestAccAWSELB_basic(t *testing.T) { "aws_elb.bar", "listener.206423021.instance_port", "8000"), resource.TestCheckResourceAttr( "aws_elb.bar", "listener.206423021.instance_protocol", "http"), - resource.TestCheckResourceAttr( - "aws_elb.bar", "listener.206423021.ssl_certificate_id", ssl_certificate_id), resource.TestCheckResourceAttr( "aws_elb.bar", "listener.206423021.lb_port", "80"), resource.TestCheckResourceAttr( @@ -58,17 +54,20 @@ func TestAccAWSELB_basic(t *testing.T) { func TestAccAWSELB_fullCharacterRange(t *testing.T) { var conf elb.LoadBalancerDescription + lbName := fmt.Sprintf("FoobarTerraform-test123-%d", + rand.New(rand.NewSource(time.Now().UnixNano())).Int()) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSELBDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSELBFullRangeOfCharacters, + Config: fmt.Sprintf(testAccAWSELBFullRangeOfCharacters, lbName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.foo", &conf), resource.TestCheckResourceAttr( - "aws_elb.foo", "name", "FoobarTerraform-test123"), + "aws_elb.foo", "name", lbName), ), }, }, @@ -87,8 +86,6 @@ func TestAccAWSELB_AccessLogs(t *testing.T) { Config: testAccAWSELBAccessLogs, Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.foo", &conf), - resource.TestCheckResourceAttr( - "aws_elb.foo", "name", "FoobarTerraform-test123"), ), }, @@ -96,8 +93,6 @@ func TestAccAWSELB_AccessLogs(t *testing.T) { Config: testAccAWSELBAccessLogsOn, Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.foo", &conf), - resource.TestCheckResourceAttr( - "aws_elb.foo", "name", "FoobarTerraform-test123"), resource.TestCheckResourceAttr( "aws_elb.foo", "access_logs.#", "1"), resource.TestCheckResourceAttr( @@ -111,8 +106,6 @@ func TestAccAWSELB_AccessLogs(t *testing.T) { Config: testAccAWSELBAccessLogs, Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.foo", &conf), - resource.TestCheckResourceAttr( - "aws_elb.foo", "name", "FoobarTerraform-test123"), resource.TestCheckResourceAttr( "aws_elb.foo", "access_logs.#", "0"), ), @@ -156,8 +149,6 @@ func TestAccAWSELB_tags(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBAttributes(&conf), - resource.TestCheckResourceAttr( - "aws_elb.bar", "name", "foobar-terraform-test"), testAccLoadTags(&conf, &td), testAccCheckELBTags(&td.Tags, "bar", "baz"), ), @@ -168,8 +159,6 @@ func TestAccAWSELB_tags(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBAttributes(&conf), - resource.TestCheckResourceAttr( - "aws_elb.bar", "name", "foobar-terraform-test"), testAccLoadTags(&conf, &td), testAccCheckELBTags(&td.Tags, "foo", "bar"), testAccCheckELBTags(&td.Tags, "new", "type"), @@ -591,10 +580,6 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te return fmt.Errorf("bad availability_zones") } - if *conf.LoadBalancerName != "foobar-terraform-test" { - return fmt.Errorf("bad name") - } - l := elb.Listener{ InstancePort: aws.Int64(int64(8000)), InstanceProtocol: aws.String("HTTP"), @@ -629,10 +614,6 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) return fmt.Errorf("bad availability_zones") } - if *conf.LoadBalancerName != "foobar-terraform-test" { - return fmt.Errorf("bad name") - } - check := &elb.HealthCheck{ Timeout: aws.Int64(int64(30)), UnhealthyThreshold: aws.Int64(int64(5)), @@ -699,7 +680,6 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resour const testAccAWSELBConfig = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -720,7 +700,7 @@ resource "aws_elb" "bar" { const testAccAWSELBFullRangeOfCharacters = ` resource "aws_elb" "foo" { - name = "FoobarTerraform-test123" + name = "%s" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -734,7 +714,6 @@ resource "aws_elb" "foo" { const testAccAWSELBAccessLogs = ` resource "aws_elb" "foo" { - name = "FoobarTerraform-test123" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -773,7 +752,6 @@ EOF } resource "aws_elb" "foo" { - name = "FoobarTerraform-test123" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -805,7 +783,6 @@ resource "aws_elb" "foo" { const testAccAWSELBConfig_TagUpdate = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -826,7 +803,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigNewInstance = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -848,7 +824,6 @@ resource "aws_instance" "foo" { const testAccAWSELBConfigListenerSSLCertificateId = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -863,7 +838,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigHealthCheck = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -885,7 +859,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigHealthCheck_update = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -907,7 +880,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigListener_update = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -921,7 +893,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigIdleTimeout = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -937,7 +908,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigIdleTimeout_update = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -953,7 +923,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigConnectionDraining = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -970,7 +939,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigConnectionDraining_update_timeout = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -987,7 +955,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigConnectionDraining_update_disable = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a"] listener { @@ -1003,7 +970,6 @@ resource "aws_elb" "bar" { const testAccAWSELBConfigSecurityGroups = ` resource "aws_elb" "bar" { - name = "foobar-terraform-test" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] listener { @@ -1017,9 +983,6 @@ resource "aws_elb" "bar" { } resource "aws_security_group" "bar" { - name = "terraform-elb-acceptance-test" - description = "Used in the terraform acceptance tests for the elb resource" - ingress { protocol = "tcp" from_port = 80 @@ -1033,7 +996,7 @@ resource "aws_security_group" "bar" { // builtin/providers/aws/resource_aws_iam_server_certificate_test.go var testAccELBIAMServerCertConfig = ` resource "aws_iam_server_certificate" "test_cert" { - name = "terraform-test-cert" + name = "terraform-test-cert-elb" certificate_body = <