diff --git a/.changelog/3602.txt b/.changelog/3602.txt new file mode 100644 index 00000000000..d723d7290e2 --- /dev/null +++ b/.changelog/3602.txt @@ -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. +``` \ No newline at end of file diff --git a/internal/cli/deployment_destroy.go b/internal/cli/deployment_destroy.go index 4c08b0aa2fa..dd35b0b0462 100644 --- a/internal/cli/deployment_destroy.go +++ b/internal/cli/deployment_destroy.go @@ -2,6 +2,7 @@ package cli import ( "context" + "errors" "strconv" "github.com/posener/complete" @@ -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()) } // Get our app client @@ -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") + } return nil }) if err != nil {