Support inlining contents

This commit is contained in:
Pieter Noordhuis 2024-09-12 16:16:23 +02:00
parent fb903fdf25
commit 9646e8859b
No known key found for this signature in database
GPG Key ID: 12ACCCC104CF2930
3 changed files with 49 additions and 1 deletions

View File

@ -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"`
}

View File

@ -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
}

View File

@ -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