From c180487af621c66ed801bd871c0aa419907aa3ac Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Thu, 26 Feb 2015 09:59:42 -0800 Subject: [PATCH 1/2] helper/resource: allow configuration of not found checks in state change --- helper/resource/state.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/helper/resource/state.go b/helper/resource/state.go index 8c5ec4b273..7a71f11546 100644 --- a/helper/resource/state.go +++ b/helper/resource/state.go @@ -22,12 +22,13 @@ type StateRefreshFunc func() (result interface{}, state string, err error) // StateChangeConf is the configuration struct used for `WaitForState`. type StateChangeConf struct { - Delay time.Duration // Wait this time before starting checks - Pending []string // States that are "allowed" and will continue trying - Refresh StateRefreshFunc // Refreshes the current state - Target string // Target state - Timeout time.Duration // The amount of time to wait before timeout - MinTimeout time.Duration // Smallest time to wait before refreshes + Delay time.Duration // Wait this time before starting checks + Pending []string // States that are "allowed" and will continue trying + Refresh StateRefreshFunc // Refreshes the current state + Target string // Target state + Timeout time.Duration // The amount of time to wait before timeout + MinTimeout time.Duration // Smallest time to wait before refreshes + NotFoundChecks int // Number of times to allow not found } // WaitForState watches an object and waits for it to achieve the state @@ -38,6 +39,11 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) { notfoundTick := 0 + // Set a default for times to check for not found + if conf.NotFoundChecks == 0 { + conf.NotFoundChecks = 20 + } + var result interface{} var resulterr error @@ -78,7 +84,7 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) { // If we didn't find the resource, check if we have been // not finding it for awhile, and if so, report an error. notfoundTick += 1 - if notfoundTick > 20 { + if notfoundTick > conf.NotFoundChecks { resulterr = errors.New("couldn't find resource") return } From 8ab4d37f7cfcd167038f9d1db2c4b6a09e2f10a6 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Thu, 26 Feb 2015 10:00:25 -0800 Subject: [PATCH 2/2] providers/digitalocean: be more lenient for droplets 404ing on creation --- .../providers/digitalocean/resource_digitalocean_droplet.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index ac929d2385..f178cc3915 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -366,6 +366,11 @@ func WaitForDropletAttribute( Timeout: 60 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, + + // This is a hack around DO API strangeness. + // https://github.com/hashicorp/terraform/issues/481 + // + NotFoundChecks: 60, } return stateConf.WaitForState()