providers/aws: tests for eip
This commit is contained in:
parent
b386717381
commit
1bcdba6f84
|
@ -102,11 +102,18 @@ func resource_aws_eip_destroy(
|
||||||
p := meta.(*ResourceProvider)
|
p := meta.(*ResourceProvider)
|
||||||
ec2conn := p.ec2conn
|
ec2conn := p.ec2conn
|
||||||
|
|
||||||
log.Printf("[DEBUG] EIP release (destroy) address: %v", s.ID)
|
var err error
|
||||||
|
if s.Attributes["vpc"] == "true" {
|
||||||
_, err := ec2conn.ReleaseAddress(s.ID)
|
log.Printf("[DEBUG] EIP release (destroy) address allocation: %v", s.ID)
|
||||||
|
_, err = ec2conn.ReleaseAddress(s.ID)
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
log.Printf("[DEBUG] EIP release (destroy) address: %v", s.ID)
|
||||||
|
_, err = ec2conn.ReleasePublicAddress(s.ID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resource_aws_eip_refresh(
|
func resource_aws_eip_refresh(
|
||||||
|
|
|
@ -34,12 +34,13 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error {
|
||||||
for _, rs := range s.Resources {
|
for _, rs := range s.Resources {
|
||||||
if rs.Type != "aws_eip" {
|
if rs.Type != "aws_eip" {
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
describe, err := ec2conn.Addresses([]string{}, []string{rs.ID}, nil)
|
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(describeGroups.EIPs) != 0 &&
|
if len(describe.Addresses) != 0 &&
|
||||||
describeGroups.EIPs[0].Name == rs.ID {
|
describe.Addresses[0].PublicIp == rs.ID {
|
||||||
return fmt.Errorf("EIP still exists")
|
return fmt.Errorf("EIP still exists")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +50,9 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error {
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if providerErr.Code != "InvalidEIP.NotFound" {
|
|
||||||
return err
|
if providerErr.Code != "InvalidAllocationID.NotFound" {
|
||||||
|
return fmt.Errorf("Unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,19 +65,15 @@ func testAccCheckAWSEIPAttributes(conf *ec2.Address) resource.TestCheckFunc {
|
||||||
return fmt.Errorf("empty public_ip")
|
return fmt.Errorf("empty public_ip")
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.PrivateIpAddress == "" {
|
if conf.PrivateIpAddress != "" {
|
||||||
return fmt.Errorf("empty private_ip")
|
return fmt.Errorf("should not have private_ip for non-vpc")
|
||||||
}
|
|
||||||
|
|
||||||
if conf.InstanceId == "" {
|
|
||||||
return fmt.Errorf("empty instance_id")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSEIPExists(n string, res *ec2.EIP) resource.TestCheckFunc {
|
func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.Resources[n]
|
rs, ok := s.Resources[n]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -88,21 +86,18 @@ func testAccCheckAWSEIPExists(n string, res *ec2.EIP) resource.TestCheckFunc {
|
||||||
|
|
||||||
conn := testAccProvider.ec2conn
|
conn := testAccProvider.ec2conn
|
||||||
|
|
||||||
describeOpts := ec2.DescribeEIPs{
|
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil)
|
||||||
Names: []string{rs.ID},
|
|
||||||
}
|
|
||||||
describe, err := conn.DescribeEIPs(&describeOpts)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(describe.EIPs) != 1 ||
|
if len(describe.Addresses) != 1 ||
|
||||||
describe.EIPs[0].Name != rs.ID {
|
describe.Addresses[0].PublicIp != rs.ID {
|
||||||
return fmt.Errorf("EIP Group not found")
|
return fmt.Errorf("EIP not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*res = describe.EIPs[0]
|
*res = describe.Addresses[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue