@@ -323,6 +323,8 @@ var resourcesMap map[string]importable = map[string]importable{
323323 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
324324 {Path : "init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "workspace_path" ,
325325 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
326+ {Path : "init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "path" ,
327+ MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
326328 },
327329 List : func (ic * importContext ) error {
328330 clusters , err := clusters .NewClustersAPI (ic .Context , ic .Client ).List ()
@@ -470,6 +472,8 @@ var resourcesMap map[string]importable = map[string]importable{
470472 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
471473 {Path : "task.new_cluster.init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "workspace_path" ,
472474 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
475+ {Path : "task.new_cluster.init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "path" ,
476+ MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
473477 {Path : "task.notebook_task.base_parameters" , Resource : "databricks_repo" , Match : "workspace_path" ,
474478 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
475479 {Path : "task.notebook_task.notebook_path" , Resource : "databricks_repo" , Match : "path" ,
@@ -492,6 +496,8 @@ var resourcesMap map[string]importable = map[string]importable{
492496 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
493497 {Path : "job_cluster.new_cluster.init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "workspace_path" ,
494498 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
499+ {Path : "job_cluster.new_cluster.init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "path" ,
500+ MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
495501 },
496502 Import : func (ic * importContext , r * resource ) error {
497503 var job jobs.JobSettingsResource
@@ -579,8 +585,8 @@ var resourcesMap map[string]importable = map[string]importable{
579585 }
580586 if task .DbtTask .Source == "WORKSPACE" {
581587 directory := task .DbtTask .ProjectDirectory
582- if strings . HasPrefix (directory , "/Repos" ) {
583- ic .emitRepoByPath (directory )
588+ if ic . isInRepoOrGitFolder (directory , true ) {
589+ ic .emitRepoOrGitFolder (directory , true )
584590 } else {
585591 // Traverse the dbt project directory and emit all objects found in it
586592 nbAPI := workspace .NewNotebooksAPI (ic .Context , ic .Client )
@@ -1456,40 +1462,51 @@ var resourcesMap map[string]importable = map[string]importable{
14561462 return nameNormalizationRegex .ReplaceAllString (name [7 :], "_" ) + "_" + d .Id ()
14571463 },
14581464 Search : func (ic * importContext , r * resource ) error {
1459- reposAPI := repos .NewReposAPI (ic .Context , ic .Client )
1460- notebooksAPI := workspace .NewNotebooksAPI (ic .Context , ic .Client )
1461- repoDir , err := notebooksAPI .Read (r .Value )
1465+ repoDir , err := ic .workspaceClient .Workspace .GetStatusByPath (ic .Context , r .Value )
14621466 if err != nil {
14631467 return err
14641468 }
1465- repo , err := reposAPI .Read (fmt .Sprintf ("%d" , repoDir .ObjectID ))
1466- if err != nil {
1467- return err
1469+ if repoDir .ObjectType != sdk_workspace .ObjectTypeRepo {
1470+ return fmt .Errorf ("object %s is not a repo" , r .Value )
1471+ }
1472+ if repoDir .ResourceId != "" {
1473+ r .ID = repoDir .ResourceId
1474+ } else {
1475+ r .ID = strconv .FormatInt (repoDir .ObjectId , 10 )
14681476 }
1469- r .ID = fmt .Sprintf ("%d" , repo .ID )
14701477 return nil
14711478 },
14721479 List : func (ic * importContext ) error {
1473- objList , err := repos .NewReposAPI (ic .Context , ic .Client ).ListAll ()
1474- if err != nil {
1475- return err
1476- }
1477- for offset , repo := range objList {
1480+ it := ic .workspaceClient .Repos .List (ic .Context , sdk_workspace.ListReposRequest {PathPrefix : "/Workspace" })
1481+ i := 1
1482+ for it .HasNext (ic .Context ) {
1483+ repo , err := it .Next (ic .Context )
1484+ if err != nil {
1485+ return err
1486+ }
14781487 if repo .Url != "" {
14791488 ic .Emit (& resource {
14801489 Resource : "databricks_repo" ,
1481- ID : fmt . Sprintf ( "%d" , repo .ID ),
1490+ ID : strconv . FormatInt ( repo .Id , 10 ),
14821491 })
14831492 } else {
14841493 log .Printf ("[WARN] ignoring databricks_repo without Git provider. Path: %s" , repo .Path )
14851494 ic .addIgnoredResource (fmt .Sprintf ("databricks_repo. path=%s" , repo .Path ))
14861495 }
1487- log .Printf ("[INFO] Scanned %d of %d repos" , offset + 1 , len (objList ))
1496+ if i % 50 == 0 {
1497+ log .Printf ("[INFO] Scanned %d repos" , i )
1498+ }
1499+ i ++
14881500 }
14891501 return nil
14901502 },
14911503 Import : func (ic * importContext , r * resource ) error {
1492- ic .emitUserOrServicePrincipalForPath (r .Data .Get ("path" ).(string ), "/Repos" )
1504+ path := maybeStripWorkspacePrefix (r .Data .Get ("path" ).(string ))
1505+ if strings .HasPrefix (path , "/Repos" ) {
1506+ ic .emitUserOrServicePrincipalForPath (path , "/Repos" )
1507+ } else if strings .HasPrefix (path , "/Users" ) {
1508+ ic .emitUserOrServicePrincipalForPath (path , "/Users" )
1509+ }
14931510 ic .emitPermissionsIfNotIgnored (r , fmt .Sprintf ("/repos/%s" , r .ID ),
14941511 "repo_" + ic .Importables ["databricks_repo" ].Name (ic , r .Data ))
14951512 return nil
@@ -1518,12 +1535,15 @@ var resourcesMap map[string]importable = map[string]importable{
15181535 }
15191536 return shouldIgnore
15201537 },
1521-
15221538 Depends : []reference {
15231539 {Path : "path" , Resource : "databricks_user" , Match : "repos" ,
15241540 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
15251541 {Path : "path" , Resource : "databricks_service_principal" , Match : "repos" ,
15261542 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
1543+ {Path : "path" , Resource : "databricks_user" , Match : "home" ,
1544+ MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
1545+ {Path : "path" , Resource : "databricks_service_principal" , Match : "home" ,
1546+ MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
15271547 },
15281548 },
15291549 "databricks_workspace_conf" : {
@@ -2236,6 +2256,8 @@ var resourcesMap map[string]importable = map[string]importable{
22362256 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
22372257 {Path : "cluster.init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "workspace_path" ,
22382258 MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
2259+ {Path : "cluster.init_scripts.workspace.destination" , Resource : "databricks_repo" , Match : "path" ,
2260+ MatchType : MatchPrefix , SearchValueTransformFunc : appendEndingSlashToDirName },
22392261 },
22402262 },
22412263 "databricks_directory" : {
@@ -3436,8 +3458,8 @@ var resourcesMap map[string]importable = map[string]importable{
34363458 },
34373459 Import : func (ic * importContext , r * resource ) error {
34383460 path := r .Data .Get ("path" ).(string )
3439- if strings . HasPrefix (path , "/Repos" ) {
3440- ic .emitRepoByPath (path )
3461+ if ic . isInRepoOrGitFolder (path , false ) {
3462+ ic .emitRepoOrGitFolder (path , false )
34413463 return nil
34423464 }
34433465 parts := strings .Split (path , "/" )
@@ -3459,10 +3481,7 @@ var resourcesMap map[string]importable = map[string]importable{
34593481 "dashboard_" + ic .Importables ["databricks_dashboard" ].Name (ic , r .Data ))
34603482 parentPath := r .Data .Get ("parent_path" ).(string )
34613483 if parentPath != "" && parentPath != "/" {
3462- ic .Emit (& resource {
3463- Resource : "databricks_directory" ,
3464- ID : parentPath ,
3465- })
3484+ ic .emitDirectoryOrRepo (parentPath )
34663485 }
34673486 warehouseId := r .Data .Get ("warehouse_id" ).(string )
34683487 if warehouseId != "" {
@@ -3478,7 +3497,7 @@ var resourcesMap map[string]importable = map[string]importable{
34783497 return pathString == "dashboard_change_detected" || shouldOmitMd5Field (ic , pathString , as , d )
34793498 },
34803499 Ignore : func (ic * importContext , r * resource ) bool {
3481- return strings . HasPrefix (r .Data .Get ("path" ).(string ), "/Repos" ) || strings . HasPrefix (r .Data .Get ("parent_path" ).(string ), "/Repos" )
3500+ return ic . isInRepoOrGitFolder (r .Data .Get ("path" ).(string ), false ) || ic . isInRepoOrGitFolder (r .Data .Get ("parent_path" ).(string ), true )
34823501 },
34833502 Depends : []reference {
34843503 {Path : "file_path" , File : true },
0 commit comments