2015-04-27 00:01:48 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/elb"
|
2015-05-04 00:29:42 +02:00
|
|
|
|
2015-04-27 00:01:48 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-12-09 00:48:57 +01:00
|
|
|
func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) {
|
2015-04-27 00:01:48 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckLBCookieStickinessPolicyDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccLBCookieStickinessPolicyConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckLBCookieStickinessPolicy(
|
|
|
|
"aws_elb.lb",
|
|
|
|
"aws_lb_cookie_stickiness_policy.foo",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccLBCookieStickinessPolicyConfigUpdate,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckLBCookieStickinessPolicy(
|
|
|
|
"aws_elb.lb",
|
2015-05-04 00:29:42 +02:00
|
|
|
"aws_lb_cookie_stickiness_policy.foo",
|
2015-04-27 00:01:48 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckLBCookieStickinessPolicyDestroy(s *terraform.State) error {
|
|
|
|
if len(s.RootModule().Resources) > 0 {
|
|
|
|
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckLBCookieStickinessPolicy(elbResource string, policyResource string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[elbResource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", elbResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
policy, ok := s.RootModule().Resources[policyResource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", policyResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
elbconn := testAccProvider.Meta().(*AWSClient).elbconn
|
|
|
|
elbName, _, policyName := resourceAwsLBCookieStickinessPolicyParseId(policy.Primary.ID)
|
|
|
|
_, err := elbconn.DescribeLoadBalancerPolicies(&elb.DescribeLoadBalancerPoliciesInput{
|
|
|
|
LoadBalancerName: aws.String(elbName),
|
|
|
|
PolicyNames: []*string{aws.String(policyName)},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccLBCookieStickinessPolicyConfig = `
|
|
|
|
resource "aws_elb" "lb" {
|
|
|
|
name = "test-lb"
|
2015-05-04 00:29:42 +02:00
|
|
|
availability_zones = ["us-west-2a"]
|
2015-04-27 00:01:48 +02:00
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_lb_cookie_stickiness_policy" "foo" {
|
2015-05-04 00:29:42 +02:00
|
|
|
name = "foo-policy"
|
|
|
|
load_balancer = "${aws_elb.lb.id}"
|
2015-04-27 00:01:48 +02:00
|
|
|
lb_port = 80
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2015-05-04 00:29:42 +02:00
|
|
|
// Sets the cookie_expiration_period to 300s.
|
2015-04-27 00:01:48 +02:00
|
|
|
const testAccLBCookieStickinessPolicyConfigUpdate = `
|
|
|
|
resource "aws_elb" "lb" {
|
|
|
|
name = "test-lb"
|
2015-05-04 00:29:42 +02:00
|
|
|
availability_zones = ["us-west-2a"]
|
2015-04-27 00:01:48 +02:00
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_lb_cookie_stickiness_policy" "foo" {
|
2015-05-04 00:29:42 +02:00
|
|
|
name = "foo-policy"
|
|
|
|
load_balancer = "${aws_elb.lb.id}"
|
2015-04-27 00:01:48 +02:00
|
|
|
lb_port = 80
|
2015-05-04 00:29:42 +02:00
|
|
|
cookie_expiration_period = 300
|
2015-04-27 00:01:48 +02:00
|
|
|
}
|
|
|
|
`
|