provider/aws: Convert EIP to use upstream aws-sdk-go

This commit is contained in:
Clint Shryock 2015-04-07 10:37:17 -05:00
parent 0fbbd1195a
commit a15547b955
2 changed files with 33 additions and 33 deletions

View File

@ -6,8 +6,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -60,7 +60,7 @@ func resourceAwsEip() *schema.Resource {
} }
func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2SDKconn
// By default, we're not in a VPC // By default, we're not in a VPC
domainOpt := "" domainOpt := ""
@ -68,7 +68,7 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
domainOpt = "vpc" domainOpt = "vpc"
} }
allocOpts := &ec2.AllocateAddressRequest{ allocOpts := &ec2.AllocateAddressInput{
Domain: aws.String(domainOpt), Domain: aws.String(domainOpt),
} }
@ -97,24 +97,24 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2SDKconn
domain := resourceAwsEipDomain(d) domain := resourceAwsEipDomain(d)
id := d.Id() id := d.Id()
assocIds := []string{} assocIds := []*string{}
publicIps := []string{} publicIps := []*string{}
if domain == "vpc" { if domain == "vpc" {
assocIds = []string{id} assocIds = []*string{aws.String(id)}
} else { } else {
publicIps = []string{id} publicIps = []*string{aws.String(id)}
} }
log.Printf( log.Printf(
"[DEBUG] EIP describe configuration: %#v, %#v (domain: %s)", "[DEBUG] EIP describe configuration: %#v, %#v (domain: %s)",
assocIds, publicIps, domain) assocIds, publicIps, domain)
req := &ec2.DescribeAddressesRequest{ req := &ec2.DescribeAddressesInput{
AllocationIDs: assocIds, AllocationIDs: assocIds,
PublicIPs: publicIps, PublicIPs: publicIps,
} }
@ -148,7 +148,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2SDKconn
domain := resourceAwsEipDomain(d) domain := resourceAwsEipDomain(d)
@ -156,14 +156,14 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("instance"); ok { if v, ok := d.GetOk("instance"); ok {
instanceId := v.(string) instanceId := v.(string)
assocOpts := &ec2.AssociateAddressRequest{ assocOpts := &ec2.AssociateAddressInput{
InstanceID: aws.String(instanceId), InstanceID: aws.String(instanceId),
PublicIP: aws.String(d.Id()), PublicIP: aws.String(d.Id()),
} }
// more unique ID conditionals // more unique ID conditionals
if domain == "vpc" { if domain == "vpc" {
assocOpts = &ec2.AssociateAddressRequest{ assocOpts = &ec2.AssociateAddressInput{
InstanceID: aws.String(instanceId), InstanceID: aws.String(instanceId),
AllocationID: aws.String(d.Id()), AllocationID: aws.String(d.Id()),
PublicIP: aws.String(""), PublicIP: aws.String(""),
@ -181,7 +181,7 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2SDKconn
if err := resourceAwsEipRead(d, meta); err != nil { if err := resourceAwsEipRead(d, meta); err != nil {
return err return err
@ -197,11 +197,11 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
var err error var err error
switch resourceAwsEipDomain(d) { switch resourceAwsEipDomain(d) {
case "vpc": case "vpc":
err = ec2conn.DisassociateAddress(&ec2.DisassociateAddressRequest{ _, err = ec2conn.DisassociateAddress(&ec2.DisassociateAddressInput{
AssociationID: aws.String(d.Get("association_id").(string)), AssociationID: aws.String(d.Get("association_id").(string)),
}) })
case "standard": case "standard":
err = ec2conn.DisassociateAddress(&ec2.DisassociateAddressRequest{ _, err = ec2conn.DisassociateAddress(&ec2.DisassociateAddressInput{
PublicIP: aws.String(d.Get("public_ip").(string)), PublicIP: aws.String(d.Get("public_ip").(string)),
}) })
} }
@ -218,12 +218,12 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf( log.Printf(
"[DEBUG] EIP release (destroy) address allocation: %v", "[DEBUG] EIP release (destroy) address allocation: %v",
d.Id()) d.Id())
err = ec2conn.ReleaseAddress(&ec2.ReleaseAddressRequest{ _, err = ec2conn.ReleaseAddress(&ec2.ReleaseAddressInput{
AllocationID: aws.String(d.Id()), AllocationID: aws.String(d.Id()),
}) })
case "standard": case "standard":
log.Printf("[DEBUG] EIP release (destroy) address: %v", d.Id()) log.Printf("[DEBUG] EIP release (destroy) address: %v", d.Id())
err = ec2conn.ReleaseAddress(&ec2.ReleaseAddressRequest{ _, err = ec2conn.ReleaseAddress(&ec2.ReleaseAddressInput{
PublicIP: aws.String(d.Id()), PublicIP: aws.String(d.Id()),
}) })
} }

View File

@ -5,8 +5,8 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -58,16 +58,16 @@ func TestAccAWSEIP_instance(t *testing.T) {
} }
func testAccCheckAWSEIPDestroy(s *terraform.State) error { func testAccCheckAWSEIPDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_eip" { if rs.Type != "aws_eip" {
continue continue
} }
req := &ec2.DescribeAddressesRequest{ req := &ec2.DescribeAddressesInput{
AllocationIDs: []string{}, AllocationIDs: []*string{},
PublicIPs: []string{rs.Primary.ID}, PublicIPs: []*string{aws.String(rs.Primary.ID)},
} }
describe, err := conn.DescribeAddresses(req) describe, err := conn.DescribeAddresses(req)
@ -113,12 +113,12 @@ func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc
return fmt.Errorf("No EIP ID is set") return fmt.Errorf("No EIP ID is set")
} }
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
if strings.Contains(rs.Primary.ID, "eipalloc") { if strings.Contains(rs.Primary.ID, "eipalloc") {
req := &ec2.DescribeAddressesRequest{ req := &ec2.DescribeAddressesInput{
AllocationIDs: []string{rs.Primary.ID}, AllocationIDs: []*string{aws.String(rs.Primary.ID)},
PublicIPs: []string{}, PublicIPs: []*string{},
} }
describe, err := conn.DescribeAddresses(req) describe, err := conn.DescribeAddresses(req)
if err != nil { if err != nil {
@ -129,12 +129,12 @@ func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc
*describe.Addresses[0].AllocationID != rs.Primary.ID { *describe.Addresses[0].AllocationID != rs.Primary.ID {
return fmt.Errorf("EIP not found") return fmt.Errorf("EIP not found")
} }
*res = describe.Addresses[0] *res = *describe.Addresses[0]
} else { } else {
req := &ec2.DescribeAddressesRequest{ req := &ec2.DescribeAddressesInput{
AllocationIDs: []string{}, AllocationIDs: []*string{},
PublicIPs: []string{rs.Primary.ID}, PublicIPs: []*string{aws.String(rs.Primary.ID)},
} }
describe, err := conn.DescribeAddresses(req) describe, err := conn.DescribeAddresses(req)
if err != nil { if err != nil {
@ -145,7 +145,7 @@ func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc
*describe.Addresses[0].PublicIP != rs.Primary.ID { *describe.Addresses[0].PublicIP != rs.Primary.ID {
return fmt.Errorf("EIP not found") return fmt.Errorf("EIP not found")
} }
*res = describe.Addresses[0] *res = *describe.Addresses[0]
} }
return nil return nil