diff --git a/exporter/context.go b/exporter/context.go index 28fddf80f2..ee3f2a753b 100644 --- a/exporter/context.go +++ b/exporter/context.go @@ -360,10 +360,10 @@ func (ic *importContext) Run() error { if err != nil { return err } + ic.meUserName = me.UserName for _, g := range me.Groups { if g.Display == "admins" { ic.meAdmin = true - ic.meUserName = me.UserName break } } diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index 174a766409..30c92591d6 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -2553,7 +2553,19 @@ resource "databricks_pipeline" "def" { func TestImportingRunJobTask(t *testing.T) { qa.HTTPFixturesApply(t, []qa.HTTPFixture{ - meAdminFixture, + { + Method: "GET", + ReuseRequest: true, + Resource: "/api/2.0/preview/scim/v2/Me", + Response: scim.User{ + Groups: []scim.ComplexValue{ + { + Display: "admins", + }, + }, + UserName: "user@domain.com", + }, + }, noCurrentMetastoreAttached, emptyRepos, emptyIpAccessLIst, @@ -2596,5 +2608,11 @@ func TestImportingRunJobTask(t *testing.T) { assert.True(t, strings.Contains(contentStr, `job_id = databricks_job.jartask_932035899730845.id`)) assert.True(t, strings.Contains(contentStr, `resource "databricks_job" "runjobtask_1047501313827425"`)) assert.True(t, strings.Contains(contentStr, `resource "databricks_job" "jartask_932035899730845"`)) + assert.True(t, strings.Contains(contentStr, `run_as { + service_principal_name = "c1b2a35b-87c4-481a-a0fb-0508be621957" + }`)) + assert.False(t, strings.Contains(contentStr, `run_as { + user_name = "user@domain.com" + }`)) }) } diff --git a/exporter/importables.go b/exporter/importables.go index 165081f12c..032ab855fc 100644 --- a/exporter/importables.go +++ b/exporter/importables.go @@ -635,6 +635,17 @@ var resourcesMap map[string]importable = map[string]importable{ if js.NotificationSettings != nil { return reflect.DeepEqual(*js.NotificationSettings, sdk_jobs.JobNotificationSettings{}) } + case "run_as": + if js.RunAs != nil && (js.RunAs.UserName != "" || js.RunAs.ServicePrincipalName != "") { + var user string + if js.RunAs.UserName != "" { + user = js.RunAs.UserName + } else { + user = js.RunAs.ServicePrincipalName + } + return user == ic.meUserName + } + return true } if strings.HasPrefix(pathString, "task.") { parts := strings.Split(pathString, ".") diff --git a/exporter/test-data/run-job-child.json b/exporter/test-data/run-job-child.json index 4cc2c7a6f2..6131aed35a 100644 --- a/exporter/test-data/run-job-child.json +++ b/exporter/test-data/run-job-child.json @@ -1,6 +1,8 @@ { "created_time":1678702840675, "job_id":932035899730845, + "run_as_user_name": "c1b2a35b-87c4-481a-a0fb-0508be621957", + "run_as_owner": false, "settings": { "format":"MULTI_TASK", "max_concurrent_runs":1, diff --git a/exporter/test-data/run-job-main.json b/exporter/test-data/run-job-main.json index 0430f6fd8a..15390aa00d 100644 --- a/exporter/test-data/run-job-main.json +++ b/exporter/test-data/run-job-main.json @@ -1,6 +1,8 @@ { "created_time":1700654567867, "job_id":1047501313827425, + "run_as_user_name": "user@domain.com", + "run_as_owner": false, "settings": { "format":"MULTI_TASK", "max_concurrent_runs":1,