6
6
7
7
"github.com/hashicorp/terraform-plugin-framework/datasource"
8
8
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
9
+ "github.com/hashicorp/terraform-plugin-framework/types"
9
10
10
11
client "github.com/pomerium/enterprise-client-go"
11
12
"github.com/pomerium/enterprise-client-go/pb"
@@ -22,6 +23,7 @@ type ServiceAccountsDataSource struct {
22
23
}
23
24
24
25
type ServiceAccountsDataSourceModel struct {
26
+ NamespaceID types.String `tfsdk:"namespace_id"`
25
27
ServiceAccounts []ServiceAccountModel `tfsdk:"service_accounts"`
26
28
}
27
29
@@ -32,8 +34,11 @@ func (d *ServiceAccountsDataSource) Metadata(_ context.Context, req datasource.M
32
34
func (d * ServiceAccountsDataSource ) Schema (_ context.Context , _ datasource.SchemaRequest , resp * datasource.SchemaResponse ) {
33
35
resp .Schema = schema.Schema {
34
36
MarkdownDescription : "List all service accounts" ,
35
-
36
37
Attributes : map [string ]schema.Attribute {
38
+ "namespace_id" : schema.StringAttribute {
39
+ Optional : true ,
40
+ Description : "Namespace of the service accounts." ,
41
+ },
37
42
"service_accounts" : schema.ListNestedAttribute {
38
43
Computed : true ,
39
44
NestedObject : schema.NestedAttributeObject {
@@ -86,10 +91,18 @@ func (d *ServiceAccountsDataSource) Configure(_ context.Context, req datasource.
86
91
d .client = client
87
92
}
88
93
89
- func (d * ServiceAccountsDataSource ) Read (ctx context.Context , _ datasource.ReadRequest , resp * datasource.ReadResponse ) {
94
+ func (d * ServiceAccountsDataSource ) Read (ctx context.Context , req datasource.ReadRequest , resp * datasource.ReadResponse ) {
90
95
var data ServiceAccountsDataSourceModel
91
96
92
- serviceAccountsResp , err := d .client .PomeriumServiceAccountService .ListPomeriumServiceAccounts (ctx , & pb.ListPomeriumServiceAccountsRequest {})
97
+ resp .Diagnostics .Append (req .Config .Get (ctx , & data )... )
98
+ if resp .Diagnostics .HasError () {
99
+ return
100
+ }
101
+
102
+ listReq := & pb.ListPomeriumServiceAccountsRequest {
103
+ Namespace : data .NamespaceID .ValueString (),
104
+ }
105
+ serviceAccountsResp , err := d .client .PomeriumServiceAccountService .ListPomeriumServiceAccounts (ctx , listReq )
93
106
if err != nil {
94
107
resp .Diagnostics .AddError ("Error reading service accounts" , err .Error ())
95
108
return
0 commit comments