diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index 0e8e980ec..4d7df8dd8 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -9,7 +9,6 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/private/waiter" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mitchellh/multistep" @@ -46,17 +45,19 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi securityGroupIds := make([]*string, len(tempSecurityGroupIds)) for i, sg := range tempSecurityGroupIds { + log.Printf("[DEBUG] Waiting for tempSecurityGroup: %s", sg) err := WaitUntilSecurityGroupExists(ec2conn, &ec2.DescribeSecurityGroupsInput{ GroupIds: []*string{aws.String(sg)}, }, ) - if err != nil { + if err == nil { log.Printf("[DEBUG] Found security group %s", sg) securityGroupIds[i] = aws.String(sg) } else { - log.Printf("[DEBUG] Error in querying security group %s", err) - state.Put("error", fmt.Errorf("Timeout waiting for security group %s to become available", sg)) + err := fmt.Errorf("Timed out waiting for security group %s", sg) + log.Printf("[DEBUG] %s", err.Error()) + state.Put("error", err) return multistep.ActionHalt } } @@ -360,30 +361,14 @@ func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) { } func WaitUntilSecurityGroupExists(c *ec2.EC2, input *ec2.DescribeSecurityGroupsInput) error { - waiterCfg := waiter.Config{ - Operation: "DescribeSecurityGroups", - Delay: 15, - MaxAttempts: 40, - Acceptors: []waiter.WaitAcceptor{ - { - State: "success", - Matcher: "path", - Argument: "lenth(SecurityGroups[]) > `0`", - Expected: "true", - }, - { - State: "failure", - Matcher: "error", - Argument: "", - Expected: "InvalidSecurityGroupID.NotFound", - }, - }, + for i := 0; i < 40; i++ { + _, err := c.DescribeSecurityGroups(input) + if err != nil { + log.Printf("[DEBUG] Error querying security group %s: %s", input.GroupIds, err) + time.Sleep(15 * time.Second) + continue + } + return nil } - - w := waiter.Waiter{ - Client: c, - Input: input, - Config: waiterCfg, - } - return w.Wait() + return fmt.Errorf("timed out") }