2014-07-15 00:48:22 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-10-02 04:19:36 +02:00
|
|
|
"os"
|
2014-07-15 00:48:22 +02:00
|
|
|
"reflect"
|
2014-12-16 15:21:25 +01:00
|
|
|
"sort"
|
2014-07-15 00:48:22 +02:00
|
|
|
"testing"
|
|
|
|
|
2015-04-14 23:41:36 +02:00
|
|
|
"github.com/awslabs/aws-sdk-go/aws"
|
|
|
|
"github.com/awslabs/aws-sdk-go/service/elb"
|
2014-07-15 00:48:22 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2014-07-16 23:02:47 +02:00
|
|
|
func TestAccAWSELB_basic(t *testing.T) {
|
2015-03-02 16:44:06 +01:00
|
|
|
var conf elb.LoadBalancerDescription
|
2014-10-02 04:19:36 +02:00
|
|
|
ssl_certificate_id := os.Getenv("AWS_SSL_CERTIFICATE_ID")
|
2014-07-15 00:48:22 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
testAccCheckAWSELBAttributes(&conf),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "name", "foobar-terraform-test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-16 15:21:25 +01:00
|
|
|
"aws_elb.bar", "availability_zones.2487133097", "us-west-2a"),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-16 15:21:25 +01:00
|
|
|
"aws_elb.bar", "availability_zones.221770259", "us-west-2b"),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-16 15:21:25 +01:00
|
|
|
"aws_elb.bar", "availability_zones.2050015877", "us-west-2c"),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "listener.206423021.instance_port", "8000"),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "listener.206423021.instance_protocol", "http"),
|
2014-08-11 01:09:05 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "listener.206423021.ssl_certificate_id", ssl_certificate_id),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "listener.206423021.lb_port", "80"),
|
2014-07-16 23:02:47 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "listener.206423021.lb_protocol", "http"),
|
2014-12-10 07:07:08 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "cross_zone_load_balancing", "true"),
|
2014-07-16 23:02:47 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:37:42 +01:00
|
|
|
func TestAccAWSELB_tags(t *testing.T) {
|
|
|
|
var conf elb.LoadBalancerDescription
|
|
|
|
var td elb.TagDescription
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfig,
|
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfig_TagUpdate,
|
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccLoadTags(conf *elb.LoadBalancerDescription, td *elb.TagDescription) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
|
|
|
|
|
|
|
describe, err := conn.DescribeTags(&elb.DescribeTagsInput{
|
2015-04-14 23:41:36 +02:00
|
|
|
LoadBalancerNames: []*string{conf.LoadBalancerName},
|
2015-03-24 19:37:42 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(describe.TagDescriptions) > 0 {
|
2015-04-14 23:41:36 +02:00
|
|
|
*td = *describe.TagDescriptions[0]
|
2015-03-24 19:37:42 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 23:02:47 +02:00
|
|
|
func TestAccAWSELB_InstanceAttaching(t *testing.T) {
|
2015-03-02 16:44:06 +01:00
|
|
|
var conf elb.LoadBalancerDescription
|
2014-07-16 23:02:47 +02:00
|
|
|
|
|
|
|
testCheckInstanceAttached := func(count int) resource.TestCheckFunc {
|
|
|
|
return func(*terraform.State) error {
|
|
|
|
if len(conf.Instances) != count {
|
|
|
|
return fmt.Errorf("instance count does not match")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
testAccCheckAWSELBAttributes(&conf),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigNewInstance,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
testCheckInstanceAttached(1),
|
2014-07-15 00:48:22 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-22 00:17:17 +02:00
|
|
|
func TestAccAWSELBUpdate_Listener(t *testing.T) {
|
|
|
|
var conf elb.LoadBalancerDescription
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
testAccCheckAWSELBAttributes(&conf),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "listener.206423021.instance_port", "8000"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigListener_update,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "listener.3931999347.instance_port", "8080"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-30 16:15:22 +02:00
|
|
|
func TestAccAWSELB_HealthCheck(t *testing.T) {
|
2015-03-02 16:44:06 +01:00
|
|
|
var conf elb.LoadBalancerDescription
|
2014-07-30 16:15:22 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigHealthCheck,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
testAccCheckAWSELBAttributesHealthCheck(&conf),
|
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"),
|
2014-07-30 16:15:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "health_check.3484319807.unhealthy_threshold", "5"),
|
2014-07-30 16:15:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "health_check.3484319807.target", "HTTP:8000/"),
|
2014-07-30 16:15:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "health_check.3484319807.timeout", "30"),
|
2014-07-30 16:15:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_elb.bar", "health_check.3484319807.interval", "60"),
|
2014-07-30 16:15:22 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-02-03 04:25:54 +01:00
|
|
|
|
|
|
|
func TestAccAWSELBUpdate_HealthCheck(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigHealthCheck,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigHealthCheck_update,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "health_check.2648756019.healthy_threshold", "10"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-22 08:44:24 +02:00
|
|
|
func TestAccAWSELB_Timeout(t *testing.T) {
|
2015-04-13 22:14:26 +02:00
|
|
|
var conf elb.LoadBalancerDescription
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigIdleTimeout,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSELBExists("aws_elb.bar", &conf),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "idle_timeout", "200",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-22 08:44:24 +02:00
|
|
|
func TestAccAWSELBUpdate_Timeout(t *testing.T) {
|
2015-04-13 22:14:26 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigIdleTimeout,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "idle_timeout", "200",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigIdleTimeout_update,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "idle_timeout", "400",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-22 08:44:24 +02:00
|
|
|
func TestAccAWSELB_ConnectionDraining(t *testing.T) {
|
2015-04-13 22:14:26 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigConnectionDraining,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining", "true",
|
|
|
|
),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining_timeout", "400",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-22 08:44:24 +02:00
|
|
|
func TestAccAWSELBUpdate_ConnectionDraining(t *testing.T) {
|
2015-04-13 22:14:26 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigConnectionDraining,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining", "true",
|
|
|
|
),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining_timeout", "400",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigConnectionDraining_update_timeout,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining", "true",
|
|
|
|
),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining_timeout", "600",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigConnectionDraining_update_disable,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "connection_draining", "false",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-23 21:46:29 +02:00
|
|
|
func TestAccAWSELB_SecurityGroups(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "security_groups.#", "0",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSELBConfigSecurityGroups,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elb.bar", "security_groups.#", "1",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-15 00:48:22 +02:00
|
|
|
func testAccCheckAWSELBDestroy(s *terraform.State) error {
|
2014-11-21 17:58:34 +01:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
2014-07-15 00:48:22 +02:00
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-07-15 00:48:22 +02:00
|
|
|
if rs.Type != "aws_elb" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:41:36 +02:00
|
|
|
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
|
|
|
|
LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
|
2014-07-15 00:48:22 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err == nil {
|
2015-03-02 16:44:06 +01:00
|
|
|
if len(describe.LoadBalancerDescriptions) != 0 &&
|
|
|
|
*describe.LoadBalancerDescriptions[0].LoadBalancerName == rs.Primary.ID {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("ELB still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the error
|
2015-03-02 16:44:06 +01:00
|
|
|
providerErr, ok := err.(aws.APIError)
|
2014-07-15 00:48:22 +02:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if providerErr.Code != "InvalidLoadBalancerName.NotFound" {
|
|
|
|
return fmt.Errorf("Unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
2014-07-15 00:48:22 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-12-16 15:21:25 +01:00
|
|
|
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
2015-04-14 23:41:36 +02:00
|
|
|
azs := make([]string, 0, len(conf.AvailabilityZones))
|
|
|
|
for _, x := range conf.AvailabilityZones {
|
|
|
|
azs = append(azs, *x)
|
|
|
|
}
|
|
|
|
sort.StringSlice(azs).Sort()
|
|
|
|
if !reflect.DeepEqual(azs, zones) {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("bad availability_zones")
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
if *conf.LoadBalancerName != "foobar-terraform-test" {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("bad name")
|
|
|
|
}
|
|
|
|
|
|
|
|
l := elb.Listener{
|
2015-04-14 23:41:36 +02:00
|
|
|
InstancePort: aws.Long(int64(8000)),
|
2015-03-02 16:44:06 +01:00
|
|
|
InstanceProtocol: aws.String("HTTP"),
|
2015-04-14 23:41:36 +02:00
|
|
|
LoadBalancerPort: aws.Long(int64(80)),
|
2015-03-02 16:44:06 +01:00
|
|
|
Protocol: aws.String("HTTP"),
|
2014-07-15 00:48:22 +02:00
|
|
|
}
|
2014-07-15 00:57:04 +02:00
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
if !reflect.DeepEqual(conf.ListenerDescriptions[0].Listener, &l) {
|
2014-07-15 14:49:40 +02:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-03-02 16:44:06 +01:00
|
|
|
conf.ListenerDescriptions[0].Listener,
|
2014-07-15 14:49:40 +02:00
|
|
|
l)
|
2014-07-15 00:48:22 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
if *conf.DNSName == "" {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("empty dns_name")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
2014-07-30 16:15:22 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-12-16 15:21:25 +01:00
|
|
|
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
2015-04-14 23:41:36 +02:00
|
|
|
azs := make([]string, 0, len(conf.AvailabilityZones))
|
|
|
|
for _, x := range conf.AvailabilityZones {
|
|
|
|
azs = append(azs, *x)
|
|
|
|
}
|
|
|
|
sort.StringSlice(azs).Sort()
|
|
|
|
if !reflect.DeepEqual(azs, zones) {
|
2014-07-30 16:15:22 +02:00
|
|
|
return fmt.Errorf("bad availability_zones")
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
if *conf.LoadBalancerName != "foobar-terraform-test" {
|
2014-07-30 16:15:22 +02:00
|
|
|
return fmt.Errorf("bad name")
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:41:36 +02:00
|
|
|
check := &elb.HealthCheck{
|
|
|
|
Timeout: aws.Long(int64(30)),
|
|
|
|
UnhealthyThreshold: aws.Long(int64(5)),
|
|
|
|
HealthyThreshold: aws.Long(int64(5)),
|
|
|
|
Interval: aws.Long(int64(60)),
|
2015-03-02 16:44:06 +01:00
|
|
|
Target: aws.String("HTTP:8000/"),
|
2014-07-30 16:15:22 +02:00
|
|
|
}
|
|
|
|
|
2015-04-14 23:41:36 +02:00
|
|
|
if !reflect.DeepEqual(conf.HealthCheck, check) {
|
2014-07-30 16:15:22 +02:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
conf.HealthCheck,
|
|
|
|
check)
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
if *conf.DNSName == "" {
|
2014-07-30 16:15:22 +02:00
|
|
|
return fmt.Errorf("empty dns_name")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
2014-07-15 00:48:22 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:44:42 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-07-15 00:48:22 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("No ELB ID is set")
|
|
|
|
}
|
|
|
|
|
2014-11-21 17:58:34 +01:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
2014-07-15 00:48:22 +02:00
|
|
|
|
2015-04-14 23:41:36 +02:00
|
|
|
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
|
|
|
|
LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
|
2014-07-15 00:48:22 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:44:06 +01:00
|
|
|
if len(describe.LoadBalancerDescriptions) != 1 ||
|
|
|
|
*describe.LoadBalancerDescriptions[0].LoadBalancerName != rs.Primary.ID {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("ELB not found")
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:41:36 +02:00
|
|
|
*res = *describe.LoadBalancerDescriptions[0]
|
2014-07-15 00:48:22 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccAWSELBConfig = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
2014-07-16 23:02:47 +02:00
|
|
|
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
2014-07-15 00:48:22 +02:00
|
|
|
|
2014-07-15 00:57:04 +02:00
|
|
|
listener {
|
2014-07-15 00:48:22 +02:00
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
2014-07-15 00:57:04 +02:00
|
|
|
|
2015-03-24 19:37:42 +01:00
|
|
|
tags {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
|
|
|
|
cross_zone_load_balancing = true
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSELBConfig_TagUpdate = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
foo = "bar"
|
|
|
|
new = "type"
|
|
|
|
}
|
|
|
|
|
2014-12-10 07:07:08 +01:00
|
|
|
cross_zone_load_balancing = true
|
2014-07-15 00:48:22 +02:00
|
|
|
}
|
|
|
|
`
|
2014-07-16 23:02:47 +02:00
|
|
|
|
|
|
|
const testAccAWSELBConfigNewInstance = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
instances = ["${aws_instance.foo.id}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_instance" "foo" {
|
|
|
|
# us-west-2
|
|
|
|
ami = "ami-043a5034"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
`
|
2014-07-30 16:15:22 +02:00
|
|
|
|
2014-08-11 01:09:05 +02:00
|
|
|
const testAccAWSELBConfigListenerSSLCertificateId = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
2014-10-02 04:19:36 +02:00
|
|
|
ssl_certificate_id = "%s"
|
2014-08-11 01:09:05 +02:00
|
|
|
lb_port = 443
|
|
|
|
lb_protocol = "https"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2014-07-30 16:15:22 +02:00
|
|
|
const testAccAWSELBConfigHealthCheck = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
2015-02-19 00:18:51 +01:00
|
|
|
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
2014-07-30 16:15:22 +02:00
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
health_check {
|
|
|
|
healthy_threshold = 5
|
|
|
|
unhealthy_threshold = 5
|
|
|
|
target = "HTTP:8000/"
|
|
|
|
interval = 60
|
|
|
|
timeout = 30
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2015-02-03 04:25:54 +01:00
|
|
|
|
|
|
|
const testAccAWSELBConfigHealthCheck_update = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
health_check {
|
|
|
|
healthy_threshold = 10
|
|
|
|
unhealthy_threshold = 5
|
|
|
|
target = "HTTP:8000/"
|
|
|
|
interval = 60
|
|
|
|
timeout = 30
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2015-04-22 00:17:17 +02:00
|
|
|
|
|
|
|
const testAccAWSELBConfigListener_update = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8080
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2015-04-22 08:38:19 +02:00
|
|
|
|
2015-04-13 22:14:26 +02:00
|
|
|
const testAccAWSELBConfigIdleTimeout = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
idle_timeout = 200
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSELBConfigIdleTimeout_update = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
idle_timeout = 400
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSELBConfigConnectionDraining = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
connection_draining = true
|
|
|
|
connection_draining_timeout = 400
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSELBConfigConnectionDraining_update_timeout = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
connection_draining = true
|
2015-05-06 19:20:05 +02:00
|
|
|
connection_draining_timeout = 600
|
2015-04-13 22:14:26 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSELBConfigConnectionDraining_update_disable = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
connection_draining = false
|
|
|
|
}
|
|
|
|
`
|
2015-04-23 21:46:29 +02:00
|
|
|
|
|
|
|
const testAccAWSELBConfigSecurityGroups = `
|
|
|
|
resource "aws_elb" "bar" {
|
|
|
|
name = "foobar-terraform-test"
|
|
|
|
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
|
|
|
|
|
|
listener {
|
|
|
|
instance_port = 8000
|
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
security_groups = ["${aws_security_group.bar.id}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
to_port = 80
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|