// wait until a stack is in a final state, then delete it func waitAndDelete(name string) { log.Println("Attempting to delete stack:", name) // we need to get the StackID in order to lookup DELETE events desc, err := stack.DescribeStacks(name) if err != nil { log.Fatalf("ERROR: %s", err) } else if len(desc.Stacks) == 0 { log.Fatal("ERROR: could not describe stack:", name) } stackId := desc.Stacks[0].Id err = stack.WaitForComplete(stackId, 5*time.Minute) if err != nil { log.Fatal(err) } _, err = stack.Delete(name) if err != nil { log.Fatal(err) } // wait err = stack.WaitForComplete(stackId, 5*time.Minute) if err != nil { log.Fatal(err) } log.Println("Deleted stack:", name) }
// return --base, or try to find a base cloudformation stack func getBase(c *cli.Context) string { errNoBase := fmt.Errorf("could not identify a unique base stack") base := c.String("base") if base != "" { return base } descResp, err := stack.DescribeStacks("") if err != nil { log.Fatal(err) } for _, stack := range descResp.Stacks { // first check for galaxy:base tag baseTag := false for _, t := range stack.Tags { if t.Key == "galaxy" && t.Value == "base" { baseTag = true } } if baseTag { if base != "" { err = errNoBase } base = stack.Name continue } parts := strings.Split(stack.Name, "-") // check for "-base" in the name if parts[len(parts)-1] == "base" { if base != "" { err = errNoBase } base = stack.Name continue } // the best we can do for now is look for a stack with a single word if len(parts) == 1 { if base != "" { err = errNoBase } base = stack.Name log.Printf("Warning: guessing base stack: %s", base) } } if err != nil { log.Fatalf("%s: %s", err, "use --base") } return base }
func stackList(c *cli.Context) { if c.String("region") != "" { stack.Region = c.String("region") } descResp, err := stack.DescribeStacks("") if err != nil { log.Fatal(err) } stacks := []string{"STACK | STATUS | "} for _, stack := range descResp.Stacks { s := fmt.Sprintf("%s | %s | %s", stack.Name, stack.Status, stack.StatusReason) stacks = append(stacks, s) } output, _ := columnize.SimpleFormat(stacks) log.Println(output) }