From b386717381fab073b027473a56b4df96de5fed7c Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Mon, 14 Jul 2014 17:59:08 -0400 Subject: [PATCH] providers/aws: basic eip structure --- .../aws/resource_aws_autoscaling_group.go | 2 +- .../providers/aws/resource_aws_eip_test.go | 117 ++++++++++++++++++ .../resource_aws_launch_configuration_test.go | 7 +- 3 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 builtin/providers/aws/resource_aws_eip_test.go diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 190ee1073..0da567389 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -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{}, diff --git a/builtin/providers/aws/resource_aws_eip_test.go b/builtin/providers/aws/resource_aws_eip_test.go new file mode 100644 index 000000000..fa5f6e5c6 --- /dev/null +++ b/builtin/providers/aws/resource_aws_eip_test.go @@ -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" +} +` diff --git a/builtin/providers/aws/resource_aws_launch_configuration_test.go b/builtin/providers/aws/resource_aws_launch_configuration_test.go index 00cb10643..2126671b6 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration_test.go +++ b/builtin/providers/aws/resource_aws_launch_configuration_test.go @@ -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") } }