From 795d53e706447535b8afe82311073e56ff9ac856 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 1 May 2015 23:33:41 +0100 Subject: [PATCH] [bugfix] Don't save instance ID if association fails - typically happens when no internet GW is available in VPC --- builtin/providers/aws/resource_aws_eip.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_eip.go b/builtin/providers/aws/resource_aws_eip.go index f871e764d..d8e802704 100644 --- a/builtin/providers/aws/resource_aws_eip.go +++ b/builtin/providers/aws/resource_aws_eip.go @@ -140,7 +140,9 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error { address := describeAddresses.Addresses[0] d.Set("association_id", address.AssociationID) - d.Set("instance", address.InstanceID) + if address.InstanceID != nil { + d.Set("instance", address.InstanceID) + } d.Set("private_ip", address.PrivateIPAddress) d.Set("public_ip", address.PublicIP) @@ -173,6 +175,9 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] EIP associate configuration: %#v (domain: %v)", assocOpts, domain) _, err := ec2conn.AssociateAddress(assocOpts) if err != nil { + // Prevent saving instance if association failed + // e.g. missing internet gateway in VPC + d.Set("instance", "") return fmt.Errorf("Failure associating instances: %s", err) } }