diff --git a/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy_test.go b/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy_test.go index d1fd59f69..f05952ec8 100644 --- a/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy_test.go +++ b/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy_test.go @@ -8,18 +8,20 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elb" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSAppCookieStickinessPolicy_basic(t *testing.T) { + lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAppCookieStickinessPolicyDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAppCookieStickinessPolicyConfig, + Config: testAccAppCookieStickinessPolicyConfig(lbName), Check: resource.ComposeTestCheckFunc( testAccCheckAppCookieStickinessPolicy( "aws_elb.lb", @@ -28,7 +30,7 @@ func TestAccAWSAppCookieStickinessPolicy_basic(t *testing.T) { ), }, resource.TestStep{ - Config: testAccAppCookieStickinessPolicyConfigUpdate, + Config: testAccAppCookieStickinessPolicyConfigUpdate(lbName), Check: resource.ComposeTestCheckFunc( testAccCheckAppCookieStickinessPolicy( "aws_elb.lb", @@ -100,9 +102,10 @@ func testAccCheckAppCookieStickinessPolicy(elbResource string, policyResource st } } -const testAccAppCookieStickinessPolicyConfig = ` +func testAccAppCookieStickinessPolicyConfig(rName string) string { + return fmt.Sprintf(` resource "aws_elb" "lb" { - name = "test-lb" + name = "%s" availability_zones = ["us-west-2a"] listener { instance_port = 8000 @@ -117,13 +120,14 @@ resource "aws_app_cookie_stickiness_policy" "foo" { load_balancer = "${aws_elb.lb.id}" lb_port = 80 cookie_name = "MyAppCookie" +}`, rName) } -` // Change the cookie_name to "MyOtherAppCookie". -const testAccAppCookieStickinessPolicyConfigUpdate = ` +func testAccAppCookieStickinessPolicyConfigUpdate(rName string) string { + return fmt.Sprintf(` resource "aws_elb" "lb" { - name = "test-lb" + name = "%s" availability_zones = ["us-west-2a"] listener { instance_port = 8000 @@ -138,5 +142,5 @@ resource "aws_app_cookie_stickiness_policy" "foo" { load_balancer = "${aws_elb.lb.id}" lb_port = 80 cookie_name = "MyOtherAppCookie" +}`, rName) } -` diff --git a/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy_test.go b/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy_test.go index 7337432e4..088848a13 100644 --- a/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy_test.go +++ b/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy_test.go @@ -8,18 +8,20 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elb" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) { + lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLBCookieStickinessPolicyDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccLBCookieStickinessPolicyConfig, + Config: testAccLBCookieStickinessPolicyConfig(lbName), Check: resource.ComposeTestCheckFunc( testAccCheckLBCookieStickinessPolicy( "aws_elb.lb", @@ -28,7 +30,7 @@ func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) { ), }, resource.TestStep{ - Config: testAccLBCookieStickinessPolicyConfigUpdate, + Config: testAccLBCookieStickinessPolicyConfigUpdate(lbName), Check: resource.ComposeTestCheckFunc( testAccCheckLBCookieStickinessPolicy( "aws_elb.lb", @@ -100,9 +102,10 @@ func testAccCheckLBCookieStickinessPolicy(elbResource string, policyResource str } } -const testAccLBCookieStickinessPolicyConfig = ` +func testAccLBCookieStickinessPolicyConfig(rName string) string { + return fmt.Sprintf(` resource "aws_elb" "lb" { - name = "test-lb" + name = "%s" availability_zones = ["us-west-2a"] listener { instance_port = 8000 @@ -116,13 +119,14 @@ resource "aws_lb_cookie_stickiness_policy" "foo" { name = "foo-policy" load_balancer = "${aws_elb.lb.id}" lb_port = 80 +}`, rName) } -` // Sets the cookie_expiration_period to 300s. -const testAccLBCookieStickinessPolicyConfigUpdate = ` +func testAccLBCookieStickinessPolicyConfigUpdate(rName string) string { + return fmt.Sprintf(` resource "aws_elb" "lb" { - name = "test-lb" + name = "%s" availability_zones = ["us-west-2a"] listener { instance_port = 8000 @@ -137,5 +141,5 @@ resource "aws_lb_cookie_stickiness_policy" "foo" { load_balancer = "${aws_elb.lb.id}" lb_port = 80 cookie_expiration_period = 300 +}`, rName) } -` diff --git a/builtin/providers/aws/resource_aws_proxy_protocol_policy_test.go b/builtin/providers/aws/resource_aws_proxy_protocol_policy_test.go index ff1cc7a7e..a1e36f7b7 100644 --- a/builtin/providers/aws/resource_aws_proxy_protocol_policy_test.go +++ b/builtin/providers/aws/resource_aws_proxy_protocol_policy_test.go @@ -6,21 +6,23 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elb" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSProxyProtocolPolicy_basic(t *testing.T) { + lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckProxyProtocolPolicyDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccProxyProtocolPolicyConfig, + Config: testAccProxyProtocolPolicyConfig(lbName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "aws_proxy_protocol_policy.smtp", "load_balancer", "test-lb"), + "aws_proxy_protocol_policy.smtp", "load_balancer", lbName), resource.TestCheckResourceAttr( "aws_proxy_protocol_policy.smtp", "instance_ports.#", "1"), resource.TestCheckResourceAttr( @@ -28,10 +30,10 @@ func TestAccAWSProxyProtocolPolicy_basic(t *testing.T) { ), }, resource.TestStep{ - Config: testAccProxyProtocolPolicyConfigUpdate, + Config: testAccProxyProtocolPolicyConfigUpdate(lbName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "aws_proxy_protocol_policy.smtp", "load_balancer", "test-lb"), + "aws_proxy_protocol_policy.smtp", "load_balancer", lbName), resource.TestCheckResourceAttr( "aws_proxy_protocol_policy.smtp", "instance_ports.#", "2"), resource.TestCheckResourceAttr( @@ -70,9 +72,10 @@ func testAccCheckProxyProtocolPolicyDestroy(s *terraform.State) error { return nil } -const testAccProxyProtocolPolicyConfig = ` +func testAccProxyProtocolPolicyConfig(rName string) string { + return fmt.Sprintf(` resource "aws_elb" "lb" { - name = "test-lb" + name = "%s" availability_zones = ["us-west-2a"] listener { @@ -93,12 +96,13 @@ resource "aws_elb" "lb" { resource "aws_proxy_protocol_policy" "smtp" { load_balancer = "${aws_elb.lb.name}" instance_ports = ["25"] +}`, rName) } -` -const testAccProxyProtocolPolicyConfigUpdate = ` +func testAccProxyProtocolPolicyConfigUpdate(rName string) string { + return fmt.Sprintf(` resource "aws_elb" "lb" { - name = "test-lb" + name = "%s" availability_zones = ["us-west-2a"] listener { @@ -119,5 +123,5 @@ resource "aws_elb" "lb" { resource "aws_proxy_protocol_policy" "smtp" { load_balancer = "${aws_elb.lb.name}" instance_ports = ["25", "587"] +}`, rName) } -`