provider/aws: don't set static ELB names in tests

Prevents ELB name collisions during test runs
This commit is contained in:
Paul Hinze 2015-12-21 17:41:55 -06:00
parent eb13baf96f
commit f473c2a6d4
3 changed files with 12 additions and 52 deletions

View File

@ -161,7 +161,7 @@ func TestAccAWSAutoScalingGroup_WithLoadBalancer(t *testing.T) {
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy, CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAWSAutoScalingGroupConfigWithLoadBalancer, Config: fmt.Sprintf(testAccAWSAutoScalingGroupConfigWithLoadBalancer),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group), testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(&group), testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(&group),
@ -280,8 +280,8 @@ func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.Group) resourc
func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.Group) resource.TestCheckFunc { func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.Group) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
if *group.LoadBalancerNames[0] != "foobar-terraform-test" { if len(group.LoadBalancerNames) != 1 {
return fmt.Errorf("Bad load_balancers: %#v", group.LoadBalancerNames[0]) return fmt.Errorf("Bad load_balancers: %v", group.LoadBalancerNames)
} }
return nil return nil
@ -513,7 +513,6 @@ resource "aws_security_group" "foo" {
} }
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
subnets = ["${aws_subnet.foo.id}"] subnets = ["${aws_subnet.foo.id}"]
security_groups = ["${aws_security_group.foo.id}"] security_groups = ["${aws_security_group.foo.id}"]

View File

