/
delete.go
68 lines (61 loc) · 1.96 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package commands
import (
"log"
"github.com/Skarlso/go-furnace/config"
"github.com/Skarlso/go-furnace/utils"
"github.com/Yitsushi/go-commander"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/fatih/color"
)
// Delete command.
type Delete struct {
}
// Execute defines what this command does.
func (c *Delete) Execute(opts *commander.CommandHelper) {
sess := session.New(&aws.Config{Region: aws.String(config.REGION)})
cfClient := cloudformation.New(sess, nil)
client := CFClient{cfClient}
deleteExecute(opts, &client)
}
func deleteExecute(opts *commander.CommandHelper, client *CFClient) {
stackname := config.STACKNAME
cyan := color.New(color.FgCyan).SprintFunc()
log.Printf("Deleting CloudFormation stack with name: %s\n", cyan(stackname))
for _, p := range config.PluginRegistry[config.PREDELETE] {
log.Println("Running plugin: ", p.Name)
p.Run.(func())()
}
deleteStack(stackname, client)
for _, p := range config.PluginRegistry[config.POSTDELETE] {
log.Println("Running plugin: ", p.Name)
p.Run.(func())()
}
}
func deleteStack(stackname string, cfClient *CFClient) {
params := &cloudformation.DeleteStackInput{
StackName: aws.String(stackname),
}
_, err := cfClient.Client.DeleteStack(params)
utils.CheckError(err)
describeStackInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackname),
}
utils.WaitForFunctionWithStatusOutput("DELETE_COMPLETE", config.WAITFREQUENCY, func() {
cfClient.Client.WaitUntilStackDeleteComplete(describeStackInput)
})
}
// NewDelete Creates a new Delete command.
func NewDelete(appName string) *commander.CommandWrapper {
return &commander.CommandWrapper{
Handler: &Delete{},
Help: &commander.CommandDescriptor{
Name: "delete",
ShortDescription: "Delete a stack",
LongDescription: `Delete a stack with a given name.`,
Arguments: "",
Examples: []string{""},
},
}
}