providers/aws: Conver AWS ELB to upstream

This commit is contained in:
Clint Shryock 2015-04-14 16:41:36 -05:00
parent e72e344d07
commit 4186ec18c6
7 changed files with 112 additions and 100 deletions

View File

@ -6,10 +6,10 @@ import (
"github.com/hashicorp/terraform/helper/multierror" "github.com/hashicorp/terraform/helper/multierror"
"github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/autoscaling" "github.com/hashicorp/aws-sdk-go/gen/autoscaling"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/hashicorp/aws-sdk-go/gen/ec2"
"github.com/hashicorp/aws-sdk-go/gen/elb"
"github.com/hashicorp/aws-sdk-go/gen/iam" "github.com/hashicorp/aws-sdk-go/gen/iam"
"github.com/hashicorp/aws-sdk-go/gen/rds" "github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/aws-sdk-go/gen/route53" "github.com/hashicorp/aws-sdk-go/gen/route53"
@ -60,8 +60,13 @@ func (c *Config) Client() (interface{}, error) {
log.Println("[INFO] Building AWS auth structure") log.Println("[INFO] Building AWS auth structure")
creds := aws.DetectCreds(c.AccessKey, c.SecretKey, c.Token) creds := aws.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
log.Println("[INFO] Initializing ELB connection") log.Println("[INFO] Initializing ELB connection")
client.elbconn = elb.New(creds, c.Region, nil) client.elbconn = elb.New(&awsSDK.Config{
Credentials: sdkCreds,
Region: c.Region,
})
log.Println("[INFO] Initializing AutoScaling connection") log.Println("[INFO] Initializing AutoScaling connection")
client.autoscalingconn = autoscaling.New(creds, c.Region, nil) client.autoscalingconn = autoscaling.New(creds, c.Region, nil)
log.Println("[INFO] Initializing S3 connection") log.Println("[INFO] Initializing S3 connection")
@ -78,7 +83,6 @@ func (c *Config) Client() (interface{}, error) {
client.ec2conn = ec2.New(creds, c.Region, nil) client.ec2conn = ec2.New(creds, c.Region, nil)
client.iamconn = iam.New(creds, c.Region, nil) client.iamconn = iam.New(creds, c.Region, nil)
sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
client.ec2SDKconn = awsEC2.New(&awsSDK.Config{ client.ec2SDKconn = awsEC2.New(&awsSDK.Config{
Credentials: sdkCreds, Credentials: sdkCreds,
Region: c.Region, Region: c.Region,

View File

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -163,15 +163,15 @@ func resourceAwsElb() *schema.Resource {
func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbconn elbconn := meta.(*AWSClient).elbconn
// Expand the "listener" set to aws-sdk-go compat []elb.Listener // Expand the "listener" set to aws-sdk-go compat []*elb.Listener
listeners, err := expandListeners(d.Get("listener").(*schema.Set).List()) listeners, err := expandListenersSDK(d.Get("listener").(*schema.Set).List())
if err != nil { if err != nil {
return err return err
} }
tags := tagsFromMapELB(d.Get("tags").(map[string]interface{})) tags := tagsFromMapELB(d.Get("tags").(map[string]interface{}))
// Provision the elb // Provision the elb
elbOpts := &elb.CreateAccessPointInput{ elbOpts := &elb.CreateLoadBalancerInput{
LoadBalancerName: aws.String(d.Get("name").(string)), LoadBalancerName: aws.String(d.Get("name").(string)),
Listeners: listeners, Listeners: listeners,
Tags: tags, Tags: tags,
@ -182,15 +182,15 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
} }
if v, ok := d.GetOk("availability_zones"); ok { if v, ok := d.GetOk("availability_zones"); ok {
elbOpts.AvailabilityZones = expandStringList(v.(*schema.Set).List()) elbOpts.AvailabilityZones = expandStringListSDK(v.(*schema.Set).List())
} }
if v, ok := d.GetOk("security_groups"); ok { if v, ok := d.GetOk("security_groups"); ok {
elbOpts.SecurityGroups = expandStringList(v.(*schema.Set).List()) elbOpts.SecurityGroups = expandStringListSDK(v.(*schema.Set).List())
} }
if v, ok := d.GetOk("subnets"); ok { if v, ok := d.GetOk("subnets"); ok {
elbOpts.Subnets = expandStringList(v.(*schema.Set).List()) elbOpts.Subnets = expandStringListSDK(v.(*schema.Set).List())
} }
log.Printf("[DEBUG] ELB create configuration: %#v", elbOpts) log.Printf("[DEBUG] ELB create configuration: %#v", elbOpts)
@ -221,11 +221,11 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{ configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
LoadBalancerName: aws.String(d.Id()), LoadBalancerName: aws.String(d.Id()),
HealthCheck: &elb.HealthCheck{ HealthCheck: &elb.HealthCheck{
HealthyThreshold: aws.Integer(check["healthy_threshold"].(int)), HealthyThreshold: aws.Long(int64(check["healthy_threshold"].(int))),
UnhealthyThreshold: aws.Integer(check["unhealthy_threshold"].(int)), UnhealthyThreshold: aws.Long(int64(check["unhealthy_threshold"].(int))),
Interval: aws.Integer(check["interval"].(int)), Interval: aws.Long(int64(check["interval"].(int))),
Target: aws.String(check["target"].(string)), Target: aws.String(check["target"].(string)),
Timeout: aws.Integer(check["timeout"].(int)), Timeout: aws.Long(int64(check["timeout"].(int))),
}, },
} }
@ -243,8 +243,8 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbconn elbconn := meta.(*AWSClient).elbconn
// Retrieve the ELB properties for updating the state // Retrieve the ELB properties for updating the state
describeElbOpts := &elb.DescribeAccessPointsInput{ describeElbOpts := &elb.DescribeLoadBalancersInput{
LoadBalancerNames: []string{d.Id()}, LoadBalancerNames: []*string{aws.String(d.Id())},
} }
describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts) describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts)
@ -267,16 +267,16 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
d.Set("dns_name", *lb.DNSName) d.Set("dns_name", *lb.DNSName)
d.Set("internal", *lb.Scheme == "internal") d.Set("internal", *lb.Scheme == "internal")
d.Set("availability_zones", lb.AvailabilityZones) d.Set("availability_zones", lb.AvailabilityZones)
d.Set("instances", flattenInstances(lb.Instances)) d.Set("instances", flattenInstancesSDK(lb.Instances))
d.Set("listener", flattenListeners(lb.ListenerDescriptions)) d.Set("listener", flattenListenersSDK(lb.ListenerDescriptions))
d.Set("security_groups", lb.SecurityGroups) d.Set("security_groups", lb.SecurityGroups)
d.Set("subnets", lb.Subnets) d.Set("subnets", lb.Subnets)
resp, err := elbconn.DescribeTags(&elb.DescribeTagsInput{ resp, err := elbconn.DescribeTags(&elb.DescribeTagsInput{
LoadBalancerNames: []string{*lb.LoadBalancerName}, LoadBalancerNames: []*string{lb.LoadBalancerName},
}) })
var et []elb.Tag var et []*elb.Tag
if len(resp.TagDescriptions) > 0 { if len(resp.TagDescriptions) > 0 {
et = resp.TagDescriptions[0].Tags et = resp.TagDescriptions[0].Tags
} }
@ -284,7 +284,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
// There's only one health check, so save that to state as we // There's only one health check, so save that to state as we
// currently can // currently can
if *lb.HealthCheck.Target != "" { if *lb.HealthCheck.Target != "" {
d.Set("health_check", flattenHealthCheck(lb.HealthCheck)) d.Set("health_check", flattenHealthCheckSDK(lb.HealthCheck))
} }
return nil return nil
@ -302,11 +302,11 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
o, n := d.GetChange("instances") o, n := d.GetChange("instances")
os := o.(*schema.Set) os := o.(*schema.Set)
ns := n.(*schema.Set) ns := n.(*schema.Set)
remove := expandInstanceString(os.Difference(ns).List()) remove := expandInstanceStringSDK(os.Difference(ns).List())
add := expandInstanceString(ns.Difference(os).List()) add := expandInstanceStringSDK(ns.Difference(os).List())
if len(add) > 0 { if len(add) > 0 {
registerInstancesOpts := elb.RegisterEndPointsInput{ registerInstancesOpts := elb.RegisterInstancesWithLoadBalancerInput{
LoadBalancerName: aws.String(d.Id()), LoadBalancerName: aws.String(d.Id()),
Instances: add, Instances: add,
} }
@ -317,7 +317,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
} }
} }
if len(remove) > 0 { if len(remove) > 0 {
deRegisterInstancesOpts := elb.DeregisterEndPointsInput{ deRegisterInstancesOpts := elb.DeregisterInstancesFromLoadBalancerInput{
LoadBalancerName: aws.String(d.Id()), LoadBalancerName: aws.String(d.Id()),
Instances: remove, Instances: remove,
} }
@ -338,7 +338,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
LoadBalancerName: aws.String(d.Get("name").(string)), LoadBalancerName: aws.String(d.Get("name").(string)),
LoadBalancerAttributes: &elb.LoadBalancerAttributes{ LoadBalancerAttributes: &elb.LoadBalancerAttributes{
CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{ CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{
aws.Boolean(d.Get("cross_zone_load_balancing").(bool)), Enabled: aws.Boolean(d.Get("cross_zone_load_balancing").(bool)),
}, },
}, },
} }
@ -356,11 +356,11 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{ configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
LoadBalancerName: aws.String(d.Id()), LoadBalancerName: aws.String(d.Id()),
HealthCheck: &elb.HealthCheck{ HealthCheck: &elb.HealthCheck{
HealthyThreshold: aws.Integer(check["healthy_threshold"].(int)), HealthyThreshold: aws.Long(int64(check["healthy_threshold"].(int))),
UnhealthyThreshold: aws.Integer(check["unhealthy_threshold"].(int)), UnhealthyThreshold: aws.Long(int64(check["unhealthy_threshold"].(int))),
Interval: aws.Integer(check["interval"].(int)), Interval: aws.Long(int64(check["interval"].(int))),
Target: aws.String(check["target"].(string)), Target: aws.String(check["target"].(string)),
Timeout: aws.Integer(check["timeout"].(int)), Timeout: aws.Long(int64(check["timeout"].(int))),
}, },
} }
_, err := elbconn.ConfigureHealthCheck(&configureHealthCheckOpts) _, err := elbconn.ConfigureHealthCheck(&configureHealthCheckOpts)
@ -387,7 +387,7 @@ func resourceAwsElbDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Deleting ELB: %s", d.Id()) log.Printf("[INFO] Deleting ELB: %s", d.Id())
// Destroy the load balancer // Destroy the load balancer
deleteElbOpts := elb.DeleteAccessPointInput{ deleteElbOpts := elb.DeleteLoadBalancerInput{
LoadBalancerName: aws.String(d.Id()), LoadBalancerName: aws.String(d.Id()),
} }
if _, err := elbconn.DeleteLoadBalancer(&deleteElbOpts); err != nil { if _, err := elbconn.DeleteLoadBalancer(&deleteElbOpts); err != nil {

View File

@ -7,8 +7,8 @@ import (
"sort" "sort"
"testing" "testing"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -95,14 +95,14 @@ func testAccLoadTags(conf *elb.LoadBalancerDescription, td *elb.TagDescription)
conn := testAccProvider.Meta().(*AWSClient).elbconn conn := testAccProvider.Meta().(*AWSClient).elbconn
describe, err := conn.DescribeTags(&elb.DescribeTagsInput{ describe, err := conn.DescribeTags(&elb.DescribeTagsInput{
LoadBalancerNames: []string{*conf.LoadBalancerName}, LoadBalancerNames: []*string{conf.LoadBalancerName},
}) })
if err != nil { if err != nil {
return err return err
} }
if len(describe.TagDescriptions) > 0 { if len(describe.TagDescriptions) > 0 {
*td = describe.TagDescriptions[0] *td = *describe.TagDescriptions[0]
} }
return nil return nil
} }
@ -205,8 +205,8 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
continue continue
} }
describe, err := conn.DescribeLoadBalancers(&elb.DescribeAccessPointsInput{ describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
LoadBalancerNames: []string{rs.Primary.ID}, LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
}) })
if err == nil { if err == nil {
@ -233,8 +233,12 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc { func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"} zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
sort.StringSlice(conf.AvailabilityZones).Sort() azs := make([]string, 0, len(conf.AvailabilityZones))
if !reflect.DeepEqual(conf.AvailabilityZones, zones) { for _, x := range conf.AvailabilityZones {
azs = append(azs, *x)
}
sort.StringSlice(azs).Sort()
if !reflect.DeepEqual(azs, zones) {
return fmt.Errorf("bad availability_zones") return fmt.Errorf("bad availability_zones")
} }
@ -243,9 +247,9 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te
} }
l := elb.Listener{ l := elb.Listener{
InstancePort: aws.Integer(8000), InstancePort: aws.Long(int64(8000)),
InstanceProtocol: aws.String("HTTP"), InstanceProtocol: aws.String("HTTP"),
LoadBalancerPort: aws.Integer(80), LoadBalancerPort: aws.Long(int64(80)),
Protocol: aws.String("HTTP"), Protocol: aws.String("HTTP"),
} }
@ -267,8 +271,12 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc { func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"} zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
sort.StringSlice(conf.AvailabilityZones).Sort() azs := make([]string, 0, len(conf.AvailabilityZones))
if !reflect.DeepEqual(conf.AvailabilityZones, zones) { for _, x := range conf.AvailabilityZones {
azs = append(azs, *x)
}
sort.StringSlice(azs).Sort()
if !reflect.DeepEqual(azs, zones) {
return fmt.Errorf("bad availability_zones") return fmt.Errorf("bad availability_zones")
} }
@ -276,15 +284,15 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription)
return fmt.Errorf("bad name") return fmt.Errorf("bad name")
} }
check := elb.HealthCheck{ check := &elb.HealthCheck{
Timeout: aws.Integer(30), Timeout: aws.Long(int64(30)),
UnhealthyThreshold: aws.Integer(5), UnhealthyThreshold: aws.Long(int64(5)),
HealthyThreshold: aws.Integer(5), HealthyThreshold: aws.Long(int64(5)),
Interval: aws.Integer(60), Interval: aws.Long(int64(60)),
Target: aws.String("HTTP:8000/"), Target: aws.String("HTTP:8000/"),
} }
if !reflect.DeepEqual(conf.HealthCheck, &check) { if !reflect.DeepEqual(conf.HealthCheck, check) {
return fmt.Errorf( return fmt.Errorf(
"Got:\n\n%#v\n\nExpected:\n\n%#v\n", "Got:\n\n%#v\n\nExpected:\n\n%#v\n",
conf.HealthCheck, conf.HealthCheck,
@ -312,8 +320,8 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resour
conn := testAccProvider.Meta().(*AWSClient).elbconn conn := testAccProvider.Meta().(*AWSClient).elbconn
describe, err := conn.DescribeLoadBalancers(&elb.DescribeAccessPointsInput{ describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
LoadBalancerNames: []string{rs.Primary.ID}, LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
}) })
if err != nil { if err != nil {
@ -325,7 +333,7 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resour
return fmt.Errorf("ELB not found") return fmt.Errorf("ELB not found")
} }
*res = describe.LoadBalancerDescriptions[0] *res = *describe.LoadBalancerDescriptions[0]
return nil return nil
} }

