rewrite to not use private aws package

This commit is contained in:
Matthew Hooker 2016-11-01 18:29:18 -07:00
parent c4c46c349e
commit d47e47cf1f
1 changed files with 14 additions and 29 deletions

View File

@ -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
}
w := waiter.Waiter{
Client: c,
Input: input,
Config: waiterCfg,
return nil
}
return w.Wait()
return fmt.Errorf("timed out")
}