-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Exporter] Add support for exporting of Lakeview dashboards (#3779)
## Changes <!-- Summary of your changes that are easy to understand --> This adds support for exporting of `databricks_dashboard` resource and dependencies. Current limitations: - No support for incremental mode - List operation fails on big lists (not clear if it's a problem with API or Go SDK) ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [x] using Go SDK
- Loading branch information
Showing
3 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"github.com/databricks/databricks-sdk-go/apierr" | ||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
"github.com/databricks/databricks-sdk-go/service/compute" | ||
sdk_dashboards "github.com/databricks/databricks-sdk-go/service/dashboards" | ||
"github.com/databricks/databricks-sdk-go/service/iam" | ||
sdk_jobs "github.com/databricks/databricks-sdk-go/service/jobs" | ||
"github.com/databricks/databricks-sdk-go/service/ml" | ||
|
@@ -436,6 +437,13 @@ var emptyMetastoreList = qa.HTTPFixture{ | |
ReuseRequest: true, | ||
} | ||
|
||
var emptyLakeviewList = qa.HTTPFixture{ | ||
Method: "GET", | ||
Resource: "/api/2.0/lakeview/dashboards?page_size=100", | ||
Response: sdk_dashboards.ListDashboardsResponse{}, | ||
ReuseRequest: true, | ||
} | ||
|
||
func TestImportingUsersGroupsSecretScopes(t *testing.T) { | ||
listSpFixtures := qa.ListServicePrincipalsFixtures([]iam.ServicePrincipal{ | ||
{ | ||
|
@@ -457,6 +465,7 @@ func TestImportingUsersGroupsSecretScopes(t *testing.T) { | |
qa.HTTPFixturesApply(t, | ||
[]qa.HTTPFixture{ | ||
noCurrentMetastoreAttached, | ||
emptyLakeviewList, | ||
emptyMetastoreList, | ||
meAdminFixture, | ||
emptyRepos, | ||
|
@@ -729,6 +738,7 @@ func TestImportingNoResourcesError(t *testing.T) { | |
}, | ||
}, | ||
noCurrentMetastoreAttached, | ||
emptyLakeviewList, | ||
emptyMetastoreList, | ||
emptyRepos, | ||
emptyExternalLocations, | ||
|
@@ -2623,3 +2633,70 @@ func TestImportingRunJobTask(t *testing.T) { | |
}`)) | ||
}) | ||
} | ||
|
||
func TestImportingLakeviewDashboards(t *testing.T) { | ||
qa.HTTPFixturesApply(t, | ||
[]qa.HTTPFixture{ | ||
{ | ||
Method: "GET", | ||
ReuseRequest: true, | ||
Resource: "/api/2.0/preview/scim/v2/Me", | ||
Response: scim.User{ | ||
Groups: []scim.ComplexValue{ | ||
{ | ||
Display: "admins", | ||
}, | ||
}, | ||
UserName: "[email protected]", | ||
}, | ||
}, | ||
noCurrentMetastoreAttached, | ||
{ | ||
Method: "GET", | ||
Resource: "/api/2.0/lakeview/dashboards?page_size=100", | ||
Response: sdk_dashboards.ListDashboardsResponse{ | ||
Dashboards: []sdk_dashboards.Dashboard{ | ||
{ | ||
DashboardId: "9cb0c8f562624a1f", | ||
DisplayName: "Dashboard1", | ||
}, | ||
}, | ||
}, | ||
ReuseRequest: true, | ||
}, | ||
{ | ||
Method: "GET", | ||
Resource: "/api/2.0/lakeview/dashboards/9cb0c8f562624a1f?", | ||
Response: sdk_dashboards.Dashboard{ | ||
DashboardId: "9cb0c8f562624a1f", | ||
DisplayName: "Dashboard1", | ||
ParentPath: "/", | ||
Path: "/Dashboard1.lvdash.json", | ||
SerializedDashboard: `{}`, | ||
WarehouseId: "1234", | ||
}, | ||
}, | ||
}, | ||
func(ctx context.Context, client *common.DatabricksClient) { | ||
tmpDir := fmt.Sprintf("/tmp/tf-%s", qa.RandomName()) | ||
defer os.RemoveAll(tmpDir) | ||
|
||
ic := newImportContext(client) | ||
ic.Directory = tmpDir | ||
ic.enableListing("dashboards") | ||
ic.enableServices("dashboards") | ||
|
||
err := ic.Run() | ||
assert.NoError(t, err) | ||
|
||
content, err := os.ReadFile(tmpDir + "/dashboards.tf") | ||
assert.NoError(t, err) | ||
contentStr := string(content) | ||
assert.True(t, strings.Contains(contentStr, `resource "databricks_dashboard" "dashboard1_9cb0c8f562624a1f"`)) | ||
assert.True(t, strings.Contains(contentStr, `file_path = "${path.module}/dashboards/Dashboard1_9cb0c8f562624a1f.lvdash.json"`)) | ||
content, err = os.ReadFile(tmpDir + "/dashboards/Dashboard1_9cb0c8f562624a1f.lvdash.json") | ||
assert.NoError(t, err) | ||
contentStr = string(content) | ||
assert.Equal(t, `{}`, contentStr) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters