-
Notifications
You must be signed in to change notification settings - Fork 423
/
Copy pathdata_dbfs_file_paths.go
62 lines (59 loc) · 1.44 KB
/
data_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
package storage
import (
"context"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/workspace"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceDbfsFilePaths() 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)
paths, err := NewDbfsAPI(ctx, m).List(path, recursive)
if err != nil {
return err
}
d.SetId(path)
pathList := []map[string]any{}
for _, pathInfo := range paths {
pathData := map[string]any{}
pathData["path"] = pathInfo.Path
pathData["file_size"] = pathInfo.FileSize
pathList = append(pathList, pathData)
}
// nolint
d.Set("path_list", pathList)
return nil
},
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: workspace.PathListHash,
},
},
}
}