Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/guides/experimental-exporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Services are just logical groups of resources used for filtering and organizatio
* `uc-system-schemas` - **listing** exports [databricks_system_schema](../resources/system_schema.md) resources for the UC metastore of the current workspace.
* `uc-tables` - **listing** (*we can't list directly, only via dependencies to top-level object*) [databricks_sql_table](../resources/sql_table.md) resource.
* `uc-volumes` - **listing** (*we can't list directly, only via dependencies to top-level object*) [databricks_volume](../resources/volume.md)
* `users` - [databricks_user](../resources/user.md) and [databricks_service_principal](../resources/service_principal.md) are written to their own file, simply because of their amount. If you use SCIM provisioning, migrating workspaces is the only use case for importing `users` service.
* `users` - **listing** [databricks_user](../resources/user.md) and [databricks_service_principal](../resources/service_principal.md) are written to their own file, simply because of their amount. If you use SCIM provisioning, migrating workspaces is the only use case for importing `users` service.
* `vector-search` - **listing** exports [databricks_vector_search_endpoint](../resources/vector_search_endpoint.md) and [databricks_vector_search_index](../resources/vector_search_index.md)
* `workspace` - **listing** [databricks_workspace_conf](../resources/workspace_conf.md) and [databricks_global_init_script](../resources/global_init_script.md)
* `wsfiles` - **listing** [databricks_workspace_file](../resources/workspace_file.md).
Expand Down
23 changes: 20 additions & 3 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,24 @@ var emptyLakeviewList = qa.HTTPFixture{
}

var emptyDestinationNotficationsList = qa.HTTPFixture{
Method: "GET",
Resource: "/api/2.0/notification-destinations?",
Response: settings.ListNotificationDestinationsResponse{},
Method: "GET",
Resource: "/api/2.0/notification-destinations?",
Response: settings.ListNotificationDestinationsResponse{},
ReuseRequest: true,
}

var emptyUsersList = qa.HTTPFixture{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users?attributes=id%2CuserName&count=100&startIndex=1",
Response: map[string]any{},
ReuseRequest: true,
}

var emptySpnsList = qa.HTTPFixture{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals?attributes=id%2CuserName&count=100&startIndex=1",
Response: map[string]any{},
ReuseRequest: true,
}

func TestImportingUsersGroupsSecretScopes(t *testing.T) {
Expand Down Expand Up @@ -739,6 +754,8 @@ func TestImportingNoResourcesError(t *testing.T) {
Groups: []scim.ComplexValue{},
},
},
emptyUsersList,
emptySpnsList,
noCurrentMetastoreAttached,
emptyLakeviewList,
emptyDestinationNotficationsList,
Expand Down
30 changes: 28 additions & 2 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,20 @@ var resourcesMap map[string]importable = map[string]importable{
}
return nameNormalizationRegex.ReplaceAllString(strings.Split(s, "@")[0], "_") + "_" + d.Id()
},
// TODO: we need to add List operation here as well
List: func(ic *importContext) error {
ic.getUsersMapping()
ic.allUsersMutex.RLocker().Lock()
userMapping := maps.Clone(ic.allUsersMapping)
ic.allUsersMutex.RLocker().Unlock()
for userName, userScimId := range userMapping {
log.Printf("[TRACE] Emitting user %s, SCIM id=%s", userName, userScimId)
ic.Emit(&resource{
Resource: "databricks_user",
ID: userScimId,
})
}
return nil
},
Search: func(ic *importContext, r *resource) error {
u, err := ic.findUserByName(r.Value, false)
if err != nil {
Expand Down Expand Up @@ -1113,7 +1126,20 @@ var resourcesMap map[string]importable = map[string]importable{
}
return name + "_" + d.Id()
},
// TODO: we need to add List operation here as well
List: func(ic *importContext) error {
ic.getSpsMapping()
ic.spsMutex.RLock()
spsMapping := maps.Clone(ic.allSpsMapping)
ic.spsMutex.RLocker().Unlock()
for applicationId, appScimId := range spsMapping {
log.Printf("[TRACE] Emitting service principal %s, SCIM id=%s", applicationId, appScimId)
ic.Emit(&resource{
Resource: "databricks_service_principal",
ID: appScimId,
})
}
return nil
},
Search: func(ic *importContext, r *resource) error {
u, err := ic.findSpnByAppID(r.Value, false)
if err != nil {
Expand Down