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"
|
|
|
|
)
|
|
|
|
|
|
|
|
var destroyCmd = &cobra.Command{
|
|
|
|
Use: "destroy",
|
|
|
|
Short: "Destroy deployed bundle resources",
|
|
|
|
|
2023-05-15 09:34:05 +00:00
|
|
|
PreRunE: ConfigureBundleWithVariables,
|
2023-04-06 10:54:58 +00:00
|
|
|
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
|
|
|
|
|
|
|
// If `--force` 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-04-06 10:54:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var autoApprove bool
|
2023-06-19 10:31:07 +00:00
|
|
|
var forceDestroy bool
|
2023-04-06 10:54:58 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
AddCommand(destroyCmd)
|
|
|
|
destroyCmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals for deleting resources and files")
|
2023-06-19 10:31:07 +00:00
|
|
|
destroyCmd.Flags().BoolVar(&forceDestroy, "force", false, "Force acquisition of deployment lock.")
|
2023-04-06 10:54:58 +00:00
|
|
|
}
|