/
group_service_account.go
62 lines (47 loc) · 1.89 KB
/
group_service_account.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 datasources
import (
"context"
"fmt"
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core"
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/model"
fivetranSchema "github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/schema"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func GroupServiceAccount() datasource.DataSource {
return &groupServiceAccount{}
}
// Ensure the implementation satisfies the desired interfaces.
var _ datasource.DataSourceWithConfigure = &groupServiceAccount{}
type groupServiceAccount struct {
core.ProviderDatasource
}
func (d *groupServiceAccount) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "fivetran_group_service_account"
}
func (d *groupServiceAccount) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: fivetranSchema.GroupServiceAccount().GetDatasourceSchema(),
}
}
func (d *groupServiceAccount) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
if d.GetClient() == nil {
resp.Diagnostics.AddError(
"Unconfigured Fivetran Client",
"Please report this issue to the provider developers.",
)
return
}
var data model.GroupServiceAccount
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
groupServiceAccountResponse, err := d.GetClient().NewGroupServiceAccount().GroupID(data.ID.ValueString()).Do(ctx)
if err != nil {
resp.Diagnostics.AddError(
"Read error.",
fmt.Sprintf("%v; code: %v; message: %v", err, groupServiceAccountResponse.Code, groupServiceAccountResponse.Message),
)
return
}
data.ReadFromResponse(groupServiceAccountResponse)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}