Merge pull request #11825 from hashicorp/f-update-lb-policy-acctests

provider/aws: Update aws_elb policy acctests
This commit is contained in:
Jake Champlin 2017-02-09 10:16:20 -05:00 committed by GitHub
commit 9064954ca0
1 changed files with 101 additions and 95 deletions

View File

@ -10,18 +10,20 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccAWSLoadBalancerPolicy_basic(t *testing.T) { func TestAccAWSLoadBalancerPolicy_basic(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLoadBalancerPolicyDestroy, CheckDestroy: testAccCheckAWSLoadBalancerPolicyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSLoadBalancerPolicyConfig_basic, Config: testAccAWSLoadBalancerPolicyConfig_basic(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLoadBalancerPolicyState("aws_elb.test-lb", "aws_load_balancer_policy.test-policy"), testAccCheckAWSLoadBalancerPolicyState("aws_elb.test-lb", "aws_load_balancer_policy.test-policy"),
), ),
@ -31,19 +33,20 @@ func TestAccAWSLoadBalancerPolicy_basic(t *testing.T) {
} }
func TestAccAWSLoadBalancerPolicy_updateWhileAssigned(t *testing.T) { func TestAccAWSLoadBalancerPolicy_updateWhileAssigned(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLoadBalancerPolicyDestroy, CheckDestroy: testAccCheckAWSLoadBalancerPolicyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0, Config: testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLoadBalancerPolicyState("aws_elb.test-lb", "aws_load_balancer_policy.test-policy"), testAccCheckAWSLoadBalancerPolicyState("aws_elb.test-lb", "aws_load_balancer_policy.test-policy"),
), ),
}, },
resource.TestStep{ {
Config: testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1, Config: testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLoadBalancerPolicyState("aws_elb.test-lb", "aws_load_balancer_policy.test-policy"), testAccCheckAWSLoadBalancerPolicyState("aws_elb.test-lb", "aws_load_balancer_policy.test-policy"),
), ),
@ -139,102 +142,105 @@ func testAccCheckAWSLoadBalancerPolicyState(elbResource string, policyResource s
} }
} }
const testAccAWSLoadBalancerPolicyConfig_basic = ` func testAccAWSLoadBalancerPolicyConfig_basic(rInt int) string {
resource "aws_elb" "test-lb" { return fmt.Sprintf(`
name = "test-aws-policies-lb" resource "aws_elb" "test-lb" {
availability_zones = ["us-west-2a"] name = "test-lb-%d"
availability_zones = ["us-west-2a"]
listener { listener {
instance_port = 80 instance_port = 80
instance_protocol = "http" instance_protocol = "http"
lb_port = 80 lb_port = 80
lb_protocol = "http" lb_protocol = "http"
} }
tags { tags {
Name = "tf-acc-test" Name = "tf-acc-test"
} }
}
resource "aws_load_balancer_policy" "test-policy" {
load_balancer_name = "${aws_elb.test-lb.name}"
policy_name = "test-policy-%d"
policy_type_name = "AppCookieStickinessPolicyType"
policy_attribute = {
name = "CookieName"
value = "magic_cookie"
}
}`, rInt, rInt)
} }
resource "aws_load_balancer_policy" "test-policy" { func testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0(rInt int) string {
load_balancer_name = "${aws_elb.test-lb.name}" return fmt.Sprintf(`
policy_name = "test-policy-policy" resource "aws_elb" "test-lb" {
policy_type_name = "AppCookieStickinessPolicyType" name = "test-lb-%d"
policy_attribute = { availability_zones = ["us-west-2a"]
name = "CookieName"
value = "magic_cookie"
}
}
`
const testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0 = ` listener {
resource "aws_elb" "test-lb" { instance_port = 80
name = "test-aws-policies-lb" instance_protocol = "http"
availability_zones = ["us-west-2a"] lb_port = 80
lb_protocol = "http"
}
listener { tags {
instance_port = 80 Name = "tf-acc-test"
instance_protocol = "http" }
lb_port = 80 }
lb_protocol = "http"
}
tags { resource "aws_load_balancer_policy" "test-policy" {
Name = "tf-acc-test" load_balancer_name = "${aws_elb.test-lb.name}"
} policy_name = "test-policy-%d"
policy_type_name = "AppCookieStickinessPolicyType"
policy_attribute = {
name = "CookieName"
value = "magic_cookie"
}
}
resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
load_balancer_name = "${aws_elb.test-lb.name}"
load_balancer_port = 80
policy_names = [
"${aws_load_balancer_policy.test-policy.policy_name}"
]
}`, rInt, rInt)
} }
resource "aws_load_balancer_policy" "test-policy" { func testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1(rInt int) string {
load_balancer_name = "${aws_elb.test-lb.name}" return fmt.Sprintf(`
policy_name = "test-policy-policy" resource "aws_elb" "test-lb" {
policy_type_name = "AppCookieStickinessPolicyType" name = "test-lb-%d"
policy_attribute = { availability_zones = ["us-west-2a"]
name = "CookieName"
value = "magic_cookie" listener {
} instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
tags {
Name = "tf-acc-test"
}
}
resource "aws_load_balancer_policy" "test-policy" {
load_balancer_name = "${aws_elb.test-lb.name}"
policy_name = "test-policy-%d"
policy_type_name = "AppCookieStickinessPolicyType"
policy_attribute = {
name = "CookieName"
value = "unicorn_cookie"
}
}
resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
load_balancer_name = "${aws_elb.test-lb.name}"
load_balancer_port = 80
policy_names = [
"${aws_load_balancer_policy.test-policy.policy_name}"
]
}`, rInt, rInt)
} }
resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
load_balancer_name = "${aws_elb.test-lb.name}"
load_balancer_port = 80
policy_names = [
"${aws_load_balancer_policy.test-policy.policy_name}"
]
}
`
const testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1 = `
resource "aws_elb" "test-lb" {
name = "test-aws-policies-lb"
availability_zones = ["us-west-2a"]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
tags {
Name = "tf-acc-test"
}
}
resource "aws_load_balancer_policy" "test-policy" {
load_balancer_name = "${aws_elb.test-lb.name}"
policy_name = "test-policy-policy"
policy_type_name = "AppCookieStickinessPolicyType"
policy_attribute = {
name = "CookieName"
value = "unicorn_cookie"
}
}
resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
load_balancer_name = "${aws_elb.test-lb.name}"
load_balancer_port = 80
policy_names = [
"${aws_load_balancer_policy.test-policy.policy_name}"
]
}
`