View File

@ -5,24 +5,24 @@ import (
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/aws-sdk-go/gen/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/aws-sdk-go/gen/rds" "github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
// Takes the result of flatmap.Expand for an array of listeners and // Takes the result of flatmap.Expand for an array of listeners and
// returns ELB API compatible objects // returns ELB API compatible objects
func expandListenersSDK(configured []interface{}) ([]elb.Listener, error) { func expandListenersSDK(configured []interface{}) ([]*elb.Listener, error) {
listeners := make([]elb.Listener, 0, len(configured)) listeners := make([]*elb.Listener, 0, len(configured))
// Loop over our configured listeners and create // Loop over our configured listeners and create
// an array of aws-sdk-go compatabile objects // an array of aws-sdk-go compatabile objects
for _, lRaw := range configured { for _, lRaw := range configured {
data := lRaw.(map[string]interface{}) data := lRaw.(map[string]interface{})
ip := data["instance_port"].(int) ip := int64(data["instance_port"].(int))
lp := data["lb_port"].(int) lp := int64(data["lb_port"].(int))
l := elb.Listener{ l := &elb.Listener{
InstancePort: &ip, InstancePort: &ip,
InstanceProtocol: aws.String(data["instance_protocol"].(string)), InstanceProtocol: aws.String(data["instance_protocol"].(string)),
LoadBalancerPort: &lp, LoadBalancerPort: &lp,
@ -152,7 +152,7 @@ func flattenSecurityGroupsSDK(list []*ec2.UserIDGroupPair) []string {
} }
// Flattens an array of Instances into a []string // Flattens an array of Instances into a []string
func flattenInstancesSDK(list []elb.Instance) []string { func flattenInstancesSDK(list []*elb.Instance) []string {
result := make([]string, 0, len(list)) result := make([]string, 0, len(list))
for _, i := range list { for _, i := range list {
result = append(result, *i.InstanceID) result = append(result, *i.InstanceID)
@ -161,16 +161,16 @@ func flattenInstancesSDK(list []elb.Instance) []string {
} }
// Expands an array of String Instance IDs into a []Instances // Expands an array of String Instance IDs into a []Instances
func expandInstanceStringSDK(list []interface{}) []elb.Instance { func expandInstanceStringSDK(list []interface{}) []*elb.Instance {
result := make([]elb.Instance, 0, len(list)) result := make([]*elb.Instance, 0, len(list))
for _, i := range list { for _, i := range list {
result = append(result, elb.Instance{aws.String(i.(string))}) result = append(result, &elb.Instance{InstanceID: aws.String(i.(string))})
} }
return result return result
} }
// Flattens an array of Listeners into a []map[string]interface{} // Flattens an array of Listeners into a []map[string]interface{}
func flattenListenersSDK(list []elb.ListenerDescription) []map[string]interface{} { func flattenListenersSDK(list []*elb.ListenerDescription) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(list)) result := make([]map[string]interface{}, 0, len(list))
for _, i := range list { for _, i := range list {
l := map[string]interface{}{ l := map[string]interface{}{

View File

@ -5,8 +5,8 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/aws-sdk-go/aws" "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/aws-sdk-go/gen/rds"
"github.com/hashicorp/terraform/flatmap" "github.com/hashicorp/terraform/flatmap"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
@ -68,8 +68,8 @@ func TestExpandIPPermsSDK(t *testing.T) {
expected := []ec2.IPPermission{ expected := []ec2.IPPermission{
ec2.IPPermission{ ec2.IPPermission{
IPProtocol: aws.String("icmp"), IPProtocol: aws.String("icmp"),
FromPort: aws.Long(1), FromPort: aws.Long(int64(1)),
ToPort: aws.Long(-1), ToPort: aws.Long(int64(-1)),
IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}}, IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}},
UserIDGroupPairs: []*ec2.UserIDGroupPair{ UserIDGroupPairs: []*ec2.UserIDGroupPair{
&ec2.UserIDGroupPair{ &ec2.UserIDGroupPair{
@ -83,8 +83,8 @@ func TestExpandIPPermsSDK(t *testing.T) {
}, },
ec2.IPPermission{ ec2.IPPermission{
IPProtocol: aws.String("icmp"), IPProtocol: aws.String("icmp"),
FromPort: aws.Long(1), FromPort: aws.Long(int64(1)),
ToPort: aws.Long(-1), ToPort: aws.Long(int64(-1)),
UserIDGroupPairs: []*ec2.UserIDGroupPair{ UserIDGroupPairs: []*ec2.UserIDGroupPair{
&ec2.UserIDGroupPair{ &ec2.UserIDGroupPair{
UserID: aws.String("foo"), UserID: aws.String("foo"),
@ -150,8 +150,8 @@ func TestExpandIPPerms_nonVPCSDK(t *testing.T) {
expected := []ec2.IPPermission{ expected := []ec2.IPPermission{
ec2.IPPermission{ ec2.IPPermission{
IPProtocol: aws.String("icmp"), IPProtocol: aws.String("icmp"),
FromPort: aws.Long(1), FromPort: aws.Long(int64(1)),
ToPort: aws.Long(-1), ToPort: aws.Long(int64(-1)),
IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}}, IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}},
UserIDGroupPairs: []*ec2.UserIDGroupPair{ UserIDGroupPairs: []*ec2.UserIDGroupPair{
&ec2.UserIDGroupPair{ &ec2.UserIDGroupPair{
@ -164,8 +164,8 @@ func TestExpandIPPerms_nonVPCSDK(t *testing.T) {
}, },
ec2.IPPermission{ ec2.IPPermission{
IPProtocol: aws.String("icmp"), IPProtocol: aws.String("icmp"),
FromPort: aws.Long(1), FromPort: aws.Long(int64(1)),
ToPort: aws.Long(-1), ToPort: aws.Long(int64(-1)),
UserIDGroupPairs: []*ec2.UserIDGroupPair{ UserIDGroupPairs: []*ec2.UserIDGroupPair{
&ec2.UserIDGroupPair{ &ec2.UserIDGroupPair{
GroupName: aws.String("foo"), GroupName: aws.String("foo"),
@ -207,8 +207,8 @@ func TestExpandListenersSDK(t *testing.T) {
} }
expected := elb.Listener{ expected := elb.Listener{
InstancePort: aws.Integer(8000), InstancePort: aws.Long(int64(8000)),
LoadBalancerPort: aws.Integer(80), LoadBalancerPort: aws.Long(int64(80)),
InstanceProtocol: aws.String("http"), InstanceProtocol: aws.String("http"),
Protocol: aws.String("http"), Protocol: aws.String("http"),
} }
@ -224,16 +224,16 @@ func TestExpandListenersSDK(t *testing.T) {
func TestFlattenHealthCheckSDK(t *testing.T) { func TestFlattenHealthCheckSDK(t *testing.T) {
cases := []struct { cases := []struct {
Input elb.HealthCheck Input *elb.HealthCheck
Output []map[string]interface{} Output []map[string]interface{}
}{ }{
{ {
Input: elb.HealthCheck{ Input: &elb.HealthCheck{
UnhealthyThreshold: aws.Integer(10), UnhealthyThreshold: aws.Long(int64(10)),
HealthyThreshold: aws.Integer(10), HealthyThreshold: aws.Long(int64(10)),
Target: aws.String("HTTP:80/"), Target: aws.String("HTTP:80/"),
Timeout: aws.Integer(30), Timeout: aws.Long(int64(30)),
Interval: aws.Integer(30), Interval: aws.Long(int64(30)),
}, },
Output: []map[string]interface{}{ Output: []map[string]interface{}{
map[string]interface{}{ map[string]interface{}{
@ -248,7 +248,7 @@ func TestFlattenHealthCheckSDK(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
output := flattenHealthCheckSDK(&tc.Input) output := flattenHealthCheckSDK(tc.Input)
if !reflect.DeepEqual(output, tc.Output) { if !reflect.DeepEqual(output, tc.Output) {
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output) t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
} }
@ -330,9 +330,9 @@ func TestFlattenParametersSDK(t *testing.T) {
func TestExpandInstanceStringSDK(t *testing.T) { func TestExpandInstanceStringSDK(t *testing.T) {
expected := []elb.Instance{ expected := []*elb.Instance{
elb.Instance{aws.String("test-one")}, &elb.Instance{InstanceID: aws.String("test-one")},
elb.Instance{aws.String("test-two")}, &elb.Instance{InstanceID: aws.String("test-two")},
} }
ids := []interface{}{ ids := []interface{}{
@ -420,7 +420,7 @@ func TestExpandPrivateIPAddessesSDK(t *testing.T) {
func TestFlattenAttachmentSDK(t *testing.T) { func TestFlattenAttachmentSDK(t *testing.T) {
expanded := &ec2.NetworkInterfaceAttachment{ expanded := &ec2.NetworkInterfaceAttachment{
InstanceID: aws.String("i-00001"), InstanceID: aws.String("i-00001"),
DeviceIndex: aws.Long(1), DeviceIndex: aws.Long(int64(1)),
AttachmentID: aws.String("at-002"), AttachmentID: aws.String("at-002"),
} }

View File

@ -3,8 +3,8 @@ package aws
import ( import (
"log" "log"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -20,12 +20,12 @@ func setTagsELB(conn *elb.ELB, d *schema.ResourceData) error {
// Set tags // Set tags
if len(remove) > 0 { if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", remove) log.Printf("[DEBUG] Removing tags: %#v", remove)
k := make([]elb.TagKeyOnly, 0, len(remove)) k := make([]*elb.TagKeyOnly, 0, len(remove))
for _, t := range remove { for _, t := range remove {
k = append(k, elb.TagKeyOnly{Key: t.Key}) k = append(k, &elb.TagKeyOnly{Key: t.Key})
} }
_, err := conn.RemoveTags(&elb.RemoveTagsInput{ _, err := conn.RemoveTags(&elb.RemoveTagsInput{
LoadBalancerNames: []string{d.Get("name").(string)}, LoadBalancerNames: []*string{aws.String(d.Get("name").(string))},
Tags: k, Tags: k,
}) })
if err != nil { if err != nil {
@ -35,7 +35,7 @@ func setTagsELB(conn *elb.ELB, d *schema.ResourceData) error {
if len(create) > 0 { if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create) log.Printf("[DEBUG] Creating tags: %#v", create)
_, err := conn.AddTags(&elb.AddTagsInput{ _, err := conn.AddTags(&elb.AddTagsInput{
LoadBalancerNames: []string{d.Get("name").(string)}, LoadBalancerNames: []*string{aws.String(d.Get("name").(string))},
Tags: create, Tags: create,
}) })
if err != nil { if err != nil {
@ -50,7 +50,7 @@ func setTagsELB(conn *elb.ELB, d *schema.ResourceData) error {
// diffTags takes our tags locally and the ones remotely and returns // diffTags takes our tags locally and the ones remotely and returns
// the set of tags that must be created, and the set of tags that must // the set of tags that must be created, and the set of tags that must
// be destroyed. // be destroyed.
func diffTagsELB(oldTags, newTags []elb.Tag) ([]elb.Tag, []elb.Tag) { func diffTagsELB(oldTags, newTags []*elb.Tag) ([]*elb.Tag, []*elb.Tag) {
// First, we're creating everything we have // First, we're creating everything we have
create := make(map[string]interface{}) create := make(map[string]interface{})
for _, t := range newTags { for _, t := range newTags {
@ -58,7 +58,7 @@ func diffTagsELB(oldTags, newTags []elb.Tag) ([]elb.Tag, []elb.Tag) {
} }
// Build the list of what to remove // Build the list of what to remove
var remove []elb.Tag var remove []*elb.Tag
for _, t := range oldTags { for _, t := range oldTags {
old, ok := create[*t.Key] old, ok := create[*t.Key]
if !ok || old != *t.Value { if !ok || old != *t.Value {
@ -71,10 +71,10 @@ func diffTagsELB(oldTags, newTags []elb.Tag) ([]elb.Tag, []elb.Tag) {
} }
// tagsFromMap returns the tags for the given map of data. // tagsFromMap returns the tags for the given map of data.
func tagsFromMapELB(m map[string]interface{}) []elb.Tag { func tagsFromMapELB(m map[string]interface{}) []*elb.Tag {
result := make([]elb.Tag, 0, len(m)) result := make([]*elb.Tag, 0, len(m))
for k, v := range m { for k, v := range m {
result = append(result, elb.Tag{ result = append(result, &elb.Tag{
Key: aws.String(k), Key: aws.String(k),
Value: aws.String(v.(string)), Value: aws.String(v.(string)),
}) })
@ -84,7 +84,7 @@ func tagsFromMapELB(m map[string]interface{}) []elb.Tag {
} }
// tagsToMap turns the list of tags into a map. // tagsToMap turns the list of tags into a map.
func tagsToMapELB(ts []elb.Tag) map[string]string { func tagsToMapELB(ts []*elb.Tag) map[string]string {
result := make(map[string]string) result := make(map[string]string)
for _, t := range ts { for _, t := range ts {
result[*t.Key] = *t.Value result[*t.Key] = *t.Value

View File

@ -5,7 +5,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/hashicorp/aws-sdk-go/gen/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -63,7 +63,7 @@ func TestDiffELBTags(t *testing.T) {
// testAccCheckTags can be used to check the tags on a resource. // testAccCheckTags can be used to check the tags on a resource.
func testAccCheckELBTags( func testAccCheckELBTags(
ts *[]elb.Tag, key string, value string) resource.TestCheckFunc { ts *[]*elb.Tag, key string, value string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
m := tagsToMapELB(*ts) m := tagsToMapELB(*ts)
v, ok := m[key] v, ok := m[key]