rewrite to not use private aws package
This commit is contained in:
parent
c4c46c349e
commit
d47e47cf1f
@ -9,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"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/aws/aws-sdk-go/service/ec2"
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
@ -46,17 +45,19 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
|
|||||||
|
|
||||||
securityGroupIds := make([]*string, len(tempSecurityGroupIds))
|
securityGroupIds := make([]*string, len(tempSecurityGroupIds))
|
||||||
for i, sg := range tempSecurityGroupIds {
|
for i, sg := range tempSecurityGroupIds {
|
||||||
|
log.Printf("[DEBUG] Waiting for tempSecurityGroup: %s", sg)
|
||||||
err := WaitUntilSecurityGroupExists(ec2conn,
|
err := WaitUntilSecurityGroupExists(ec2conn,
|
||||||
&ec2.DescribeSecurityGroupsInput{
|
&ec2.DescribeSecurityGroupsInput{
|
||||||
GroupIds: []*string{aws.String(sg)},
|
GroupIds: []*string{aws.String(sg)},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.Printf("[DEBUG] Found security group %s", sg)
|
log.Printf("[DEBUG] Found security group %s", sg)
|
||||||
securityGroupIds[i] = aws.String(sg)
|
securityGroupIds[i] = aws.String(sg)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[DEBUG] Error in querying security group %s", err)
|
err := fmt.Errorf("Timed out waiting for security group %s", sg)
|
||||||
state.Put("error", fmt.Errorf("Timeout waiting for security group %s to become available", sg))
|
log.Printf("[DEBUG] %s", err.Error())
|
||||||
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,30 +361,14 @@ func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WaitUntilSecurityGroupExists(c *ec2.EC2, input *ec2.DescribeSecurityGroupsInput) error {
|
func WaitUntilSecurityGroupExists(c *ec2.EC2, input *ec2.DescribeSecurityGroupsInput) error {
|
||||||
waiterCfg := waiter.Config{
|
for i := 0; i < 40; i++ {
|
||||||
Operation: "DescribeSecurityGroups",
|
_, err := c.DescribeSecurityGroups(input)
|
||||||
Delay: 15,
|
if err != nil {
|
||||||
MaxAttempts: 40,
|
log.Printf("[DEBUG] Error querying security group %s: %s", input.GroupIds, err)
|
||||||
Acceptors: []waiter.WaitAcceptor{
|
time.Sleep(15 * time.Second)
|
||||||
{
|
continue
|
||||||
State: "success",
|
}
|
||||||
Matcher: "path",
|
return nil
|
||||||
Argument: "lenth(SecurityGroups[]) > `0`",
|
|
||||||
Expected: "true",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
State: "failure",
|
|
||||||
Matcher: "error",
|
|
||||||
Argument: "",
|
|
||||||
Expected: "InvalidSecurityGroupID.NotFound",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("timed out")
|
||||||
w := waiter.Waiter{
|
|
||||||
Client: c,
|
|
||||||
Input: input,
|
|
||||||
Config: waiterCfg,
|
|
||||||
}
|
|
||||||
return w.Wait()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user