4141 nameNormalizationRegex = regexp .MustCompile (`\W+` )
4242 jobClustersRegex = regexp .MustCompile (`^((job_cluster|task)\.[0-9]+\.new_cluster\.[0-9]+\.)` )
4343 dltClusterRegex = regexp .MustCompile (`^(cluster\.[0-9]+\.)` )
44+ uuidRegex = regexp .MustCompile (`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` )
4445 predefinedClusterPolicies = []string {"Personal Compute" , "Job Compute" , "Power User Compute" , "Shared Compute" }
4546 secretPathRegex = regexp .MustCompile (`^\{\{secrets\/([^\/]+)\/([^}]+)\}\}$` )
4647)
@@ -287,6 +288,7 @@ var resourcesMap map[string]importable = map[string]importable{
287288 {Path : "spark_python_task.parameters" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
288289 {Path : "spark_jar_task.jar_uri" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
289290 {Path : "notebook_task.notebook_path" , Resource : "databricks_notebook" },
291+ {Path : "notebook_task.notebook_path" , Resource : "databricks_repo" , Match : "path" , MatchType : MatchPrefix },
290292 {Path : "pipeline_task.pipeline_id" , Resource : "databricks_pipeline" },
291293 {Path : "task.library.jar" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
292294 {Path : "task.library.whl" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
@@ -295,6 +297,7 @@ var resourcesMap map[string]importable = map[string]importable{
295297 {Path : "task.spark_python_task.parameters" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
296298 {Path : "task.spark_jar_task.jar_uri" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
297299 {Path : "task.notebook_task.notebook_path" , Resource : "databricks_notebook" },
300+ {Path : "task.notebook_task.notebook_path" , Resource : "databricks_repo" , Match : "path" , MatchType : MatchPrefix },
298301 {Path : "task.pipeline_task.pipeline_id" , Resource : "databricks_pipeline" },
299302 {Path : "task.sql_task.query.query_id" , Resource : "databricks_sql_query" },
300303 {Path : "task.sql_task.dashboard.dashboard_id" , Resource : "databricks_sql_dashboard" },
@@ -359,10 +362,7 @@ var resourcesMap map[string]importable = map[string]importable{
359362 }
360363 }
361364 if job .NotebookTask != nil {
362- ic .Emit (& resource {
363- Resource : "databricks_notebook" ,
364- ID : job .NotebookTask .NotebookPath ,
365- })
365+ ic .emitNotebookOrRepo (job .NotebookTask .NotebookPath )
366366 }
367367 if job .PipelineTask != nil {
368368 ic .Emit (& resource {
@@ -373,10 +373,7 @@ var resourcesMap map[string]importable = map[string]importable{
373373 // Support for multitask jobs
374374 for _ , task := range job .Tasks {
375375 if task .NotebookTask != nil {
376- ic .Emit (& resource {
377- Resource : "databricks_notebook" ,
378- ID : task .NotebookTask .NotebookPath ,
379- })
376+ ic .emitNotebookOrRepo (task .NotebookTask .NotebookPath )
380377 }
381378 if task .PipelineTask != nil {
382379 ic .Emit (& resource {
@@ -958,7 +955,21 @@ var resourcesMap map[string]importable = map[string]importable{
958955 if name == "" {
959956 return d .Id ()
960957 }
961- return strings .TrimPrefix (name , "/" )
958+ return nameNormalizationRegex .ReplaceAllString (name [7 :], "_" )
959+ },
960+ Search : func (ic * importContext , r * resource ) error {
961+ reposAPI := repos .NewReposAPI (ic .Context , ic .Client )
962+ notebooksAPI := workspace .NewNotebooksAPI (ic .Context , ic .Client )
963+ repoDir , err := notebooksAPI .Read (r .Value )
964+ if err != nil {
965+ return err
966+ }
967+ repo , err := reposAPI .Read (fmt .Sprintf ("%d" , repoDir .ObjectID ))
968+ if err != nil {
969+ return err
970+ }
971+ r .ID = fmt .Sprintf ("%d" , repo .ID )
972+ return nil
962973 },
963974 List : func (ic * importContext ) error {
964975 repoList , err := repos .NewReposAPI (ic .Context , ic .Client ).ListAll ()
@@ -977,6 +988,7 @@ var resourcesMap map[string]importable = map[string]importable{
977988 return nil
978989 },
979990 Import : func (ic * importContext , r * resource ) error {
991+ ic .emitUserOrServicePrincipalForPath (r .Data .Get ("path" ).(string ), "/Repos" )
980992 if ic .meAdmin {
981993 ic .Emit (& resource {
982994 Resource : "databricks_permissions" ,
@@ -986,6 +998,17 @@ var resourcesMap map[string]importable = map[string]importable{
986998 }
987999 return nil
9881000 },
1001+ ShouldOmitField : func (ic * importContext , pathString string , as * schema.Schema , d * schema.ResourceData ) bool {
1002+ if pathString == "path" {
1003+ return false
1004+ }
1005+ return defaultShouldOmitFieldFunc (ic , pathString , as , d )
1006+ },
1007+
1008+ Depends : []reference {
1009+ {Path : "path" , Resource : "databricks_user" , Match : "repos" , MatchType : MatchPrefix },
1010+ {Path : "path" , Resource : "databricks_service_principal" , Match : "repos" , MatchType : MatchPrefix },
1011+ },
9891012 },
9901013 "databricks_workspace_conf" : {
9911014 Service : "workspace" ,
@@ -1094,6 +1117,7 @@ var resourcesMap map[string]importable = map[string]importable{
10941117 return nil
10951118 },
10961119 Import : func (ic * importContext , r * resource ) error {
1120+ ic .emitUserOrServicePrincipalForPath (r .ID , "/Users" )
10971121 notebooksAPI := workspace .NewNotebooksAPI (ic .Context , ic .Client )
10981122 contentB64 , err := notebooksAPI .Export (r .ID , "SOURCE" )
10991123 if err != nil {
@@ -1118,6 +1142,8 @@ var resourcesMap map[string]importable = map[string]importable{
11181142 },
11191143 Depends : []reference {
11201144 {Path : "source" , File : true },
1145+ {Path : "path" , Resource : "databricks_user" , Match : "home" , MatchType : MatchPrefix },
1146+ {Path : "path" , Resource : "databricks_service_principal" , Match : "home" , MatchType : MatchPrefix },
11211147 },
11221148 },
11231149 "databricks_sql_query" : {
@@ -1391,10 +1417,7 @@ var resourcesMap map[string]importable = map[string]importable{
13911417 common .DataToStructPointer (r .Data , s , & pipeline )
13921418 for _ , lib := range pipeline .Libraries {
13931419 if lib .Notebook != nil {
1394- ic .Emit (& resource {
1395- Resource : "databricks_notebook" ,
1396- ID : lib .Notebook .Path ,
1397- })
1420+ ic .emitNotebookOrRepo (lib .Notebook .Path )
13981421 }
13991422 ic .emitIfDbfsFile (lib .Jar )
14001423 ic .emitIfDbfsFile (lib .Whl )
@@ -1452,6 +1475,7 @@ var resourcesMap map[string]importable = map[string]importable{
14521475 {Path : "cluster.instance_pool_id" , Resource : "databricks_instance_pool" },
14531476 {Path : "cluster.driver_instance_pool_id" , Resource : "databricks_instance_pool" },
14541477 {Path : "library.notebook.path" , Resource : "databricks_notebook" },
1478+ {Path : "library.notebook.path" , Resource : "databricks_repo" , Match : "path" , MatchType : MatchPrefix },
14551479 {Path : "library.jar" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
14561480 {Path : "library.whl" , Resource : "databricks_dbfs_file" , Match : "dbfs_path" },
14571481 },
0 commit comments