rewrite to not use private aws package
This commit is contained in:
parent
c4c46c349e
commit
d47e47cf1f
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue