-
Notifications
You must be signed in to change notification settings - Fork 353
/
data_source_databricks_dbfs_file_paths.go
65 lines (58 loc) · 1.4 KB
/
data_source_databricks_dbfs_file_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
65
package databricks
import (
"github.com/databrickslabs/databricks-terraform/client/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceDBFSFilePaths() *schema.Resource {
return &schema.Resource{
Read: dataSourceDBFSFilePathsRead,
Schema: map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"recursive": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},
"path_list": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Optional: true,
},
"file_size": {
Type: schema.TypeInt,
Optional: true,
},
},
},
Set: notebookPathListHash,
},
},
}
}
func dataSourceDBFSFilePathsRead(d *schema.ResourceData, m interface{}) error {
path := d.Get("path").(string)
recursive := d.Get("recursive").(bool)
client := m.(*service.DBApiClient)
paths, err := client.DBFS().List(path, recursive)
if err != nil {
return err
}
d.SetId(path)
pathList := []map[string]interface{}{}
for _, pathInfo := range paths {
pathData := map[string]interface{}{}
pathData["path"] = pathInfo.Path
pathData["file_size"] = pathInfo.FileSize
pathList = append(pathList, pathData)
}
err = d.Set("path_list", pathList)
return err
}