Merge pull request #1408 from hashicorp/f-aws-upstream-eip

provider/aws: Convert EIP to use upstream aws-sdk-go
This commit is contained in:
Clint 2015-04-08 15:51:18 -05:00
commit 8e25dcd4f6
2 changed files with 33 additions and 33 deletions

View File

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

View File

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