-
Notifications
You must be signed in to change notification settings - Fork 353
/
data_notebook_paths.go
64 lines (61 loc) · 1.54 KB
/
data_notebook_paths.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package workspace
import (
"context"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// DataSourceNotebookPaths ...
func DataSourceNotebookPaths() common.Resource {
return common.Resource{
Read: func(ctx context.Context, d *schema.ResourceData, m *common.DatabricksClient) error {
path := d.Get("path").(string)
recursive := d.Get("recursive").(bool)
notebookList, err := NewNotebooksAPI(ctx, m).List(path, recursive, false)
if err != nil {
return err
}
d.SetId(path)
var notebookPathList []map[string]string
for _, v := range notebookList {
if v.ObjectType == Notebook {
notebookPathMap := map[string]string{}
notebookPathMap["path"] = v.Path
notebookPathMap["language"] = string(v.Language)
notebookPathList = append(notebookPathList, notebookPathMap)
}
}
// nolint
d.Set("notebook_path_list", notebookPathList)
return nil
},
Schema: map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"recursive": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},
"notebook_path_list": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"language": {
Type: schema.TypeString,
Optional: true,
},
"path": {
Type: schema.TypeString,
Optional: true,
},
},
},
Set: PathListHash,
},
},
}
}