-
Notifications
You must be signed in to change notification settings - Fork 353
/
data_notebook.go
73 lines (70 loc) · 1.54 KB
/
data_notebook.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
66
67
68
69
70
71
72
73
package workspace
import (
"context"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
// DataSourceNotebook ...
func DataSourceNotebook() common.Resource {
s := map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"format": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"DBC",
"SOURCE",
"HTML",
}, false),
},
"content": {
Type: schema.TypeString,
Computed: true,
},
"language": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"object_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"object_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
}
return common.Resource{
Schema: s,
Read: func(ctx context.Context, d *schema.ResourceData, m *common.DatabricksClient) error {
notebooksAPI := NewNotebooksAPI(ctx, m)
path := d.Get("path").(string)
format := d.Get("format").(string)
notebookContent, err := notebooksAPI.Export(path, format)
if err != nil {
return err
}
d.SetId(path)
// nolint
d.Set("content", notebookContent)
objectStatus, err := notebooksAPI.Read(d.Id())
if err != nil {
return err
}
err = common.StructToData(objectStatus, s, d)
if err != nil {
return err
}
return nil
},
}
}