2023-04-06 10:54:58 +00:00
|
|
|
package bundle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/phases"
|
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
|
|
|
"github.com/databricks/cli/libs/flags"
|
2023-04-06 10:54:58 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/term"
|
|
|
|
)
|
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
func newDestroyCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "destroy",
|
|
|
|
Short: "Destroy deployed bundle resources",
|
2023-04-06 10:54:58 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
PreRunE: ConfigureBundleWithVariables,
|
|
|
|
}
|
|
|
|
|
|
|
|
var autoApprove bool
|
|
|
|
var forceDestroy bool
|
|
|
|
cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals for deleting resources and files")
|
2023-07-30 12:44:33 +00:00
|
|
|
cmd.Flags().BoolVar(&forceDestroy, "force-lock", false, "Force acquisition of deployment lock.")
|
2023-07-27 10:03:08 +00:00
|
|
|
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2023-04-18 14:55:06 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
b := bundle.Get(ctx)
|
2023-04-06 10:54:58 +00:00
|
|
|
|
2023-07-30 12:44:33 +00:00
|
|
|
// If `--force-lock` is specified, force acquisition of the deployment lock.
|
2023-06-19 10:31:07 +00:00
|
|
|
b.Config.Bundle.Lock.Force = forceDestroy
|
2023-04-06 10:54:58 +00:00
|
|
|
|
|
|
|
// If `--auto-approve`` is specified, we skip confirmation checks
|
|
|
|
b.AutoApprove = autoApprove
|
|
|
|
|
|
|
|
// we require auto-approve for non tty terminals since interactive consent
|
|
|
|
// is not possible
|
|
|
|
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApprove {
|
|
|
|
return fmt.Errorf("please specify --auto-approve to skip interactive confirmation checks for non tty consoles")
|
|
|
|
}
|
|
|
|
|
2023-04-18 14:55:06 +00:00
|
|
|
// Check auto-approve is selected for json logging
|
|
|
|
logger, ok := cmdio.FromContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("progress logger not found")
|
|
|
|
}
|
|
|
|
if logger.Mode == flags.ModeJson && !autoApprove {
|
|
|
|
return fmt.Errorf("please specify --auto-approve since selected logging format is json")
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
return bundle.Apply(ctx, b, bundle.Seq(
|
2023-04-06 10:54:58 +00:00
|
|
|
phases.Initialize(),
|
|
|
|
phases.Build(),
|
|
|
|
phases.Destroy(),
|
2023-05-24 12:45:19 +00:00
|
|
|
))
|
2023-07-27 10:03:08 +00:00
|
|
|
}
|
2023-04-06 10:54:58 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
return cmd
|
2023-04-06 10:54:58 +00:00
|
|
|
}
|