provider/aws: Fixing EIP in EC2-VPC
This commit is contained in:
parent
9523b22e49
commit
ebd50ab6ff
|
@ -3,6 +3,7 @@ package aws
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/config"
|
||||
"github.com/hashicorp/terraform/helper/diff"
|
||||
|
@ -43,8 +44,11 @@ func resource_aws_eip_create(
|
|||
// the EIP api has a conditional unique ID (really), so
|
||||
// if we're in a VPC we need to save the ID as such, otherwise
|
||||
// it defaults to using the public IP
|
||||
if vpc {
|
||||
log.Printf("[DEBUG] EIP Allocate: %#v", allocResp)
|
||||
if allocResp.AllocationId != "" {
|
||||
rs.ID = allocResp.AllocationId
|
||||
rs.Attributes["vpc"] = "true"
|
||||
|
||||
} else {
|
||||
rs.ID = allocResp.PublicIp
|
||||
}
|
||||
|
@ -65,7 +69,7 @@ func resource_aws_eip_update(
|
|||
// properly.
|
||||
rs := s.MergeDiff(d)
|
||||
|
||||
vpc := rs.Attributes["vpc"] == "true"
|
||||
vpc := strings.Contains(rs.ID, "eipalloc")
|
||||
|
||||
// If we have an instance to register, do it
|
||||
instanceId := rs.Attributes["instance"]
|
||||
|
@ -82,6 +86,7 @@ func resource_aws_eip_update(
|
|||
assocOpts = ec2.AssociateAddress{
|
||||
InstanceId: instanceId,
|
||||
AllocationId: rs.ID,
|
||||
PublicIp: "",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +112,7 @@ func resource_aws_eip_destroy(
|
|||
ec2conn := p.ec2conn
|
||||
|
||||
var err error
|
||||
if s.Attributes["vpc"] == "true" {
|
||||
if strings.Contains(s.ID, "eipalloc") {
|
||||
log.Printf("[DEBUG] EIP release (destroy) address allocation: %v", s.ID)
|
||||
_, err = ec2conn.ReleaseAddress(s.ID)
|
||||
return err
|
||||
|
|
|
@ -2,6 +2,7 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
|
@ -113,19 +114,31 @@ func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc
|
|||
|
||||
conn := testAccProvider.ec2conn
|
||||
|
||||
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil)
|
||||
if strings.Contains(rs.ID, "eipalloc") {
|
||||
describe, err := conn.Addresses([]string{}, []string{rs.ID}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
if len(describe.Addresses) != 1 ||
|
||||
describe.Addresses[0].AllocationId != rs.ID {
|
||||
return fmt.Errorf("EIP not found")
|
||||
}
|
||||
*res = describe.Addresses[0]
|
||||
|
||||
} else {
|
||||
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(describe.Addresses) != 1 ||
|
||||
describe.Addresses[0].PublicIp != rs.ID {
|
||||
return fmt.Errorf("EIP not found")
|
||||
}
|
||||
*res = describe.Addresses[0]
|
||||
}
|
||||
|
||||
if len(describe.Addresses) != 1 ||
|
||||
describe.Addresses[0].PublicIp != rs.ID {
|
||||
return fmt.Errorf("EIP not found")
|
||||
}
|
||||
|
||||
*res = describe.Addresses[0]
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue