From 7c56148f95bc8599cb1608a718e2a701df73073d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 Sep 2013 20:37:14 -0700 Subject: [PATCH] builder/amazon/common: error if WaitForState can't find resource repeatably --- CHANGELOG.md | 2 ++ builder/amazon/common/state.go | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dfb440ad..8a0b4700b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ IMPROVEMENTS: BUG FIXES: * builder/amazon/*: While waiting for AMI, will detect "failed" state. +* builder/amazon/*: Waiting for state will detect if the resource (AMI, + instance, etc.) disappears from under it. * provisioner/puppet-masterless: Fix failure case when both facter vars are used and prevent_sudo. [GH-415] diff --git a/builder/amazon/common/state.go b/builder/amazon/common/state.go index 2dedfb3a0..1e9dea36b 100644 --- a/builder/amazon/common/state.go +++ b/builder/amazon/common/state.go @@ -82,6 +82,8 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc { func WaitForState(conf *StateChangeConf) (i interface{}, err error) { log.Printf("Waiting for state to become: %s", conf.Target) + notfoundTick := 0 + for { var currentState string i, currentState, err = conf.Refresh() @@ -89,9 +91,17 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) { return } - // Check states only if we were able to refresh to an instance - // that exists. - if i != nil { + if i == nil { + // 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 { + return nil, errors.New("couldn't find resource") + } + } else { + // Reset the counter for when a resource isn't found + notfoundTick = 0 + if currentState == conf.Target { return }