providers/aws: basic eip structure

This commit is contained in:
Jack Pearkes 2014-07-14 17:59:08 -04:00
parent ac0168df68
commit b386717381
3 changed files with 121 additions and 5 deletions

View File

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

View File

@ -0,0 +1,117 @@
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 := ec2conn.Addresses([]string{}, []string{rs.ID}, nil)
if err == nil {
if len(describeGroups.EIPs) != 0 &&
describeGroups.EIPs[0].Name == rs.ID {
return fmt.Errorf("EIP still exists")
}
}
// Verify the error
providerErr, ok := err.(*ec2.Error)
if !ok {
return err
}
if providerErr.Code != "InvalidEIP.NotFound" {
return 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("empty private_ip")
}
if conf.InstanceId == "" {
return fmt.Errorf("empty instance_id")
}
return nil
}
}
func testAccCheckAWSEIPExists(n string, res *ec2.EIP) 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
describeOpts := ec2.DescribeEIPs{
Names: []string{rs.ID},
}
describe, err := conn.DescribeEIPs(&describeOpts)
if err != nil {
return err
}
if len(describe.EIPs) != 1 ||
describe.EIPs[0].Name != rs.ID {
return fmt.Errorf("EIP Group not found")
}
*res = describe.EIPs[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 continue
} }
// Try to find the Group describe, err := conn.DescribeLaunchConfigurations(
describeGroups, err := conn.DescribeLaunchConfigurations(
&autoscaling.DescribeLaunchConfigurations{ &autoscaling.DescribeLaunchConfigurations{
Names: []string{rs.ID}, Names: []string{rs.ID},
}) })
if err == nil { if err == nil {
if len(describeGroups.LaunchConfigurations) != 0 && if len(describe.LaunchConfigurations) != 0 &&
describeGroups.LaunchConfigurations[0].Name == rs.ID { describe.LaunchConfigurations[0].Name == rs.ID {
return fmt.Errorf("Launch Configuration still exists") return fmt.Errorf("Launch Configuration still exists")
} }
} }