Skip to content

Commit e1aa0e2

Browse files
committed
(refactor) remove schema.go due to needing individual implementations per data source and resource.
1 parent 42ff8e8 commit e1aa0e2

8 files changed

+153
-157
lines changed

internal/provider/namespace.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55

66
"github.com/hashicorp/terraform-plugin-framework/diag"
77
"github.com/hashicorp/terraform-plugin-framework/resource"
8+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
9+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
10+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
811
"github.com/hashicorp/terraform-plugin-framework/types"
912
"github.com/hashicorp/terraform-plugin-log/tflog"
1013

@@ -36,7 +39,26 @@ func (r *NamespaceResource) Metadata(_ context.Context, req resource.MetadataReq
3639
}
3740

3841
func (r *NamespaceResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
39-
resp.Schema = NamespaceSchema(false)
42+
resp.Schema = schema.Schema{
43+
MarkdownDescription: "Namespace for Pomerium.",
44+
Attributes: map[string]schema.Attribute{
45+
"id": schema.StringAttribute{
46+
Computed: true,
47+
Description: "Unique identifier for the namespace.",
48+
PlanModifiers: []planmodifier.String{
49+
stringplanmodifier.UseStateForUnknown(),
50+
},
51+
},
52+
"name": schema.StringAttribute{
53+
Description: "Name of the namespace.",
54+
Required: true,
55+
},
56+
"parent_id": schema.StringAttribute{
57+
Description: "ID of the parent namespace (optional).",
58+
Optional: true,
59+
},
60+
},
61+
}
4062
}
4163

