/
datasource_webtargets.go
37 lines (34 loc) · 1.47 KB
/
datasource_webtargets.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
package webtarget
import (
"context"
"github.com/bastionzero/bastionzero-sdk-go/bastionzero"
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/service/targets"
"github.com/bastionzero/terraform-provider-bastionzero/bastionzero/target"
"github.com/bastionzero/terraform-provider-bastionzero/internal/bzdatasource"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
)
func NewWebTargetsDataSource() datasource.DataSource {
return bzdatasource.NewListDataSource(&bzdatasource.ListDataSourceConfig[webTargetModel, targets.WebTarget]{
BaseListDataSourceConfig: &bzdatasource.BaseListDataSourceConfig[webTargetModel, targets.WebTarget]{
RecordSchema: makeWebTargetDataSourceSchema(
&target.BaseTargetDataSourceAttributeOptions{
IsIDComputed: true,
IsNameComputed: true,
}),
MetadataTypeName: "web_targets",
ResultAttributeName: "targets",
PrettyAttributeName: "Web targets",
FlattenAPIModel: func(ctx context.Context, apiObject *targets.WebTarget) (state *webTargetModel, diags diag.Diagnostics) {
state = new(webTargetModel)
setWebTargetAttributes(ctx, state, apiObject)
return
},
MarkdownDescription: "Get a list of all Web targets in your BastionZero organization.",
},
ListAPIModels: func(ctx context.Context, client *bastionzero.Client) ([]targets.WebTarget, error) {
targets, _, err := client.Targets.ListWebTargets(ctx)
return targets, err
},
})
}