Skip to content

Commit

Permalink
[Exporter] Emit WSFS/UC files from parameters in the jobs
Browse files Browse the repository at this point in the history
The global `parameters` array may contain references to files on Workspace File
System (WSFS) or UC Volumes.  This PR adds emitting of these files and handling references
  • Loading branch information
alexott committed Dec 13, 2024
1 parent 8b63df1 commit bb532e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
21 changes: 17 additions & 4 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,23 @@ var resourcesMap map[string]importable = map[string]importable{
{Path: "task.sql_task.dashboard.dashboard_id", Resource: "databricks_sql_dashboard"},
{Path: "task.sql_task.query.query_id", Resource: "databricks_query"},
{Path: "task.sql_task.warehouse_id", Resource: "databricks_sql_endpoint"},
{Path: "task.webhook_notifications.on_duration_warning_threshold_exceeded.id", Resource: "databricks_notification_destination"},
{Path: "task.webhook_notifications.on_duration_warning_threshold_exceeded.id",
Resource: "databricks_notification_destination"},
{Path: "task.webhook_notifications.on_failure.id", Resource: "databricks_notification_destination"},
{Path: "task.webhook_notifications.on_start.id", Resource: "databricks_notification_destination"},
{Path: "task.webhook_notifications.on_success.id", Resource: "databricks_notification_destination"},
{Path: "task.webhook_notifications.on_streaming_backlog_exceeded.id", Resource: "databricks_notification_destination"},
{Path: "parameter.default", Resource: "databricks_workspace_file", Match: "workspace_path"},
{Path: "parameter.default", Resource: "databricks_workspace_file", Match: "path"},
{Path: "parameter.default", Resource: "databricks_file", Match: "path"},
{Path: "task.email_notifications.on_duration_warning_threshold_exceeded", Resource: "databricks_user",
Match: "user_name", MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_failure", Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_start", Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_success", Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_failure", Resource: "databricks_user", Match: "user_name",
MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_start", Resource: "databricks_user", Match: "user_name",
MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_success", Resource: "databricks_user", Match: "user_name",
MatchType: MatchCaseInsensitive},
{Path: "task.email_notifications.on_streaming_backlog_exceeded", Resource: "databricks_user",
Match: "user_name", MatchType: MatchCaseInsensitive},
{Path: "run_as.user_name", Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
Expand Down Expand Up @@ -492,6 +499,8 @@ var resourcesMap map[string]importable = map[string]importable{
MatchType: MatchPrefix, SearchValueTransformFunc: appendEndingSlashToDirName},
{Path: "job_cluster.new_cluster.init_scripts.workspace.destination", Resource: "databricks_repo", Match: "workspace_path",
MatchType: MatchPrefix, SearchValueTransformFunc: appendEndingSlashToDirName},
{Path: "parameter.default", Resource: "databricks_repo", Match: "workspace_path",
MatchType: MatchPrefix, SearchValueTransformFunc: appendEndingSlashToDirName},
},
Import: func(ic *importContext, r *resource) error {
var job jobs.JobSettingsResource
Expand Down Expand Up @@ -662,6 +671,10 @@ var resourcesMap map[string]importable = map[string]importable{
ic.emitJobsDestinationNotifications(job.WebhookNotifications.OnStart)
ic.emitJobsDestinationNotifications(job.WebhookNotifications.OnStreamingBacklogExceeded)
}
for _, param := range job.Parameters {
ic.emitIfWsfsFile(param.Default)
ic.emitIfVolumeFile(param.Default)
}

return ic.importLibraries(r.Data, s)
},
Expand Down
3 changes: 1 addition & 2 deletions exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ func (ic *importContext) emitIfDbfsFile(path string) {

func (ic *importContext) emitIfWsfsFile(path string) {
if strings.HasPrefix(path, "/Workspace/") {
normalPath := strings.TrimPrefix(path, "/Workspace")
ic.emitWorkspaceFileOrRepo(normalPath)
ic.emitWorkspaceFileOrRepo(maybeStringWorkspacePrefix(path))
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/util_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func isRepoPath(path string) bool {

func maybeStringWorkspacePrefix(path string) string {
if strings.HasPrefix(path, "/Workspace/") {
return path[10:]
return strings.TrimPrefix(path, "/Workspace")
}
return path
}
Expand Down

0 comments on commit bb532e6

Please sign in to comment.