diff --git a/TODO.md b/TODO.md index 4323a49d7..726a87b42 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,4 @@ This is just to keep track of what we need to do in the short term. * Configuration schemas for providers and provisioners * Helper improvements around complex types perhaps * Providers/AWS: `aws_security_group` needs an update func - * Providers/AWS: `aws_eip` needs an update func (re-assocation, I think this - is possible in the AWS API). `aws_eip` also needs improved tests * Providers/AWS: `aws_rds` needs an update func (+goamz changes) diff --git a/builtin/providers/aws/resource_aws_eip.go b/builtin/providers/aws/resource_aws_eip.go index 2410aeee5..c32e41c17 100644 --- a/builtin/providers/aws/resource_aws_eip.go +++ b/builtin/providers/aws/resource_aws_eip.go @@ -51,6 +51,22 @@ func resource_aws_eip_create( log.Printf("[INFO] EIP ID: %s (vpc: %v)", rs.ID, vpc) + return resource_aws_eip_update(rs, d, meta) +} + +func resource_aws_eip_update( + s *terraform.ResourceState, + d *terraform.ResourceDiff, + meta interface{}) (*terraform.ResourceState, error) { + p := meta.(*ResourceProvider) + ec2conn := p.ec2conn + + // Merge the diff into the state so that we have all the attributes + // properly. + rs := s.MergeDiff(d) + + vpc := rs.Attributes["vpc"] == "true" + // If we have an instance to register, do it instanceId := rs.Attributes["instance"] @@ -60,6 +76,7 @@ func resource_aws_eip_create( InstanceId: instanceId, PublicIp: rs.ID, } + // more unique ID conditionals if vpc { assocOpts = ec2.AssociateAddress{ @@ -70,7 +87,6 @@ func resource_aws_eip_create( log.Printf("[DEBUG] EIP associate configuration: %#v (vpc: %v)", assocOpts, vpc) _, err := ec2conn.AssociateAddress(&assocOpts) - if err != nil { return rs, fmt.Errorf("Failure associating instances: %s", err) } @@ -84,19 +100,6 @@ func resource_aws_eip_create( return resource_aws_eip_update_state(rs, address) } -func resource_aws_eip_update( - s *terraform.ResourceState, - d *terraform.ResourceDiff, - meta interface{}) (*terraform.ResourceState, error) { - - rs := s.MergeDiff(d) - log.Printf("ResourceDiff: %s", d) - log.Printf("ResourceState: %s", s) - log.Printf("Merged: %s", rs) - - return nil, fmt.Errorf("Did not update") -} - func resource_aws_eip_destroy( s *terraform.ResourceState, meta interface{}) error { diff --git a/builtin/providers/aws/resource_aws_eip_test.go b/builtin/providers/aws/resource_aws_eip_test.go index e42ff2047..6e6f1fd91 100644 --- a/builtin/providers/aws/resource_aws_eip_test.go +++ b/builtin/providers/aws/resource_aws_eip_test.go @@ -9,7 +9,7 @@ import ( "github.com/mitchellh/goamz/ec2" ) -func TestAccAWSEIP(t *testing.T) { +func TestAccAWSEIP_normal(t *testing.T) { var conf ec2.Address resource.Test(t, resource.TestCase{ @@ -28,6 +28,33 @@ func TestAccAWSEIP(t *testing.T) { }) } +func TestAccAWSEIP_instance(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: testAccAWSEIPInstanceConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEIPExists("aws_eip.bar", &conf), + testAccCheckAWSEIPAttributes(&conf), + ), + }, + + resource.TestStep{ + Config: testAccAWSEIPInstanceConfig2, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEIPExists("aws_eip.bar", &conf), + testAccCheckAWSEIPAttributes(&conf), + ), + }, + }, + }) +} + func testAccCheckAWSEIPDestroy(s *terraform.State) error { conn := testAccProvider.ec2conn @@ -107,3 +134,27 @@ const testAccAWSEIPConfig = ` resource "aws_eip" "bar" { } ` + +const testAccAWSEIPInstanceConfig = ` +resource "aws_instance" "foo" { + # us-west-2 + ami = "ami-4fccb37f" + instance_type = "m1.small" +} + +resource "aws_eip" "bar" { + instance = "${aws_instance.foo.id}" +} +` + +const testAccAWSEIPInstanceConfig2 = ` +resource "aws_instance" "bar" { + # us-west-2 + ami = "ami-4fccb37f" + instance_type = "m1.small" +} + +resource "aws_eip" "bar" { + instance = "${aws_instance.bar.id}" +} +` diff --git a/builtin/providers/aws/resources.go b/builtin/providers/aws/resources.go index f03689b14..a2c81b479 100644 --- a/builtin/providers/aws/resources.go +++ b/builtin/providers/aws/resources.go @@ -45,6 +45,7 @@ func init() { Destroy: resource_aws_eip_destroy, Diff: resource_aws_eip_diff, Refresh: resource_aws_eip_refresh, + Update: resource_aws_eip_update, }, "aws_elb": resource.Resource{