From ce687422e3230dae706a1dbc76017a5360809aae Mon Sep 17 00:00:00 2001 From: Aidan Steele Date: Mon, 3 Sep 2018 14:03:48 +1000 Subject: [PATCH] Cleanup empty stacks stuck in REVIEW_IN_PROGRESS state --- pkg/stackit/up.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/stackit/up.go b/pkg/stackit/up.go index 095279d..6dfc87d 100644 --- a/pkg/stackit/up.go +++ b/pkg/stackit/up.go @@ -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) } -