mirror of https://github.com/databricks/cli.git
Add --dry-run option for bundle deplot
This commit is contained in:
parent
a8cff48c0b
commit
a64b88b93c
|
@ -81,6 +81,9 @@ type Bundle struct {
|
||||||
// files
|
// files
|
||||||
AutoApprove bool
|
AutoApprove bool
|
||||||
|
|
||||||
|
// if true, the deploy changes are presented, but not applied
|
||||||
|
DryRun bool
|
||||||
|
|
||||||
// Tagging is used to normalize tag keys and values.
|
// Tagging is used to normalize tag keys and values.
|
||||||
// The implementation depends on the cloud being targeted.
|
// The implementation depends on the cloud being targeted.
|
||||||
Tagging tags.Cloud
|
Tagging tags.Cloud
|
||||||
|
|
|
@ -115,6 +115,15 @@ properties such as the 'catalog' or 'storage' are changed:`
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.DryRun {
|
||||||
|
cmdio.LogString(ctx, "Following changes would be deployed:")
|
||||||
|
_, err := tf.ShowPlanFile(ctx, b.Plan.Path)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
if !cmdio.IsPromptSupported(ctx) {
|
if !cmdio.IsPromptSupported(ctx) {
|
||||||
return false, fmt.Errorf("the deployment requires destructive actions, but current console does not support prompting. Please specify --auto-approve if you would like to skip prompts and proceed")
|
return false, fmt.Errorf("the deployment requires destructive actions, but current console does not support prompting. Please specify --auto-approve if you would like to skip prompts and proceed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ func newDeployCommand() *cobra.Command {
|
||||||
var failOnActiveRuns bool
|
var failOnActiveRuns bool
|
||||||
var clusterId string
|
var clusterId string
|
||||||
var autoApprove bool
|
var autoApprove bool
|
||||||
|
var dryRyn bool
|
||||||
var verbose bool
|
var verbose bool
|
||||||
cmd.Flags().BoolVar(&force, "force", false, "Force-override Git branch validation.")
|
cmd.Flags().BoolVar(&force, "force", false, "Force-override Git branch validation.")
|
||||||
cmd.Flags().BoolVar(&forceLock, "force-lock", false, "Force acquisition of deployment lock.")
|
cmd.Flags().BoolVar(&forceLock, "force-lock", false, "Force acquisition of deployment lock.")
|
||||||
|
@ -33,6 +34,7 @@ func newDeployCommand() *cobra.Command {
|
||||||
cmd.Flags().StringVar(&clusterId, "compute-id", "", "Override cluster in the deployment with the given compute ID.")
|
cmd.Flags().StringVar(&clusterId, "compute-id", "", "Override cluster in the deployment with the given compute ID.")
|
||||||
cmd.Flags().StringVarP(&clusterId, "cluster-id", "c", "", "Override cluster in the deployment with the given cluster ID.")
|
cmd.Flags().StringVarP(&clusterId, "cluster-id", "c", "", "Override cluster in the deployment with the given cluster ID.")
|
||||||
cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals that might be required for deployment.")
|
cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals that might be required for deployment.")
|
||||||
|
cmd.Flags().BoolVar(&dryRyn, "dry-run", false, "Present changes that would be deployed without applying.")
|
||||||
cmd.Flags().MarkDeprecated("compute-id", "use --cluster-id instead")
|
cmd.Flags().MarkDeprecated("compute-id", "use --cluster-id instead")
|
||||||
cmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose output.")
|
cmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose output.")
|
||||||
// Verbose flag currently only affects file sync output, it's used by the vscode extension
|
// Verbose flag currently only affects file sync output, it's used by the vscode extension
|
||||||
|
@ -47,6 +49,7 @@ func newDeployCommand() *cobra.Command {
|
||||||
b.Config.Bundle.Force = force
|
b.Config.Bundle.Force = force
|
||||||
b.Config.Bundle.Deployment.Lock.Force = forceLock
|
b.Config.Bundle.Deployment.Lock.Force = forceLock
|
||||||
b.AutoApprove = autoApprove
|
b.AutoApprove = autoApprove
|
||||||
|
b.DryRun = dryRyn
|
||||||
|
|
||||||
if cmd.Flag("compute-id").Changed {
|
if cmd.Flag("compute-id").Changed {
|
||||||
b.Config.Bundle.ClusterId = clusterId
|
b.Config.Bundle.ClusterId = clusterId
|
||||||
|
|
|
@ -127,6 +127,34 @@ func TestAccBundleDeployUcSchemaFailsWithoutAutoApprove(t *testing.T) {
|
||||||
assert.Contains(t, stdout.String(), "the deployment requires destructive actions, but current console does not support prompting. Please specify --auto-approve if you would like to skip prompts and proceed")
|
assert.Contains(t, stdout.String(), "the deployment requires destructive actions, but current console does not support prompting. Please specify --auto-approve if you would like to skip prompts and proceed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccBundleDeployUcSchemaDryRun(t *testing.T) {
|
||||||
|
ctx, wt := acc.UcWorkspaceTest(t)
|
||||||
|
w := wt.W
|
||||||
|
|
||||||
|
uniqueId := uuid.New().String()
|
||||||
|
schemaName := "test-schema-" + uniqueId
|
||||||
|
catalogName := "main"
|
||||||
|
|
||||||
|
bundleRoot := setupUcSchemaBundle(t, ctx, w, uniqueId)
|
||||||
|
|
||||||
|
// Remove the UC schema from the resource configuration.
|
||||||
|
err := os.Remove(filepath.Join(bundleRoot, "schema.yml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Redeploy the bundle
|
||||||
|
t.Setenv("BUNDLE_ROOT", bundleRoot)
|
||||||
|
t.Setenv("TERM", "dumb")
|
||||||
|
c := internal.NewCobraTestRunnerWithContext(t, ctx, "bundle", "deploy", "--dry0run")
|
||||||
|
stdout, _, err := c.Run()
|
||||||
|
|
||||||
|
// Assert the schema is deleted
|
||||||
|
_, err = w.Schemas.GetByFullName(ctx, strings.Join([]string{catalogName, schemaName}, "."))
|
||||||
|
apiErr := &apierr.APIError{}
|
||||||
|
assert.Contains(t, stdout.String(), "Following changes would be deployed:")
|
||||||
|
assert.True(t, errors.As(err, &apiErr))
|
||||||
|
assert.Equal(t, "SCHEMA_DOES_NOT_EXIST", apiErr.ErrorCode)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccBundlePipelineDeleteWithoutAutoApprove(t *testing.T) {
|
func TestAccBundlePipelineDeleteWithoutAutoApprove(t *testing.T) {
|
||||||
ctx, wt := acc.WorkspaceTest(t)
|
ctx, wt := acc.WorkspaceTest(t)
|
||||||
w := wt.W
|
w := wt.W
|
||||||
|
@ -236,7 +264,7 @@ func TestAccDeployBasicBundleLogs(t *testing.T) {
|
||||||
|
|
||||||
stdout, stderr := blackBoxRun(t, root, "bundle", "deploy")
|
stdout, stderr := blackBoxRun(t, root, "bundle", "deploy")
|
||||||
assert.Equal(t, strings.Join([]string{
|
assert.Equal(t, strings.Join([]string{
|
||||||
fmt.Sprintf("Uploading bundle files to /Workspace/Users/%s/.bundle/%s/files...", currentUser.UserName, uniqueId),
|
fmt.Sprintf("Uploading bundle files to /Users/%s/.bundle/%s/files...", currentUser.UserName, uniqueId),
|
||||||
"Deploying resources...",
|
"Deploying resources...",
|
||||||
"Updating deployment state...",
|
"Updating deployment state...",
|
||||||
"Deployment complete!\n",
|
"Deployment complete!\n",
|
||||||
|
|
Loading…
Reference in New Issue