This commit is contained in:
Pieter Noordhuis 2024-09-27 16:39:51 +02:00
parent ff15a046fc
commit 3a1d92c75c
No known key found for this signature in database
GPG Key ID: 12ACCCC104CF2930
3 changed files with 32 additions and 13 deletions

View File

@ -18,21 +18,37 @@ type Dashboard struct {
// === BEGIN OF API FIELDS ===
// ===========================
// DisplayName is the name of the dashboard (both as title and as basename in the workspace).
DisplayName string `json:"display_name,omitempty"`
// DisplayName is the display name of the dashboard (both as title and as basename in the workspace).
DisplayName string `json:"display_name"`
// ParentPath is the path to the parent directory of the dashboard.
// WarehouseID is the ID of the SQL Warehouse used to run the dashboard's queries.
WarehouseID string `json:"warehouse_id"`
// SerializedDashboard is the contents of the dashboard in serialized JSON form.
// Note: its type is any and not string such that it can be inlined as YAML.
// If it is not a string, its contents will be marshalled as JSON.
SerializedDashboard any `json:"serialized_dashboard,omitempty"`
// ParentPath is the workspace path of the folder containing the dashboard.
// Includes leading slash and no trailing slash.
//
// Defaults to ${workspace.resource_path} if not set.
ParentPath string `json:"parent_path,omitempty"`
// WarehouseID is the ID of the warehouse to use for the dashboard.
WarehouseID string `json:"warehouse_id,omitempty"`
// EmbedCredentials is a flag to indicate if the publisher's credentials should
// be embedded in the published dashboard. These embedded credentials will be used
// to execute the published dashboard's queries.
//
// Defaults to false if not set.
EmbedCredentials bool `json:"embed_credentials,omitempty"`
// ===========================
// ==== END OF API FIELDS ====
// ===========================
// DefinitionPath points to the local `.lvdash.json` file containing the dashboard definition.
DefinitionPath string `json:"definition_path,omitempty"`
// FilePath points to the local `.lvdash.json` file containing the dashboard definition.
// If specified, it will populate the `SerializedDashboard` field.
FilePath string `json:"file_path,omitempty"`
}
func (s *Dashboard) UnmarshalJSON(b []byte) error {
@ -43,7 +59,7 @@ func (s Dashboard) MarshalJSON() ([]byte, error) {
return marshal.Marshal(s)
}
func (_ *Dashboard) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
func (*Dashboard) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
_, err := w.Lakeview.Get(ctx, dashboards.GetDashboardRequest{
DashboardId: id,
})
@ -54,6 +70,6 @@ func (_ *Dashboard) Exists(ctx context.Context, w *databricks.WorkspaceClient, i
return true, nil
}
func (_ *Dashboard) TerraformResourceName() string {
func (*Dashboard) TerraformResourceName() string {
return "databricks_dashboard"
}

View File

@ -58,9 +58,12 @@ func TestBundleToTerraformJob(t *testing.T) {
},
}
out := BundleToTerraform(&config)
resource := out.Resource.Job["my_job"].(*schema.ResourceJob)
vin, err := convert.FromTyped(config, dyn.NilValue)
require.NoError(t, err)
out, err := BundleToTerraformWithDynValue(context.Background(), vin)
require.NoError(t, err)
resource := out.Resource.Job["my_job"].(*schema.ResourceJob)
assert.Equal(t, "my job", resource.Name)
assert.Len(t, resource.JobCluster, 1)
assert.Equal(t, "https://github.com/foo/bar", resource.GitSource.Url)

View File

@ -175,7 +175,7 @@ func (d *dashboard) watchForChanges(ctx context.Context, b *bundle.Bundle) error
return err
}
relPath, err := filepath.Rel(cwd, dash.DefinitionPath)
relPath, err := filepath.Rel(cwd, dash.FilePath)
if err != nil {
return err
}
@ -199,7 +199,7 @@ func (d *dashboard) watchForChanges(ctx context.Context, b *bundle.Bundle) error
if etag != dashboard.Etag {
fmt.Printf("[%s]: Updating dashboard at %s\n", dashboard.UpdateTime, relPath)
d.saveSerializedDashboard(ctx, dashboard, dash.DefinitionPath)
d.saveSerializedDashboard(ctx, dashboard, dash.FilePath)
}
etag = dashboard.Etag