From 443ffd68f292127e0932add771c3cc881a18ad49 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Sat, 2 Jul 2016 15:48:51 -0700 Subject: [PATCH] Added explicit error when SG is not working --- .../amazon/common/step_run_source_instance.go | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index 91ae1edfe..fc6d064af 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -45,19 +45,25 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi securityGroupIds := make([]*string, len(tempSecurityGroupIds)) for i, sg := range tempSecurityGroupIds { + found := false for i := 0; i < 5; i++ { - log.Printf("Describing tempSecurityGroup to ensure it is available: %s", sg) + time.Sleep(time.Duration(i) * 5 * time.Second) + log.Printf("[DEBUG] Describing tempSecurityGroup to ensure it is available: %s", sg) _, err := ec2conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{ GroupIds: []*string{aws.String(sg)}, }) if err == nil { - log.Printf("Found security group %s", sg) - break - } - log.Printf("Error in querying security group %s", err) - time.Sleep(5 * time.Second) + log.Printf("[DEBUG] Found security group %s", sg) + found = true + break + } + log.Printf("[DEBUG] Error in querying security group %s", err) + } + if found { + securityGroupIds[i] = aws.String(sg) + } else { + state.Put("error", fmt.Errorf("Timeout waiting for security group %s to become available", sg)) } - securityGroupIds[i] = aws.String(sg) } userData := s.UserData