[bugfix] Don't save instance ID if association fails

- typically happens when no internet GW is available in VPC
This commit is contained in:
Radek Simko 2015-05-01 23:33:41 +01:00
parent 15c75c501f
commit 795d53e706
1 changed files with 6 additions and 1 deletions

View File

@ -140,7 +140,9 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
address := describeAddresses.Addresses[0] address := describeAddresses.Addresses[0]
d.Set("association_id", address.AssociationID) 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("private_ip", address.PrivateIPAddress)
d.Set("public_ip", address.PublicIP) 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) log.Printf("[DEBUG] EIP associate configuration: %#v (domain: %v)", assocOpts, domain)
_, err := ec2conn.AssociateAddress(assocOpts) _, err := ec2conn.AssociateAddress(assocOpts)
if err != nil { 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) return fmt.Errorf("Failure associating instances: %s", err)
} }
} }