@@ -749,8 +749,8 @@ var resourcesMap map[string]importable = map[string]importable{
749749 {Path : "registered_model_id" , Resource : "databricks_mlflow_model" },
750750 {Path : "experiment_id" , Resource : "databricks_mlflow_experiment" },
751751 {Path : "repo_id" , Resource : "databricks_repo" },
752- {Path : "directory_path " , Resource : "databricks_directory" },
753- {Path : "notebook_path " , Resource : "databricks_notebook" },
752+ {Path : "directory_id " , Resource : "databricks_directory" , Match : "object_id " },
753+ {Path : "notebook_id " , Resource : "databricks_notebook" , Match : "object_id " },
754754 {Path : "access_control.user_name" , Resource : "databricks_user" , Match : "user_name" },
755755 {Path : "access_control.group_name" , Resource : "databricks_group" , Match : "display_name" },
756756 {Path : "access_control.service_principal_name" , Resource : "databricks_service_principal" , Match : "application_id" },
@@ -1163,6 +1163,28 @@ var resourcesMap map[string]importable = map[string]importable{
11631163 name := r .ID [1 :] + ext [language ] // todo: replace non-alphanum+/ with _
11641164 content , _ := base64 .StdEncoding .DecodeString (contentB64 )
11651165 fileName , err := ic .createFileIn ("notebooks" , name , []byte (content ))
1166+ splits := strings .Split (r .Name , "_" )
1167+ notebookId := splits [len (splits )- 1 ]
1168+ directorySplits := strings .Split (r .ID , "/" )
1169+ directorySplits = directorySplits [:len (directorySplits )- 1 ]
1170+ directoryPath := strings .Join (directorySplits , "/" )
1171+
1172+ if ic .meAdmin {
1173+ ic .Emit (& resource {
1174+ Resource : "databricks_permissions" ,
1175+ ID : fmt .Sprintf ("/notebooks/%s" , notebookId ),
1176+ Name : "notebook_" + ic .Importables ["databricks_notebook" ].Name (ic , r .Data ),
1177+ })
1178+ }
1179+
1180+ if ic .meAdmin {
1181+ ic .Emit (& resource {
1182+ Resource : "databricks_directory" ,
1183+ Attribute : "path" ,
1184+ Value : directoryPath ,
1185+ })
1186+ }
1187+
11661188 if err != nil {
11671189 return err
11681190 }
@@ -1515,4 +1537,64 @@ var resourcesMap map[string]importable = map[string]importable{
15151537 {Path : "library.whl" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
15161538 },
15171539 },
1540+ "databricks_directory" : {
1541+ Service : "notebooks" ,
1542+ Name : func (ic * importContext , d * schema.ResourceData ) string {
1543+ name := d .Get ("path" ).(string )
1544+ if name == "" {
1545+ return d .Id ()
1546+ } else {
1547+ name = nameNormalizationRegex .ReplaceAllString (name [1 :], "_" ) + "_" +
1548+ strconv .FormatInt (int64 (d .Get ("object_id" ).(int )), 10 )
1549+ }
1550+ return name
1551+ },
1552+ List : func (ic * importContext ) error {
1553+ notebooksAPI := workspace .NewNotebooksAPI (ic .Context , ic .Client )
1554+ directoryList , err := notebooksAPI .ListDirectories ("/" , true )
1555+ if err != nil {
1556+ return err
1557+ }
1558+ for offset , directory := range directoryList {
1559+ if strings .HasPrefix (directory .Path , "/Repos" ) {
1560+ continue
1561+ }
1562+ ic .Emit (& resource {
1563+ Resource : "databricks_directory" ,
1564+ ID : directory .Path ,
1565+ })
1566+ if offset % 50 == 0 {
1567+ log .Printf ("[INFO] Scanned %d of %d directories" ,
1568+ offset + 1 , len (directoryList ))
1569+ }
1570+ }
1571+ return nil
1572+ },
1573+ Import : func (ic * importContext , r * resource ) error {
1574+
1575+ ic .emitUserOrServicePrincipalForPath (r .ID , "/Users" )
1576+ splits := strings .Split (r .Name , "_" )
1577+ directoryId := splits [len (splits )- 1 ]
1578+
1579+ if ic .meAdmin {
1580+ ic .Emit (& resource {
1581+ Resource : "databricks_permissions" ,
1582+ ID : fmt .Sprintf ("/directories/%s" , directoryId ),
1583+ Name : "directory_" + ic .Importables ["databricks_directory" ].Name (ic , r .Data ),
1584+ })
1585+ }
1586+
1587+ if r .ID == "/Shared" || r .ID == "/Users" || ic .IsUserOrServicePrincipalDirectory (r .ID , "/Users" ) {
1588+ r .Mode = "data"
1589+ }
1590+
1591+ return nil
1592+
1593+ },
1594+ Body : resourceOrDataBlockBody ,
1595+ Depends : []reference {
1596+ {Path : "path" , Resource : "databricks_user" , Match : "home" , MatchType : MatchPrefix },
1597+ {Path : "path" , Resource : "databricks_service_principal" , Match : "home" , MatchType : MatchPrefix },
1598+ },
1599+ },
15181600}
0 commit comments