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