Merge pull request #1090 from hashicorp/aws-go-elb
provider/aws: Convert AWS ELB to aws-sdk-go
This commit is contained in:
commit
475a748ff8
|
@ -9,10 +9,10 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/multierror"
|
||||
"github.com/mitchellh/goamz/aws"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
|
||||
awsGo "github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
||||
|
@ -64,7 +64,7 @@ func (c *Config) Client() (interface{}, error) {
|
|||
log.Println("[INFO] Initializing EC2 connection")
|
||||
client.ec2conn = ec2.New(auth, region)
|
||||
log.Println("[INFO] Initializing ELB connection")
|
||||
client.elbconn = elb.New(auth, region)
|
||||
client.elbconn = elb.New(creds, c.Region, nil)
|
||||
log.Println("[INFO] Initializing AutoScaling connection")
|
||||
client.autoscalingconn = autoscaling.New(creds, c.Region, nil)
|
||||
log.Println("[INFO] Initializing S3 connection")
|
||||
|
|
|
@ -5,9 +5,10 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
)
|
||||
|
||||
func resourceAwsElb() *schema.Resource {
|
||||
|
@ -167,14 +168,18 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
// Provision the elb
|
||||
elbOpts := &elb.CreateLoadBalancer{
|
||||
LoadBalancerName: d.Get("name").(string),
|
||||
|
||||
elbOpts := &elb.CreateAccessPointInput{
|
||||
LoadBalancerName: aws.String(d.Get("name").(string)),
|
||||
Listeners: listeners,
|
||||
Internal: d.Get("internal").(bool),
|
||||
}
|
||||
|
||||
if scheme, ok := d.GetOk("internal"); ok && scheme.(bool) {
|
||||
elbOpts.Scheme = aws.String("internal")
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("availability_zones"); ok {
|
||||
elbOpts.AvailZone = expandStringList(v.(*schema.Set).List())
|
||||
elbOpts.AvailabilityZones = expandStringList(v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("security_groups"); ok {
|
||||
|
@ -208,14 +213,14 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
if len(vs) > 0 {
|
||||
check := vs[0].(map[string]interface{})
|
||||
|
||||
configureHealthCheckOpts := elb.ConfigureHealthCheck{
|
||||
LoadBalancerName: d.Id(),
|
||||
Check: elb.HealthCheck{
|
||||
HealthyThreshold: int64(check["healthy_threshold"].(int)),
|
||||
UnhealthyThreshold: int64(check["unhealthy_threshold"].(int)),
|
||||
Interval: int64(check["interval"].(int)),
|
||||
Target: check["target"].(string),
|
||||
Timeout: int64(check["timeout"].(int)),
|
||||
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
|
||||
LoadBalancerName: aws.String(d.Id()),
|
||||
HealthCheck: &elb.HealthCheck{
|
||||
HealthyThreshold: aws.Integer(check["healthy_threshold"].(int)),
|
||||
UnhealthyThreshold: aws.Integer(check["unhealthy_threshold"].(int)),
|
||||
Interval: aws.Integer(check["interval"].(int)),
|
||||
Target: aws.String(check["target"].(string)),
|
||||
Timeout: aws.Integer(check["timeout"].(int)),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -233,13 +238,13 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
|
|||
elbconn := meta.(*AWSClient).elbconn
|
||||
|
||||
// Retrieve the ELB properties for updating the state
|
||||
describeElbOpts := &elb.DescribeLoadBalancer{
|
||||
Names: []string{d.Id()},
|
||||
describeElbOpts := &elb.DescribeAccessPointsInput{
|
||||
LoadBalancerNames: []string{d.Id()},
|
||||
}
|
||||
|
||||
describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts)
|
||||
if err != nil {
|
||||
if ec2err, ok := err.(*elb.Error); ok && ec2err.Code == "LoadBalancerNotFound" {
|
||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "LoadBalancerNotFound" {
|
||||
// The ELB is gone now, so just remove it from the state
|
||||
d.SetId("")
|
||||
return nil
|
||||
|
@ -247,24 +252,24 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
return fmt.Errorf("Error retrieving ELB: %s", err)
|
||||
}
|
||||
if len(describeResp.LoadBalancers) != 1 {
|
||||
return fmt.Errorf("Unable to find ELB: %#v", describeResp.LoadBalancers)
|
||||
if len(describeResp.LoadBalancerDescriptions) != 1 {
|
||||
return fmt.Errorf("Unable to find ELB: %#v", describeResp.LoadBalancerDescriptions)
|
||||
}
|
||||
|
||||
lb := describeResp.LoadBalancers[0]
|
||||
lb := describeResp.LoadBalancerDescriptions[0]
|
||||
|
||||
d.Set("name", lb.LoadBalancerName)
|
||||
d.Set("dns_name", lb.DNSName)
|
||||
d.Set("internal", lb.Scheme == "internal")
|
||||
d.Set("name", *lb.LoadBalancerName)
|
||||
d.Set("dns_name", *lb.DNSName)
|
||||
d.Set("internal", *lb.Scheme == "internal")
|
||||
d.Set("availability_zones", lb.AvailabilityZones)
|
||||
d.Set("instances", flattenInstances(lb.Instances))
|
||||
d.Set("listener", flattenListeners(lb.Listeners))
|
||||
d.Set("listener", flattenListeners(lb.ListenerDescriptions))
|
||||
d.Set("security_groups", lb.SecurityGroups)
|
||||
d.Set("subnets", lb.Subnets)
|
||||
|
||||
// There's only one health check, so save that to state as we
|
||||
// currently can
|
||||
if lb.HealthCheck.Target != "" {
|
||||
if *lb.HealthCheck.Target != "" {
|
||||
d.Set("health_check", flattenHealthCheck(lb.HealthCheck))
|
||||
}
|
||||
|
||||
|
@ -283,12 +288,12 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
o, n := d.GetChange("instances")
|
||||
os := o.(*schema.Set)
|
||||
ns := n.(*schema.Set)
|
||||
remove := expandStringList(os.Difference(ns).List())
|
||||
add := expandStringList(ns.Difference(os).List())
|
||||
remove := expandInstanceString(os.Difference(ns).List())
|
||||
add := expandInstanceString(ns.Difference(os).List())
|
||||
|
||||
if len(add) > 0 {
|
||||
registerInstancesOpts := elb.RegisterInstancesWithLoadBalancer{
|
||||
LoadBalancerName: d.Id(),
|
||||
registerInstancesOpts := elb.RegisterEndPointsInput{
|
||||
LoadBalancerName: aws.String(d.Id()),
|
||||
Instances: add,
|
||||
}
|
||||
|
||||
|
@ -298,8 +303,8 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
}
|
||||
if len(remove) > 0 {
|
||||
deRegisterInstancesOpts := elb.DeregisterInstancesFromLoadBalancer{
|
||||
LoadBalancerName: d.Id(),
|
||||
deRegisterInstancesOpts := elb.DeregisterEndPointsInput{
|
||||
LoadBalancerName: aws.String(d.Id()),
|
||||
Instances: remove,
|
||||
}
|
||||
|
||||
|
@ -315,10 +320,12 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
log.Println("[INFO] outside modify attributes")
|
||||
if d.HasChange("cross_zone_load_balancing") {
|
||||
log.Println("[INFO] inside modify attributes")
|
||||
attrs := elb.ModifyLoadBalancerAttributes{
|
||||
LoadBalancerName: d.Get("name").(string),
|
||||
LoadBalancerAttributes: elb.LoadBalancerAttributes{
|
||||
CrossZoneLoadBalancingEnabled: d.Get("cross_zone_load_balancing").(bool),
|
||||
attrs := elb.ModifyLoadBalancerAttributesInput{
|
||||
LoadBalancerName: aws.String(d.Get("name").(string)),
|
||||
LoadBalancerAttributes: &elb.LoadBalancerAttributes{
|
||||
CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{
|
||||
aws.Boolean(d.Get("cross_zone_load_balancing").(bool)),
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := elbconn.ModifyLoadBalancerAttributes(&attrs)
|
||||
|
@ -332,14 +339,14 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
vs := d.Get("health_check").(*schema.Set).List()
|
||||
if len(vs) > 0 {
|
||||
check := vs[0].(map[string]interface{})
|
||||
configureHealthCheckOpts := elb.ConfigureHealthCheck{
|
||||
LoadBalancerName: d.Id(),
|
||||
Check: elb.HealthCheck{
|
||||
HealthyThreshold: int64(check["healthy_threshold"].(int)),
|
||||
UnhealthyThreshold: int64(check["unhealthy_threshold"].(int)),
|
||||
Interval: int64(check["interval"].(int)),
|
||||
Target: check["target"].(string),
|
||||
Timeout: int64(check["timeout"].(int)),
|
||||
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
|
||||
LoadBalancerName: aws.String(d.Id()),
|
||||
HealthCheck: &elb.HealthCheck{
|
||||
HealthyThreshold: aws.Integer(check["healthy_threshold"].(int)),
|
||||
UnhealthyThreshold: aws.Integer(check["unhealthy_threshold"].(int)),
|
||||
Interval: aws.Integer(check["interval"].(int)),
|
||||
Target: aws.String(check["target"].(string)),
|
||||
Timeout: aws.Integer(check["timeout"].(int)),
|
||||
},
|
||||
}
|
||||
_, err := elbconn.ConfigureHealthCheck(&configureHealthCheckOpts)
|
||||
|
@ -351,6 +358,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
d.Partial(false)
|
||||
|
||||
return resourceAwsElbRead(d, meta)
|
||||
}
|
||||
|
||||
|
@ -360,8 +368,8 @@ func resourceAwsElbDelete(d *schema.ResourceData, meta interface{}) error {
|
|||
log.Printf("[INFO] Deleting ELB: %s", d.Id())
|
||||
|
||||
// Destroy the load balancer
|
||||
deleteElbOpts := elb.DeleteLoadBalancer{
|
||||
LoadBalancerName: d.Id(),
|
||||
deleteElbOpts := elb.DeleteAccessPointInput{
|
||||
LoadBalancerName: aws.String(d.Id()),
|
||||
}
|
||||
if _, err := elbconn.DeleteLoadBalancer(&deleteElbOpts); err != nil {
|
||||
return fmt.Errorf("Error deleting ELB: %s", err)
|
||||
|
|
|
@ -7,13 +7,14 @@ import (
|
|||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
)
|
||||
|
||||
func TestAccAWSELB_basic(t *testing.T) {
|
||||
var conf elb.LoadBalancer
|
||||
var conf elb.LoadBalancerDescription
|
||||
ssl_certificate_id := os.Getenv("AWS_SSL_CERTIFICATE_ID")
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
@ -53,7 +54,7 @@ func TestAccAWSELB_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccAWSELB_InstanceAttaching(t *testing.T) {
|
||||
var conf elb.LoadBalancer
|
||||
var conf elb.LoadBalancerDescription
|
||||
|
||||
testCheckInstanceAttached := func(count int) resource.TestCheckFunc {
|
||||
return func(*terraform.State) error {
|
||||
|
@ -89,7 +90,7 @@ func TestAccAWSELB_InstanceAttaching(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccAWSELB_HealthCheck(t *testing.T) {
|
||||
var conf elb.LoadBalancer
|
||||
var conf elb.LoadBalancerDescription
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -149,19 +150,19 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
|
|||
continue
|
||||
}
|
||||
|
||||
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancer{
|
||||
Names: []string{rs.Primary.ID},
|
||||
describe, err := conn.DescribeLoadBalancers(&elb.DescribeAccessPointsInput{
|
||||
LoadBalancerNames: []string{rs.Primary.ID},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
if len(describe.LoadBalancers) != 0 &&
|
||||
describe.LoadBalancers[0].LoadBalancerName == rs.Primary.ID {
|
||||
if len(describe.LoadBalancerDescriptions) != 0 &&
|
||||
*describe.LoadBalancerDescriptions[0].LoadBalancerName == rs.Primary.ID {
|
||||
return fmt.Errorf("ELB still exists")
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the error
|
||||
providerErr, ok := err.(*elb.Error)
|
||||
providerErr, ok := err.(aws.APIError)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
|
@ -174,7 +175,7 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc {
|
||||
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
||||
sort.StringSlice(conf.AvailabilityZones).Sort()
|
||||
|
@ -182,25 +183,25 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc
|
|||
return fmt.Errorf("bad availability_zones")
|
||||
}
|
||||
|
||||
if conf.LoadBalancerName != "foobar-terraform-test" {
|
||||
if *conf.LoadBalancerName != "foobar-terraform-test" {
|
||||
return fmt.Errorf("bad name")
|
||||
}
|
||||
|
||||
l := elb.Listener{
|
||||
InstancePort: 8000,
|
||||
InstanceProtocol: "HTTP",
|
||||
LoadBalancerPort: 80,
|
||||
Protocol: "HTTP",
|
||||
InstancePort: aws.Integer(8000),
|
||||
InstanceProtocol: aws.String("HTTP"),
|
||||
LoadBalancerPort: aws.Integer(80),
|
||||
Protocol: aws.String("HTTP"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(conf.Listeners[0], l) {
|
||||
if !reflect.DeepEqual(conf.ListenerDescriptions[0].Listener, &l) {
|
||||
return fmt.Errorf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
conf.Listeners[0],
|
||||
conf.ListenerDescriptions[0].Listener,
|
||||
l)
|
||||
}
|
||||
|
||||
if conf.DNSName == "" {
|
||||
if *conf.DNSName == "" {
|
||||
return fmt.Errorf("empty dns_name")
|
||||
}
|
||||
|
||||
|
@ -208,7 +209,7 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancer) resource.TestCheckFunc {
|
||||
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
||||
sort.StringSlice(conf.AvailabilityZones).Sort()
|
||||
|
@ -216,26 +217,26 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancer) resource.Te
|
|||
return fmt.Errorf("bad availability_zones")
|
||||
}
|
||||
|
||||
if conf.LoadBalancerName != "foobar-terraform-test" {
|
||||
if *conf.LoadBalancerName != "foobar-terraform-test" {
|
||||
return fmt.Errorf("bad name")
|
||||
}
|
||||
|
||||
check := elb.HealthCheck{
|
||||
Timeout: 30,
|
||||
UnhealthyThreshold: 5,
|
||||
HealthyThreshold: 5,
|
||||
Interval: 60,
|
||||
Target: "HTTP:8000/",
|
||||
Timeout: aws.Integer(30),
|
||||
UnhealthyThreshold: aws.Integer(5),
|
||||
HealthyThreshold: aws.Integer(5),
|
||||
Interval: aws.Integer(60),
|
||||
Target: aws.String("HTTP:8000/"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(conf.HealthCheck, check) {
|
||||
if !reflect.DeepEqual(conf.HealthCheck, &check) {
|
||||
return fmt.Errorf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
conf.HealthCheck,
|
||||
check)
|
||||
}
|
||||
|
||||
if conf.DNSName == "" {
|
||||
if *conf.DNSName == "" {
|
||||
return fmt.Errorf("empty dns_name")
|
||||
}
|
||||
|
||||
|
@ -243,7 +244,7 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancer) resource.Te
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckAWSELBExists(n string, res *elb.LoadBalancer) resource.TestCheckFunc {
|
||||
func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
|
@ -256,20 +257,20 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancer) resource.TestChec
|
|||
|
||||
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
||||
|
||||
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancer{
|
||||
Names: []string{rs.Primary.ID},
|
||||
describe, err := conn.DescribeLoadBalancers(&elb.DescribeAccessPointsInput{
|
||||
LoadBalancerNames: []string{rs.Primary.ID},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(describe.LoadBalancers) != 1 ||
|
||||
describe.LoadBalancers[0].LoadBalancerName != rs.Primary.ID {
|
||||
if len(describe.LoadBalancerDescriptions) != 1 ||
|
||||
*describe.LoadBalancerDescriptions[0].LoadBalancerName != rs.Primary.ID {
|
||||
return fmt.Errorf("ELB not found")
|
||||
}
|
||||
|
||||
*res = describe.LoadBalancers[0]
|
||||
*res = describe.LoadBalancerDescriptions[0]
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
)
|
||||
|
||||
// Takes the result of flatmap.Expand for an array of listeners and
|
||||
|
@ -21,14 +21,14 @@ func expandListeners(configured []interface{}) ([]elb.Listener, error) {
|
|||
data := lRaw.(map[string]interface{})
|
||||
|
||||
l := elb.Listener{
|
||||
InstancePort: int64(data["instance_port"].(int)),
|
||||
InstanceProtocol: data["instance_protocol"].(string),
|
||||
LoadBalancerPort: int64(data["lb_port"].(int)),
|
||||
Protocol: data["lb_protocol"].(string),
|
||||
InstancePort: aws.Integer(data["instance_port"].(int)),
|
||||
InstanceProtocol: aws.String(data["instance_protocol"].(string)),
|
||||
LoadBalancerPort: aws.Integer(data["lb_port"].(int)),
|
||||
Protocol: aws.String(data["lb_protocol"].(string)),
|
||||
}
|
||||
|
||||
if v, ok := data["ssl_certificate_id"]; ok {
|
||||
l.SSLCertificateId = v.(string)
|
||||
l.SSLCertificateID = aws.String(v.(string))
|
||||
}
|
||||
|
||||
listeners = append(listeners, l)
|
||||
|
@ -138,15 +138,15 @@ func flattenIPPerms(list []ec2.IPPerm) []map[string]interface{} {
|
|||
|
||||
// Flattens a health check into something that flatmap.Flatten()
|
||||
// can handle
|
||||
func flattenHealthCheck(check elb.HealthCheck) []map[string]interface{} {
|
||||
func flattenHealthCheck(check *elb.HealthCheck) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, 1)
|
||||
|
||||
chk := make(map[string]interface{})
|
||||
chk["unhealthy_threshold"] = int(check.UnhealthyThreshold)
|
||||
chk["healthy_threshold"] = int(check.HealthyThreshold)
|
||||
chk["target"] = check.Target
|
||||
chk["timeout"] = int(check.Timeout)
|
||||
chk["interval"] = int(check.Interval)
|
||||
chk["unhealthy_threshold"] = *check.UnhealthyThreshold
|
||||
chk["healthy_threshold"] = *check.HealthyThreshold
|
||||
chk["target"] = *check.Target
|
||||
chk["timeout"] = *check.Timeout
|
||||
chk["interval"] = *check.Interval
|
||||
|
||||
result = append(result, chk)
|
||||
|
||||
|
@ -166,22 +166,35 @@ func flattenSecurityGroups(list []ec2.UserSecurityGroup) []string {
|
|||
func flattenInstances(list []elb.Instance) []string {
|
||||
result := make([]string, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, i.InstanceId)
|
||||
result = append(result, *i.InstanceID)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Expands an array of String Instance IDs into a []Instances
|
||||
func expandInstanceString(list []interface{}) []elb.Instance {
|
||||
result := make([]elb.Instance, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, elb.Instance{aws.String(i.(string))})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Flattens an array of Listeners into a []map[string]interface{}
|
||||
func flattenListeners(list []elb.Listener) []map[string]interface{} {
|
||||
func flattenListeners(list []elb.ListenerDescription) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, map[string]interface{}{
|
||||
"instance_port": i.InstancePort,
|
||||
"instance_protocol": strings.ToLower(i.InstanceProtocol),
|
||||
"ssl_certificate_id": i.SSLCertificateId,
|
||||
"lb_port": i.LoadBalancerPort,
|
||||
"lb_protocol": strings.ToLower(i.Protocol),
|
||||
})
|
||||
l := map[string]interface{}{
|
||||
"instance_port": *i.Listener.InstancePort,
|
||||
"instance_protocol": strings.ToLower(*i.Listener.InstanceProtocol),
|
||||
"lb_port": *i.Listener.LoadBalancerPort,
|
||||
"lb_protocol": strings.ToLower(*i.Listener.Protocol),
|
||||
}
|
||||
// SSLCertificateID is optional, and may be nil
|
||||
if i.Listener.SSLCertificateID != nil {
|
||||
l["ssl_certificate_id"] = *i.Listener.SSLCertificateID
|
||||
}
|
||||
result = append(result, l)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||
"github.com/hashicorp/terraform/flatmap"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
)
|
||||
|
||||
// Returns test configuration
|
||||
|
@ -36,7 +36,7 @@ func testConf() map[string]string {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_expandIPPerms(t *testing.T) {
|
||||
func TestExpandIPPerms(t *testing.T) {
|
||||
hash := func(v interface{}) int {
|
||||
return hashcode.String(v.(string))
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func Test_expandIPPerms(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func Test_flattenIPPerms(t *testing.T) {
|
||||
func TestFlattenIPPerms(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input []ec2.IPPerm
|
||||
Output []map[string]interface{}
|
||||
|
@ -177,7 +177,7 @@ func Test_flattenIPPerms(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_expandListeners(t *testing.T) {
|
||||
func TestExpandListeners(t *testing.T) {
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"instance_port": 8000,
|
||||
|
@ -192,10 +192,10 @@ func Test_expandListeners(t *testing.T) {
|
|||
}
|
||||
|
||||
expected := elb.Listener{
|
||||
InstancePort: 8000,
|
||||
LoadBalancerPort: 80,
|
||||
InstanceProtocol: "http",
|
||||
Protocol: "http",
|
||||
InstancePort: aws.Integer(8000),
|
||||
LoadBalancerPort: aws.Integer(80),
|
||||
InstanceProtocol: aws.String("http"),
|
||||
Protocol: aws.String("http"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(listeners[0], expected) {
|
||||
|
@ -207,18 +207,18 @@ func Test_expandListeners(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func Test_flattenHealthCheck(t *testing.T) {
|
||||
func TestFlattenHealthCheck(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input elb.HealthCheck
|
||||
Output []map[string]interface{}
|
||||
}{
|
||||
{
|
||||
Input: elb.HealthCheck{
|
||||
UnhealthyThreshold: 10,
|
||||
HealthyThreshold: 10,
|
||||
Target: "HTTP:80/",
|
||||
Timeout: 30,
|
||||
Interval: 30,
|
||||
UnhealthyThreshold: aws.Integer(10),
|
||||
HealthyThreshold: aws.Integer(10),
|
||||
Target: aws.String("HTTP:80/"),
|
||||
Timeout: aws.Integer(30),
|
||||
Interval: aws.Integer(30),
|
||||
},
|
||||
Output: []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
|
@ -233,14 +233,14 @@ func Test_flattenHealthCheck(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
output := flattenHealthCheck(tc.Input)
|
||||
output := flattenHealthCheck(&tc.Input)
|
||||
if !reflect.DeepEqual(output, tc.Output) {
|
||||
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_expandStringList(t *testing.T) {
|
||||
func TestExpandStringList(t *testing.T) {
|
||||
expanded := flatmap.Expand(testConf(), "availability_zones").([]interface{})
|
||||
stringList := expandStringList(expanded)
|
||||
expected := []string{
|
||||
|
@ -257,7 +257,7 @@ func Test_expandStringList(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func Test_expandParameters(t *testing.T) {
|
||||
func TestExpandParameters(t *testing.T) {
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "character_set_client",
|
||||
|
@ -284,7 +284,7 @@ func Test_expandParameters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_flattenParameters(t *testing.T) {
|
||||
func TestFlattenParameters(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input []rds.Parameter
|
||||
Output []map[string]interface{}
|
||||
|
@ -312,3 +312,22 @@ func Test_flattenParameters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandInstanceString(t *testing.T) {
|
||||
|
||||
expected := []elb.Instance{
|
||||
elb.Instance{aws.String("test-one")},
|
||||
elb.Instance{aws.String("test-two")},
|
||||
}
|
||||
|
||||
ids := []interface{}{
|
||||
"test-one",
|
||||
"test-two",
|
||||
}
|
||||
|
||||
expanded := expandInstanceString(ids)
|
||||
|
||||
if !reflect.DeepEqual(expanded, expected) {
|
||||
t.Fatalf("Expand Instance String output did not match.\nGot:\n%#v\n\nexpected:\n%#v", expanded, expected)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue