providers/aws: retry delete of eip [GH-276]
This commit is contained in:
parent
57f287c06d
commit
62e2743dcc
|
@ -16,6 +16,8 @@ BUG FIXES:
|
||||||
* providers/aws: Refreshing EIP from pre-0.2 state file won't error. [GH-258]
|
* providers/aws: Refreshing EIP from pre-0.2 state file won't error. [GH-258]
|
||||||
* providers/aws: Creating EIP without an instance/network won't fail.
|
* providers/aws: Creating EIP without an instance/network won't fail.
|
||||||
* providers/aws: Refreshing EIP manually deleted works.
|
* providers/aws: Refreshing EIP manually deleted works.
|
||||||
|
* providers/aws: Retry EIP delete to allow AWS eventual consistency to
|
||||||
|
detect it isn't attached. [GH-276]
|
||||||
* providers/digitalocean: Handle situations when resource was destroyed
|
* providers/digitalocean: Handle situations when resource was destroyed
|
||||||
manually. [GH-279]
|
manually. [GH-279]
|
||||||
* providers/digitalocean: Fix a couple scenarios where the diff was
|
* providers/digitalocean: Fix a couple scenarios where the diff was
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
//"github.com/hashicorp/terraform/terraform"
|
//"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
"github.com/mitchellh/goamz/ec2"
|
||||||
|
@ -125,20 +127,14 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
p := meta.(*ResourceProvider)
|
stateConf := &resource.StateChangeConf{
|
||||||
ec2conn := p.ec2conn
|
Pending: []string{"pending"},
|
||||||
|
Target: "destroyed",
|
||||||
domain := resourceAwsEipDomain(d)
|
Refresh: resourceEipDeleteRefreshFunc(d, meta),
|
||||||
|
Timeout: 3 * time.Minute,
|
||||||
var err error
|
MinTimeout: 1 * time.Second,
|
||||||
if domain == "vpc" {
|
|
||||||
log.Printf("[DEBUG] EIP release (destroy) address allocation: %v", d.Id())
|
|
||||||
_, err = ec2conn.ReleaseAddress(d.Id())
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
_, err := stateConf.WaitForState()
|
||||||
log.Printf("[DEBUG] EIP release (destroy) address: %v", d.Id())
|
|
||||||
_, err = ec2conn.ReleasePublicAddress(d.Id())
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,3 +196,38 @@ func resourceAwsEipDomain(d *schema.ResourceData) string {
|
||||||
|
|
||||||
return "standard"
|
return "standard"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceEipDeleteRefreshFunc(
|
||||||
|
d *schema.ResourceData,
|
||||||
|
meta interface{}) resource.StateRefreshFunc {
|
||||||
|
p := meta.(*ResourceProvider)
|
||||||
|
ec2conn := p.ec2conn
|
||||||
|
domain := resourceAwsEipDomain(d)
|
||||||
|
|
||||||
|
return func() (interface{}, string, error) {
|
||||||
|
var err error
|
||||||
|
if domain == "vpc" {
|
||||||
|
log.Printf(
|
||||||
|
"[DEBUG] EIP release (destroy) address allocation: %v",
|
||||||
|
d.Id())
|
||||||
|
_, err = ec2conn.ReleaseAddress(d.Id())
|
||||||
|
} else {
|
||||||
|
log.Printf("[DEBUG] EIP release (destroy) address: %v", d.Id())
|
||||||
|
_, err = ec2conn.ReleasePublicAddress(d.Id())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return d, "destroyed", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ec2err, ok := err.(*ec2.Error)
|
||||||
|
if !ok {
|
||||||
|
return d, "error", err
|
||||||
|
}
|
||||||
|
if ec2err.Code != "InvalidIPAddress.InUse" {
|
||||||
|
return d, "error", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return d, "pending", nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue