-
Notifications
You must be signed in to change notification settings - Fork 91
/
framework_datasource.go
55 lines (44 loc) · 1.15 KB
/
framework_datasource.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
package kernel
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/linode/terraform-provider-linode/v2/linode/helper"
)
func NewDataSource() datasource.DataSource {
return &DataSource{
BaseDataSource: helper.NewBaseDataSource(
helper.BaseDataSourceConfig{
Name: "linode_kernel",
Schema: &frameworkDatasourceSchema,
},
),
}
}
type DataSource struct {
helper.BaseDataSource
}
func (d *DataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
tflog.Debug(ctx, "Read data.linode_kernel")
client := d.Meta.Client
var data DataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
ctx = tflog.SetField(ctx, "kernel_id", data.ID.ValueString())
tflog.Trace(ctx, "client.GetKernel(...)")
kernel, err := client.GetKernel(ctx, data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Unable to get Kernel: %s", err.Error(),
)
return
}
data.ParseKernel(ctx, kernel)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}