Commit 61320b20 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/common: error if WaitForState can't find resource

repeatably
parent 1bf91e28
......@@ -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]
......
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment