Merge branch 'acc-temp'

This commit is contained in:
Jack Pearkes 2014-07-14 18:31:10 -04:00
commit e71bc9d5a5
4 changed files with 127 additions and 9 deletions

View File

@ -164,7 +164,7 @@ func resource_aws_autoscaling_group_diff(
"vpc_zone_identifier": diff.AttrTypeCreate,
"load_balancers": diff.AttrTypeCreate,
"availability_zone": diff.AttrTypeCreate,
"force_delete": diff.AttrTypeCreate,
"force_delete": diff.AttrTypeCreate,
},
ComputedAttrs: []string{},

View File

@ -102,11 +102,18 @@ func resource_aws_eip_destroy(
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
log.Printf("[DEBUG] EIP release (destroy) address: %v", s.ID)
var err error
if s.Attributes["vpc"] == "true" {
log.Printf("[DEBUG] EIP release (destroy) address allocation: %v", s.ID)
_, err = ec2conn.ReleaseAddress(s.ID)
return err
} else {
log.Printf("[DEBUG] EIP release (destroy) address: %v", s.ID)
_, err = ec2conn.ReleasePublicAddress(s.ID)
return err
}
_, err := ec2conn.ReleaseAddress(s.ID)
return err
return nil
}
func resource_aws_eip_refresh(

View File

@ -0,0 +1,112 @@
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/ec2"
)
func TestAccAWSEIP(t *testing.T) {
var conf ec2.Address
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEIPConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.bar", &conf),
testAccCheckAWSEIPAttributes(&conf),
),
},
},
})
}
func testAccCheckAWSEIPDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn
for _, rs := range s.Resources {
if rs.Type != "aws_eip" {
continue
}
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil)
if err == nil {
if len(describe.Addresses) != 0 &&
describe.Addresses[0].PublicIp == rs.ID {
return fmt.Errorf("EIP still exists")
}
}
// Verify the error
providerErr, ok := err.(*ec2.Error)
if !ok {
return err
}
if providerErr.Code != "InvalidAllocationID.NotFound" {
return fmt.Errorf("Unexpected error: %s", err)
}
}
return nil
}
func testAccCheckAWSEIPAttributes(conf *ec2.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
if conf.PublicIp == "" {
return fmt.Errorf("empty public_ip")
}
if conf.PrivateIpAddress != "" {
return fmt.Errorf("should not have private_ip for non-vpc")
}
return nil
}
}
func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
return fmt.Errorf("No EIP ID is set")
}
conn := testAccProvider.ec2conn
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]
return nil
}
}
const testAccAWSEIPConfig = `
resource "aws_eip" "bar" {
name = "foobar-terraform-test"
image_id = "ami-fb8e9292"
instance_type = "t1.micro"
}
`

View File

@ -42,15 +42,14 @@ func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error {
continue
}
// Try to find the Group
describeGroups, err := conn.DescribeLaunchConfigurations(
describe, err := conn.DescribeLaunchConfigurations(
&autoscaling.DescribeLaunchConfigurations{
Names: []string{rs.ID},
})
if err == nil {
if len(describeGroups.LaunchConfigurations) != 0 &&
describeGroups.LaunchConfigurations[0].Name == rs.ID {
if len(describe.LaunchConfigurations) != 0 &&
describe.LaunchConfigurations[0].Name == rs.ID {
return fmt.Errorf("Launch Configuration still exists")
}
}