From 9646e8859b0638d95eb9682152c30a22c227a34a Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 12 Sep 2024 16:16:23 +0200 Subject: [PATCH] Support inlining contents --- bundle/config/resources/dashboard.go | 6 ++++ .../terraform/tfdyn/convert_dashboard.go | 14 +++++++++ tmp/dashboard-dab/databricks.yml | 30 ++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/bundle/config/resources/dashboard.go b/bundle/config/resources/dashboard.go index d4640271..3404f9bd 100644 --- a/bundle/config/resources/dashboard.go +++ b/bundle/config/resources/dashboard.go @@ -27,10 +27,16 @@ type Dashboard struct { // WarehouseID is the ID of the warehouse to use for the dashboard. WarehouseID string `json:"warehouse_id,omitempty"` + // SerializedDashboard is the serialized dashboard definition. + SerializedDashboard string `json:"serialized_dashboard,omitempty"` + // =========================== // ==== END OF API FIELDS ==== // =========================== + // Contents can contain an object representing the unmarshalled version of the serialized dashboard. + Contents any `json:"contents,omitempty"` + // DefinitionPath points to the local `.lvdash.json` file containing the dashboard definition. DefinitionPath string `json:"definition_path,omitempty"` } diff --git a/bundle/deploy/terraform/tfdyn/convert_dashboard.go b/bundle/deploy/terraform/tfdyn/convert_dashboard.go index b173c14e..ac693448 100644 --- a/bundle/deploy/terraform/tfdyn/convert_dashboard.go +++ b/bundle/deploy/terraform/tfdyn/convert_dashboard.go @@ -2,6 +2,7 @@ package tfdyn import ( "context" + "encoding/json" "fmt" "github.com/databricks/cli/bundle/internal/tf/schema" @@ -27,6 +28,19 @@ func convertDashboardResource(ctx context.Context, vin dyn.Value) (dyn.Value, er } } + // Include marshalled copy of "contents" if set. + contents := vin.Get("contents") + if contents.Kind() == dyn.KindMap { + buf, err := json.Marshal(contents.AsAny()) + if err != nil { + return dyn.InvalidValue, fmt.Errorf("failed to marshal contents: %w", err) + } + vout, err = dyn.Set(vout, "serialized_dashboard", dyn.V(string(buf))) + if err != nil { + return dyn.InvalidValue, fmt.Errorf("failed to set serialized_dashboard: %w", err) + } + } + return vout, nil } diff --git a/tmp/dashboard-dab/databricks.yml b/tmp/dashboard-dab/databricks.yml index 70a6d15c..a64cd92f 100644 --- a/tmp/dashboard-dab/databricks.yml +++ b/tmp/dashboard-dab/databricks.yml @@ -24,7 +24,35 @@ resources: display_name: "Foobar" parent_path: ${workspace.file_path} warehouse_id: ${var.warehouse_id} - definition_path: ./dashboard.lvdash.json + # definition_path: ./dashboard.lvdash.json + + contents: + pages: + - displayName: New Page + layout: + - position: + height: 4 + width: 6 + x: 0 + y: 0 + widget: + name: 82eb9107 + textbox_spec: | + # My bundle target: ${bundle.target} + + I'm running this as ${workspace.current_user.short_name}. + + The workspace I'm targeting is [${workspace.host}](${workspace.host}). + + - position: + height: 1 + width: 3 + x: 0 + y: 4 + widget: + name: ffa6de4f + textbox_spec: another widget + name: fdd21a3c # # file_path: ./dashboard.lvdash.json