in util/awsservice/cloudformation.go [62:83]
func FindStackInstanceId(ctx context.Context, stackName string, client *cloudformation.Client, timeOutMinutes int) string {
for i := 0; i <= timeOutMinutes; i++ {
cfStackInput := cloudformation.DescribeStacksInput{
StackName: aws.String(stackName),
}
stacks, err := client.DescribeStacks(ctx, &cfStackInput)
if err != nil || len(stacks.Stacks) != 1 || stacks.Stacks[0].StackStatus != types.StackStatusCreateComplete {
log.Printf("Stack %s not ready in minute %d continue to next minute", stackName, i)
} else {
for output := range stacks.Stacks[0].Outputs {
if *stacks.Stacks[0].Outputs[output].OutputKey == instanceIdKey {
log.Printf("Found instance id %s from stack %s", *stacks.Stacks[0].Outputs[output].OutputValue, stackName)
return *stacks.Stacks[0].Outputs[output].OutputValue
}
}
}
log.Printf("Sleep for one minute to wait for stack to start")
time.Sleep(time.Minute)
}
log.Fatalf("Stack not created within timeout %s", stackName)
return ""
}