diff --git a/.nextchanges/bundles/7117.md b/.nextchanges/bundles/7117.md new file mode 100644 index 00000000000..31753443d73 --- /dev/null +++ b/.nextchanges/bundles/7117.md @@ -0,0 +1 @@ +* Zero-value overrides of `presets`, `lifecycle.prevent_destroy` and `deployment` settings in includes now replace non-zero base values, and `bundle validate -o json` shows explicit zero presets. ([#7117](https://github.com/databricks/cli/pull/7117)) diff --git a/acceptance/bundle/validate/includes/clears_unforced_preset_values/output.txt b/acceptance/bundle/validate/includes/clears_unforced_preset_values/output.txt index 82b92b1e6ad..a2e1bac25ce 100644 --- a/acceptance/bundle/validate/includes/clears_unforced_preset_values/output.txt +++ b/acceptance/bundle/validate/includes/clears_unforced_preset_values/output.txt @@ -1,7 +1,11 @@ >>> [CLI] bundle validate -o json { - "presets": {}, + "presets": { + "artifacts_dynamic_version": false, + "jobs_max_concurrent_runs": 0, + "name_prefix": "" + }, "job": { "name": "job", "max_concurrent_runs": 1 diff --git a/acceptance/bundle/validate/lifecycle_override/databricks.yml b/acceptance/bundle/validate/lifecycle_override/databricks.yml new file mode 100644 index 00000000000..242874319d3 --- /dev/null +++ b/acceptance/bundle/validate/lifecycle_override/databricks.yml @@ -0,0 +1,33 @@ +bundle: + name: test-bundle + +resources: + jobs: + j: + name: job + tasks: + - task_key: task + notebook_task: + notebook_path: /notebook + lifecycle: + prevent_destroy: true + + clusters: + c: + spark_version: "15.4.x-scala2.12" + node_type_id: "i3.xlarge" + num_workers: 2 + lifecycle: + prevent_destroy: true + +targets: + dev: + resources: + jobs: + j: + lifecycle: + prevent_destroy: false + clusters: + c: + lifecycle: + prevent_destroy: false diff --git a/acceptance/bundle/validate/lifecycle_override/out.test.toml b/acceptance/bundle/validate/lifecycle_override/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/validate/lifecycle_override/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/validate/lifecycle_override/output.txt b/acceptance/bundle/validate/lifecycle_override/output.txt new file mode 100644 index 00000000000..6062c603c5c --- /dev/null +++ b/acceptance/bundle/validate/lifecycle_override/output.txt @@ -0,0 +1,6 @@ + +>>> [CLI] bundle validate -t dev -o json +{ + "job_prevent_destroy": false, + "cluster_prevent_destroy": false +} diff --git a/acceptance/bundle/validate/lifecycle_override/script b/acceptance/bundle/validate/lifecycle_override/script new file mode 100644 index 00000000000..12de3d7d803 --- /dev/null +++ b/acceptance/bundle/validate/lifecycle_override/script @@ -0,0 +1,2 @@ +# The target override prevent_destroy: false wins over the base prevent_destroy: true +trace $CLI bundle validate -t dev -o json | jq '{job_prevent_destroy: .resources.jobs.j.lifecycle.prevent_destroy, cluster_prevent_destroy: .resources.clusters.c.lifecycle.prevent_destroy}' diff --git a/bundle/config/deployment.go b/bundle/config/deployment.go index e29051e4ff5..3b3f65608b3 100644 --- a/bundle/config/deployment.go +++ b/bundle/config/deployment.go @@ -14,4 +14,9 @@ type Deployment struct { // LatestVersionID is the most recent version recorded for the deployment. It is // zero when the deployment exists but has no version yet. LatestVersionID int `json:"latest_version_id,omitempty"` + + // ForceSendFields records which fields were explicitly set so that zero-value + // overrides can replace non-zero base values (e.g., fail_on_active_runs: false). + // This field is not serialized to JSON. + ForceSendFields []string `json:"-"` } diff --git a/bundle/config/presets.go b/bundle/config/presets.go index 46562067ae3..a831d83c9c2 100644 --- a/bundle/config/presets.go +++ b/bundle/config/presets.go @@ -29,6 +29,11 @@ type Presets struct { // Tags to add to all resources. Tags map[string]string `json:"tags,omitempty"` + + // ForceSendFields records which fields were explicitly set so that zero-value + // overrides can replace non-zero base values (e.g., name_prefix: "" clearing a base prefix). + // This field is not serialized to JSON. + ForceSendFields []string `json:"-"` } // IsExplicitlyEnabled tests whether this feature is explicitly enabled. diff --git a/bundle/config/resources/lifecycle.go b/bundle/config/resources/lifecycle.go index db2b130d313..b7f0d55ec72 100644 --- a/bundle/config/resources/lifecycle.go +++ b/bundle/config/resources/lifecycle.go @@ -9,6 +9,12 @@ type LifecycleConfig interface { type Lifecycle struct { // Lifecycle setting to prevent the resource from being destroyed. PreventDestroy bool `json:"prevent_destroy,omitempty"` + + // ForceSendFields records which fields were explicitly set so that zero-value + // overrides can replace non-zero base values (e.g., prevent_destroy: false in a target + // can override prevent_destroy: true in the base). + // This field is not serialized to JSON. + ForceSendFields []string `json:"-"` } // HasPreventDestroy returns true if prevent_destroy is set.