Skip to content

Commit

Permalink
Cleanup empty stacks stuck in REVIEW_IN_PROGRESS state
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansteele committed Sep 3, 2018
1 parent 0fff654 commit ce68742
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions pkg/stackit/up.go
Original file line number Diff line number Diff line change
@@ -61,8 +61,16 @@ func (s *Stackit) EnsureStackReady(events chan<- TailStackEvent) error {
return err
}

cleanup := func() {
token := generateToken()
s.api.DeleteStack(&cloudformation.DeleteStackInput{StackName: &s.stackId, ClientRequestToken: &token})
s.PollStackEvents(token, func(event TailStackEvent) {
events <- event
})
}

if stack != nil { // stack already exists
if !IsTerminalStatus(*stack.StackStatus) {
if !IsTerminalStatus(*stack.StackStatus) && *stack.StackStatus != "REVIEW_IN_PROGRESS" {
s.PollStackEvents("", func(event TailStackEvent) {
events <- event
})
@@ -75,11 +83,16 @@ func (s *Stackit) EnsureStackReady(events chan<- TailStackEvent) error {
}

if *stack.StackStatus == "CREATE_FAILED" || *stack.StackStatus == "ROLLBACK_COMPLETE" {
token := generateToken()
s.api.DeleteStack(&cloudformation.DeleteStackInput{StackName: &s.stackId, ClientRequestToken: &token})
s.PollStackEvents(token, func(event TailStackEvent) {
events <- event
})
cleanup()
} else if *stack.StackStatus == "REVIEW_IN_PROGRESS" {
resp, err := s.api.ListStackResources(&cloudformation.ListStackResourcesInput{StackName: &s.stackId})
if err != nil {
s.error(err, events)
return err
}
if len(resp.StackResourceSummaries) == 0 {
cleanup()
}
}
}

@@ -165,4 +178,3 @@ func (s *Stackit) Up(input StackitUpInput, events chan<- TailStackEvent) {
})
close(events)
}

0 comments on commit ce68742

Please sign in to comment.