4264
func (r *NamespaceResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {

internal/provider/namespace_data_source.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ func (d *NamespaceDataSource) Metadata(_ context.Context, req datasource.Metadat
2828

2929
func (d *NamespaceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
3030
resp.Schema = schema.Schema{
31-
MarkdownDescription: "Namespace data source",
32-
31+
MarkdownDescription: "Namespace for Pomerium.",
3332
Attributes: map[string]schema.Attribute{
3433
"id": schema.StringAttribute{
3534
Required: true,

internal/provider/policy.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/diag"
88
"github.com/hashicorp/terraform-plugin-framework/path"
99
"github.com/hashicorp/terraform-plugin-framework/resource"
10+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1013
"github.com/hashicorp/terraform-plugin-framework/types"
1114
"github.com/hashicorp/terraform-plugin-log/tflog"
1215

@@ -38,7 +41,30 @@ func (r *PolicyResource) Metadata(_ context.Context, req resource.MetadataReques
3841
}
3942

4043
func (r *PolicyResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
41-
resp.Schema = PolicySchema(false)
44+
resp.Schema = schema.Schema{
45+
MarkdownDescription: "Policy for Pomerium.",
46+
Attributes: map[string]schema.Attribute{
47+
"id": schema.StringAttribute{
48+
Computed: true,
49+
Description: "Unique identifier for the policy.",
50+
PlanModifiers: []planmodifier.String{
51+
stringplanmodifier.UseStateForUnknown(),
52+
},
53+
},
54+
"name": schema.StringAttribute{
55+
Description: "Name of the policy.",
56+
Required: true,
57+
},
58+
"namespace_id": schema.StringAttribute{
59+
Description: "ID of the namespace the policy belongs to.",
60+
Required: true,
61+
},
62+
"ppl": schema.StringAttribute{
63+
Description: "Policy Policy Language (PPL) string.",
64+
Required: true,
65+
},
66+
},
67+
}
4268
}
4369

4470
func (r *PolicyResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {

internal/provider/policy_data_source.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ func (d *PolicyDataSource) Metadata(_ context.Context, req datasource.MetadataRe
2929

3030
func (d *PolicyDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
3131
resp.Schema = schema.Schema{
32-
MarkdownDescription: "Policy data source",
33-
32+
MarkdownDescription: "Policy for Pomerium.",
3433
Attributes: map[string]schema.Attribute{
3534
"id": schema.StringAttribute{
3635
Required: true,

internal/provider/route.go

+37-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/diag"
99
"github.com/hashicorp/terraform-plugin-framework/path"
1010
"github.com/hashicorp/terraform-plugin-framework/resource"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
13+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1114
"github.com/hashicorp/terraform-plugin-framework/types"
1215
"github.com/hashicorp/terraform-plugin-log/tflog"
1316
client "github.com/pomerium/enterprise-client-go"
@@ -37,7 +40,40 @@ func (r *RouteResource) Metadata(_ context.Context, req resource.MetadataRequest
3740
}
3841

3942
func (r *RouteResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
40-
resp.Schema = RouteSchema(false)
43+
resp.Schema = schema.Schema{
44+
MarkdownDescription: "Route for Pomerium.",
45+
Attributes: map[string]schema.Attribute{
46+
"id": schema.StringAttribute{
47+
Computed: true,
48+
Description: "Unique identifier for the route.",
49+
PlanModifiers: []planmodifier.String{
50+
stringplanmodifier.UseStateForUnknown(),
51+
},
52+
},
53+
"name": schema.StringAttribute{
54+
Description: "Name of the route.",
55+
Required: true,
56+
},
57+
"from": schema.StringAttribute{
58+
Description: "From URL.",
59+
Required: true,
60+
},
61+
"to": schema.ListAttribute{
62+
ElementType: types.StringType,
63+
Description: "To URLs.",
64+
Required: true,
65+
},
66+
"namespace_id": schema.StringAttribute{
67+
Description: "ID of the namespace the route belongs to.",
68+
Required: true,
69+
},
70+
"policies": schema.ListAttribute{
71+
ElementType: types.StringType,
72+
Description: "List of policy IDs associated with the route.",
73+
Optional: true,
74+
},
75+
},
76+
}
4177
}
4278

4379
func (r *RouteResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {

internal/provider/schemas.go

-147
This file was deleted.

internal/provider/service_account.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/diag"
99
"github.com/hashicorp/terraform-plugin-framework/path"
1010
"github.com/hashicorp/terraform-plugin-framework/resource"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
13+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1114
"github.com/hashicorp/terraform-plugin-framework/types"
1215
"github.com/hashicorp/terraform-plugin-log/tflog"
1316

@@ -35,7 +38,38 @@ func (r *ServiceAccountResource) Metadata(_ context.Context, req resource.Metada
3538
}
3639

3740
func (r *ServiceAccountResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
38-
resp.Schema = ServiceAccountSchema(false)
41+
resp.Schema = schema.Schema{
42+
MarkdownDescription: "Service Account for Pomerium.",
43+
Attributes: map[string]schema.Attribute{
44+
"id": schema.StringAttribute{
45+
Computed: true,
46+
Description: "Unique identifier for the service account.",
47+
PlanModifiers: []planmodifier.String{
48+
stringplanmodifier.UseStateForUnknown(),
49+
},
50+
},
51+
"name": schema.StringAttribute{
52+
Description: "Name of the service account.",
53+
Required: true,
54+
},
55+
"namespace_id": schema.StringAttribute{
56+
Description: "ID of the namespace the service account belongs to.",
57+
Required: true,
58+
},
59+
"description": schema.StringAttribute{
60+
Description: "Description of the service account.",
61+
Optional: true,
62+
},
63+
"user_id": schema.StringAttribute{
64+
Computed: true,
65+
Description: "User ID associated with the service account.",
66+
},
67+
"expires_at": schema.StringAttribute{
68+
Computed: true,
69+
Description: "Timestamp when the service account expires.",
70+
},
71+
},
72+
}
3973
}
4074

4175
func (r *ServiceAccountResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {

internal/provider/service_account_data_source.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-framework/datasource"
88
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
9-
"github.com/hashicorp/terraform-plugin-framework/types"
109

1110
client "github.com/pomerium/enterprise-client-go"
1211
"github.com/pomerium/enterprise-client-go/pb"
@@ -29,7 +28,35 @@ func (d *ServiceAccountDataSource) Metadata(_ context.Context, req datasource.Me
2928
}
3029

3130
func (d *ServiceAccountDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
32-
resp.Schema = ServiceAccountSchema(true)
31+
resp.Schema = schema.Schema{
32+
MarkdownDescription: "Service Account for Pomerium.",
33+
Attributes: map[string]schema.Attribute{
34+
"id": schema.StringAttribute{
35+
Required: true,
36+
Description: "Unique identifier for the service account.",
37+
},
38+
"name": schema.StringAttribute{
39+
Computed: true,
40+
Description: "Name of the service account.",
41+
},
42+
"namespace_id": schema.StringAttribute{
43+
Computed: true,
44+
Description: "ID of the namespace the service account belongs to.",
45+
},
46+
"description": schema.StringAttribute{
47+
Computed: true,
48+
Description: "Description of the service account.",
49+
},
50+
"user_id": schema.StringAttribute{
51+
Computed: true,
52+
Description: "User ID associated with the service account.",
53+
},
54+
"expires_at": schema.StringAttribute{
55+
Computed: true,
56+
Description: "Timestamp when the service account expires.",
57+
},
58+
},
59+
}
3360
}
3461

3562
func (d *ServiceAccountDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {

0 commit comments

Comments
 (0)