Merge pull request #1532 from hashicorp/f-aws-upstream-elb

providers/aws: Conver AWS ELB to upstream
This commit is contained in:
Clint 2015-04-15 14:16:24 -05:00
commit 220f62eb72
7 changed files with 117 additions and 105 deletions

View File

@ -6,10 +6,10 @@ import (
"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/gen/autoscaling"
"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/rds"
"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")
creds := aws.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
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")
client.autoscalingconn = autoscaling.New(creds, c.Region, nil)
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.iamconn = iam.New(creds, c.Region, nil)
sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
client.ec2SDKconn = awsEC2.New(&awsSDK.Config{
Credentials: sdkCreds,
Region: c.Region,

View File

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

View File

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

View File

@ -5,24 +5,24 @@ import (
"github.com/awslabs/aws-sdk-go/aws"
"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/terraform/helper/schema"
)
// Takes the result of flatmap.Expand for an array of listeners and
// returns ELB API compatible objects
func expandListenersSDK(configured []interface{}) ([]elb.Listener, error) {
listeners := make([]elb.Listener, 0, len(configured))
func expandListenersSDK(configured []interface{}) ([]*elb.Listener, error) {
listeners := make([]*elb.Listener, 0, len(configured))
// Loop over our configured listeners and create
// an array of aws-sdk-go compatabile objects
for _, lRaw := range configured {
data := lRaw.(map[string]interface{})
ip := data["instance_port"].(int)
lp := data["lb_port"].(int)
l := elb.Listener{
ip := int64(data["instance_port"].(int))
lp := int64(data["lb_port"].(int))
l := &elb.Listener{
InstancePort: &ip,
InstanceProtocol: aws.String(data["instance_protocol"].(string)),
LoadBalancerPort: &lp,
@ -152,7 +152,7 @@ func flattenSecurityGroupsSDK(list []*ec2.UserIDGroupPair) []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))
for _, i := range list {
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
func expandInstanceStringSDK(list []interface{}) []elb.Instance {
result := make([]elb.Instance, 0, len(list))
func expandInstanceStringSDK(list []interface{}) []*elb.Instance {
result := make([]*elb.Instance, 0, len(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
}
// 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))
for _, i := range list {
l := map[string]interface{}{

View File

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

View File

@ -3,8 +3,8 @@ package aws
import (
"log"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/elb"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/schema"
)
@ -20,12 +20,12 @@ func setTagsELB(conn *elb.ELB, d *schema.ResourceData) error {
// Set tags
if len(remove) > 0 {
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 {
k = append(k, elb.TagKeyOnly{Key: t.Key})
k = append(k, &elb.TagKeyOnly{Key: t.Key})
}
_, err := conn.RemoveTags(&elb.RemoveTagsInput{
LoadBalancerNames: []string{d.Get("name").(string)},
LoadBalancerNames: []*string{aws.String(d.Get("name").(string))},
Tags: k,
})
if err != nil {
@ -35,7 +35,7 @@ func setTagsELB(conn *elb.ELB, d *schema.ResourceData) error {
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create)
_, err := conn.AddTags(&elb.AddTagsInput{
LoadBalancerNames: []string{d.Get("name").(string)},
LoadBalancerNames: []*string{aws.String(d.Get("name").(string))},
Tags: create,
})
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
// the set of tags that must be created, and the set of tags that must
// 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
create := make(map[string]interface{})
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
var remove []elb.Tag
var remove []*elb.Tag
for _, t := range oldTags {
old, ok := create[*t.Key]
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.
func tagsFromMapELB(m map[string]interface{}) []elb.Tag {
result := make([]elb.Tag, 0, len(m))
func tagsFromMapELB(m map[string]interface{}) []*elb.Tag {
result := make([]*elb.Tag, 0, len(m))
for k, v := range m {
result = append(result, elb.Tag{
result = append(result, &elb.Tag{
Key: aws.String(k),
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.
func tagsToMapELB(ts []elb.Tag) map[string]string {
func tagsToMapELB(ts []*elb.Tag) map[string]string {
result := make(map[string]string)
for _, t := range ts {
result[*t.Key] = *t.Value

View File

@ -5,7 +5,7 @@ import (
"reflect"
"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/terraform"
)
@ -63,7 +63,7 @@ func TestDiffELBTags(t *testing.T) {
// testAccCheckTags can be used to check the tags on a resource.
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 {
m := tagsToMapELB(*ts)
v, ok := m[key]