Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/bundle-generate-all-resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add `databricks bundle generate <resource>` subcommands for every bundle resource type. ([#7365](https://github.com/databricks/cli/pull/7365))
5 changes: 5 additions & 0 deletions acceptance/bundle/generate/catalog/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bundle:
name: generate-catalog

include:
- resources/*.yml
2 changes: 2 additions & 0 deletions acceptance/bundle/generate/catalog/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
19 changes: 19 additions & 0 deletions acceptance/bundle/generate/catalog/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

>>> [CLI] bundle generate catalog --existing-id my_catalog
Catalog configuration successfully saved to [TEST_TMP_DIR]/resources/my_catalog.catalog.yml

>>> cat resources/my_catalog.catalog.yml
resources:
catalogs:
my_catalog:
comment: primary catalog
name: my_catalog

>>> [CLI] bundle validate
Name: generate-catalog
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/generate-catalog/default

Validation OK!
10 changes: 10 additions & 0 deletions acceptance/bundle/generate/catalog/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$CLI catalogs create my_catalog --comment "primary catalog" > /dev/null

trace $CLI bundle generate catalog --existing-id my_catalog

trace cat resources/my_catalog.catalog.yml

# The generated configuration loads as part of the bundle.
trace $CLI bundle validate

rm -r resources
1 change: 1 addition & 0 deletions acceptance/bundle/generate/catalog/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore = [".databricks"]
3 changes: 3 additions & 0 deletions acceptance/bundle/help/bundle-generate-dashboard/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ bundle files automatically, useful during active dashboard development.
Usage:
databricks bundle generate dashboard [flags]

Aliases:
dashboard, dashboards

Flags:
-s, --dashboard-dir string directory to write the dashboard representation to (default "src")
--existing-id string ID of the dashboard to generate configuration for
Expand Down
3 changes: 3 additions & 0 deletions acceptance/bundle/help/bundle-generate-job/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ After generation, you can deploy this job to other targets using:
Usage:
databricks bundle generate job [flags]

Aliases:
job, jobs

Flags:
-d, --config-dir string Dir path where the output config will be stored (default "resources")
--download-spark-python-files download workspace files referenced by spark_python_task and rewrite them to a relative path
Expand Down
3 changes: 3 additions & 0 deletions acceptance/bundle/help/bundle-generate-pipeline/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ like catalogs, schemas, and compute configurations per target.
Usage:
databricks bundle generate pipeline [flags]

Aliases:
pipeline, pipelines

Flags:
-d, --config-dir string Dir path where the output config will be stored (default "resources")
--existing-pipeline-id string ID of the pipeline to generate config for
Expand Down
47 changes: 41 additions & 6 deletions acceptance/bundle/help/bundle-generate/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,47 @@ Usage:
databricks bundle generate [command]

Available Commands:
alert Generate configuration for an alert
app Generate bundle configuration for a Databricks app
dashboard Generate configuration for a dashboard
genie-space Generate configuration for a Genie space
job Generate bundle configuration for a job
pipeline Generate bundle configuration for a pipeline
alert Generate configuration for an alert
app Generate bundle configuration for a Databricks app
catalog Generate bundle configuration for a catalog
cluster Generate bundle configuration for a cluster
cluster-policy Generate bundle configuration for a cluster policy
dashboard Generate configuration for a dashboard
data-quality-monitor Generate bundle configuration for a data quality monitor
database-catalog Generate bundle configuration for a database catalog
database-instance Generate bundle configuration for a database instance
experiment Generate bundle configuration for an experiment
external-location Generate bundle configuration for an external location
feature Generate bundle configuration for a feature
genie-space Generate configuration for a Genie space
instance-pool Generate bundle configuration for an instance pool
job Generate bundle configuration for a job
materialization-set Generate bundle configuration for a materialization set
mcp-service Generate bundle configuration for a mcp service
model Generate bundle configuration for a model
model-provider-service Generate bundle configuration for a model provider service
model-service Generate bundle configuration for a model service
model-serving-endpoint Generate bundle configuration for a model serving endpoint
pipeline Generate bundle configuration for a pipeline
postgres-branch Generate bundle configuration for a postgres branch
postgres-catalog Generate bundle configuration for a postgres catalog
postgres-data-api Generate bundle configuration for a postgres data api
postgres-database Generate bundle configuration for a postgres database
postgres-endpoint Generate bundle configuration for a postgres endpoint
postgres-project Generate bundle configuration for a postgres project
postgres-role Generate bundle configuration for a postgres role
postgres-snapshot-schedule Generate bundle configuration for a postgres snapshot schedule
postgres-synced-table Generate bundle configuration for a postgres synced table
quality-monitor Generate bundle configuration for a quality monitor
registered-model Generate bundle configuration for a registered model
schema Generate bundle configuration for a schema
secret Generate bundle configuration for a secret
secret-scope Generate bundle configuration for a secret scope
sql-warehouse Generate bundle configuration for a sql warehouse
synced-database-table Generate bundle configuration for a synced database table
vector-search-endpoint Generate bundle configuration for a vector search endpoint
vector-search-index Generate bundle configuration for a vector search index
volume Generate bundle configuration for a volume

Flags:
-h, --help help for generate
Expand Down
12 changes: 12 additions & 0 deletions bundle/generate/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package generate

import (
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/dyn/yamlsaver"
)

// ConvertResourceToValue serializes a bundle resource for a generated YAML file.
// Nil fields are dropped and the remaining keys are sorted alphabetically.
func ConvertResourceToValue(resource any) (dyn.Value, error) {
return yamlsaver.ConvertToMapValue(resource, nil, nil, make(map[string]dyn.Value))
}
30 changes: 30 additions & 0 deletions bundle/generate/resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package generate

import (
"testing"

"github.com/databricks/cli/bundle/config/resources"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestConvertResourceToValueDropsEmptyFieldsAndSortsKeys(t *testing.T) {
c := resources.Catalog{
StorageRoot: "s3://bucket",
Name: "main",
Comment: "primary",
}

v, err := ConvertResourceToValue(&c)
require.NoError(t, err)

m, ok := v.AsMap()
require.True(t, ok)
// The YAML encoder orders entries by line, so the lines encode alphabetical order.
// BaseResource, ID, and Grants are zero and must not appear.
lines := make(map[string]int)
for _, p := range m.Pairs() {
lines[p.Key.MustString()] = p.Value.Location().Line
}
assert.Equal(t, map[string]int{"comment": 1, "name": 2, "storage_root": 3}, lines)
}
7 changes: 1 addition & 6 deletions cmd/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ Use --key to specify the resource name in your bundle configuration.
Use --bind to automatically bind the generated resource to the existing workspace resource.`,
}

cmd.AddCommand(generate.NewGenerateJobCommand())
cmd.AddCommand(generate.NewGeneratePipelineCommand())
cmd.AddCommand(generate.NewGenerateDashboardCommand())
cmd.AddCommand(generate.NewGenerateAlertCommand())
cmd.AddCommand(generate.NewGenerateAppCommand())
cmd.AddCommand(generate.NewGenerateGenieSpaceCommand())
cmd.AddCommand(generate.NewCommands()...)
cmd.PersistentFlags().StringVar(&key, "key", "", `resource key to use for the generated configuration`)
return cmd
}
Loading
Loading