Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Destroy Failed Deployments #3602

Merged
merged 6 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/3602.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
cli: `deployment destroy` will now attempt to destroy any known resources for failed
deployments. Previously, `destroy` would skip unsuccessful deployments.
```
12 changes: 9 additions & 3 deletions internal/cli/deployment_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"errors"
"strconv"

"github.com/posener/complete"
Expand Down Expand Up @@ -60,10 +61,12 @@ func (c *DeploymentDestroyCommand) Run(args []string) int {

// Destroy each deployment
c.ui.Output("%d deployments will be destroyed.", len(deployments), terminal.WithHeaderStyle())
var destroymentErrors []error
for _, deployment := range deployments {
// Can't destroy a deployment that was not successful
if deployment.Status.GetState() != pb.Status_SUCCESS {
continue
c.ui.Output("Deployment %d was not successful - destroy may not completely destroy "+
"all resources", deployment.Sequence, terminal.WithWarningStyle())
catsby marked this conversation as resolved.
Show resolved Hide resolved
}

// Get our app client
Expand All @@ -75,10 +78,13 @@ func (c *DeploymentDestroyCommand) Run(args []string) int {
Deployment: deployment,
},
}); err != nil {
c.ui.Output("Error destroying the deployment: %s", err.Error(), terminal.WithErrorStyle())
return ErrSentinel
c.ui.Output("Error destroying deployment %d: %s", deployment.Sequence, err.Error(), terminal.WithErrorStyle())
destroymentErrors = append(destroymentErrors, err)
}
}
if len(destroymentErrors) > 0 {
return errors.New("one or more deployments failed to be destroyed")
briancain marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
})
if err != nil {
Expand Down