@ -356,7 +356,6 @@ EOF
} }
resource "aws_elb" "main" { resource "aws_elb" "main" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {

View File

@ -2,11 +2,12 @@ package aws
import ( import (
"fmt" "fmt"
"os" "math/rand"
"reflect" "reflect"
"regexp" "regexp"
"sort" "sort"
"testing" "testing"
"time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
@ -17,7 +18,6 @@ import (
func TestAccAWSELB_basic(t *testing.T) { func TestAccAWSELB_basic(t *testing.T) {
var conf elb.LoadBalancerDescription var conf elb.LoadBalancerDescription
ssl_certificate_id := os.Getenv("AWS_SSL_CERTIFICATE_ID")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -29,8 +29,6 @@ func TestAccAWSELB_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBExists("aws_elb.bar", &conf),
testAccCheckAWSELBAttributes(&conf), testAccCheckAWSELBAttributes(&conf),
resource.TestCheckResourceAttr(
"aws_elb.bar", "name", "foobar-terraform-test"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.2487133097", "us-west-2a"), "aws_elb.bar", "availability_zones.2487133097", "us-west-2a"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -41,8 +39,6 @@ func TestAccAWSELB_basic(t *testing.T) {
"aws_elb.bar", "listener.206423021.instance_port", "8000"), "aws_elb.bar", "listener.206423021.instance_port", "8000"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "listener.206423021.instance_protocol", "http"), "aws_elb.bar", "listener.206423021.instance_protocol", "http"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "listener.206423021.ssl_certificate_id", ssl_certificate_id),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.bar", "listener.206423021.lb_port", "80"), "aws_elb.bar", "listener.206423021.lb_port", "80"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -58,17 +54,20 @@ func TestAccAWSELB_basic(t *testing.T) {
func TestAccAWSELB_fullCharacterRange(t *testing.T) { func TestAccAWSELB_fullCharacterRange(t *testing.T) {
var conf elb.LoadBalancerDescription var conf elb.LoadBalancerDescription
lbName := fmt.Sprintf("FoobarTerraform-test123-%d",
rand.New(rand.NewSource(time.Now().UnixNano())).Int())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSELBDestroy, CheckDestroy: testAccCheckAWSELBDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAWSELBFullRangeOfCharacters, Config: fmt.Sprintf(testAccAWSELBFullRangeOfCharacters, lbName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.foo", &conf), testAccCheckAWSELBExists("aws_elb.foo", &conf),
resource.TestCheckResourceAttr( 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, Config: testAccAWSELBAccessLogs,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.foo", &conf), 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, Config: testAccAWSELBAccessLogsOn,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.foo", &conf), testAccCheckAWSELBExists("aws_elb.foo", &conf),
resource.TestCheckResourceAttr(
"aws_elb.foo", "name", "FoobarTerraform-test123"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.foo", "access_logs.#", "1"), "aws_elb.foo", "access_logs.#", "1"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -111,8 +106,6 @@ func TestAccAWSELB_AccessLogs(t *testing.T) {
Config: testAccAWSELBAccessLogs, Config: testAccAWSELBAccessLogs,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.foo", &conf), testAccCheckAWSELBExists("aws_elb.foo", &conf),
resource.TestCheckResourceAttr(
"aws_elb.foo", "name", "FoobarTerraform-test123"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_elb.foo", "access_logs.#", "0"), "aws_elb.foo", "access_logs.#", "0"),
), ),
@ -156,8 +149,6 @@ func TestAccAWSELB_tags(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBExists("aws_elb.bar", &conf),
testAccCheckAWSELBAttributes(&conf), testAccCheckAWSELBAttributes(&conf),
resource.TestCheckResourceAttr(
"aws_elb.bar", "name", "foobar-terraform-test"),
testAccLoadTags(&conf, &td), testAccLoadTags(&conf, &td),
testAccCheckELBTags(&td.Tags, "bar", "baz"), testAccCheckELBTags(&td.Tags, "bar", "baz"),
), ),
@ -168,8 +159,6 @@ func TestAccAWSELB_tags(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.bar", &conf), testAccCheckAWSELBExists("aws_elb.bar", &conf),
testAccCheckAWSELBAttributes(&conf), testAccCheckAWSELBAttributes(&conf),
resource.TestCheckResourceAttr(
"aws_elb.bar", "name", "foobar-terraform-test"),
testAccLoadTags(&conf, &td), testAccLoadTags(&conf, &td),
testAccCheckELBTags(&td.Tags, "foo", "bar"), testAccCheckELBTags(&td.Tags, "foo", "bar"),
testAccCheckELBTags(&td.Tags, "new", "type"), testAccCheckELBTags(&td.Tags, "new", "type"),
@ -591,10 +580,6 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te
return fmt.Errorf("bad availability_zones") return fmt.Errorf("bad availability_zones")
} }
if *conf.LoadBalancerName != "foobar-terraform-test" {
return fmt.Errorf("bad name")
}
l := elb.Listener{ l := elb.Listener{
InstancePort: aws.Int64(int64(8000)), InstancePort: aws.Int64(int64(8000)),
InstanceProtocol: aws.String("HTTP"), InstanceProtocol: aws.String("HTTP"),
@ -629,10 +614,6 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription)
return fmt.Errorf("bad availability_zones") return fmt.Errorf("bad availability_zones")
} }
if *conf.LoadBalancerName != "foobar-terraform-test" {
return fmt.Errorf("bad name")
}
check := &elb.HealthCheck{ check := &elb.HealthCheck{
Timeout: aws.Int64(int64(30)), Timeout: aws.Int64(int64(30)),
UnhealthyThreshold: aws.Int64(int64(5)), UnhealthyThreshold: aws.Int64(int64(5)),
@ -699,7 +680,6 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resour
const testAccAWSELBConfig = ` const testAccAWSELBConfig = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -720,7 +700,7 @@ resource "aws_elb" "bar" {
const testAccAWSELBFullRangeOfCharacters = ` const testAccAWSELBFullRangeOfCharacters = `
resource "aws_elb" "foo" { resource "aws_elb" "foo" {
name = "FoobarTerraform-test123" name = "%s"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -734,7 +714,6 @@ resource "aws_elb" "foo" {
const testAccAWSELBAccessLogs = ` const testAccAWSELBAccessLogs = `
resource "aws_elb" "foo" { resource "aws_elb" "foo" {
name = "FoobarTerraform-test123"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -773,7 +752,6 @@ EOF
} }
resource "aws_elb" "foo" { resource "aws_elb" "foo" {
name = "FoobarTerraform-test123"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -805,7 +783,6 @@ resource "aws_elb" "foo" {
const testAccAWSELBConfig_TagUpdate = ` const testAccAWSELBConfig_TagUpdate = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -826,7 +803,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigNewInstance = ` const testAccAWSELBConfigNewInstance = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -848,7 +824,6 @@ resource "aws_instance" "foo" {
const testAccAWSELBConfigListenerSSLCertificateId = ` const testAccAWSELBConfigListenerSSLCertificateId = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -863,7 +838,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigHealthCheck = ` const testAccAWSELBConfigHealthCheck = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -885,7 +859,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigHealthCheck_update = ` const testAccAWSELBConfigHealthCheck_update = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -907,7 +880,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigListener_update = ` const testAccAWSELBConfigListener_update = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -921,7 +893,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigIdleTimeout = ` const testAccAWSELBConfigIdleTimeout = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -937,7 +908,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigIdleTimeout_update = ` const testAccAWSELBConfigIdleTimeout_update = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -953,7 +923,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigConnectionDraining = ` const testAccAWSELBConfigConnectionDraining = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -970,7 +939,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigConnectionDraining_update_timeout = ` const testAccAWSELBConfigConnectionDraining_update_timeout = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -987,7 +955,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigConnectionDraining_update_disable = ` const testAccAWSELBConfigConnectionDraining_update_disable = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a"] availability_zones = ["us-west-2a"]
listener { listener {
@ -1003,7 +970,6 @@ resource "aws_elb" "bar" {
const testAccAWSELBConfigSecurityGroups = ` const testAccAWSELBConfigSecurityGroups = `
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {
@ -1017,9 +983,6 @@ resource "aws_elb" "bar" {
} }
resource "aws_security_group" "bar" { resource "aws_security_group" "bar" {
name = "terraform-elb-acceptance-test"
description = "Used in the terraform acceptance tests for the elb resource"
ingress { ingress {
protocol = "tcp" protocol = "tcp"
from_port = 80 from_port = 80
@ -1033,7 +996,7 @@ resource "aws_security_group" "bar" {
// builtin/providers/aws/resource_aws_iam_server_certificate_test.go // builtin/providers/aws/resource_aws_iam_server_certificate_test.go
var testAccELBIAMServerCertConfig = ` var testAccELBIAMServerCertConfig = `
resource "aws_iam_server_certificate" "test_cert" { resource "aws_iam_server_certificate" "test_cert" {
name = "terraform-test-cert" name = "terraform-test-cert-elb"
certificate_body = <<EOF certificate_body = <<EOF
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIDCDCCAfACAQEwDQYJKoZIhvcNAQELBQAwgY4xCzAJBgNVBAYTAlVTMREwDwYD MIIDCDCCAfACAQEwDQYJKoZIhvcNAQELBQAwgY4xCzAJBgNVBAYTAlVTMREwDwYD
@ -1103,7 +1066,6 @@ EOF
} }
resource "aws_elb" "bar" { resource "aws_elb" "bar" {
name = "foobar-terraform-test"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
listener { listener {