Skip to content

Commit 20bed8c

Browse files
committed
use optional infer
1 parent 2858c7b commit 20bed8c

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

example/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ resource "pomerium_route" "test_route" {
105105
pomerium_policy.test_policy.id,
106106
]
107107
jwt_groups_filter = {
108+
groups = ["group1", "group2"]
108109
infer_from_ppl = true
109110
}
110111
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/terraform-plugin-go v0.25.0
1212
github.com/hashicorp/terraform-plugin-log v0.9.0
1313
github.com/iancoleman/strcase v0.3.0
14-
github.com/pomerium/enterprise-client-go v0.28.1-0.20250124233741-2592eb1169f7
14+
github.com/pomerium/enterprise-client-go v0.28.1-0.20250129215653-11b7f67dcbf4
1515
github.com/pomerium/pomerium v0.28.1-0.20250122205906-0bd6d8cc8315
1616
github.com/rs/zerolog v1.33.0
1717
github.com/stretchr/testify v1.10.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ github.com/pomerium/csrf v1.7.0 h1:Qp4t6oyEod3svQtKfJZs589mdUTWKVf7q0PgCKYCshY=
231231
github.com/pomerium/csrf v1.7.0/go.mod h1:hAPZV47mEj2T9xFs+ysbum4l7SF1IdrryYaY6PdoIqw=
232232
github.com/pomerium/enterprise-client-go v0.28.1-0.20250124233741-2592eb1169f7 h1:m5rq102yZxD4UWUfyq5M0+butxmhuIeh5STMjMSQzJI=
233233
github.com/pomerium/enterprise-client-go v0.28.1-0.20250124233741-2592eb1169f7/go.mod h1:fnT1uLizb7e1aodN9SqSiqg6iYlWoppWFdaPlSR5eKc=
234+
github.com/pomerium/enterprise-client-go v0.28.1-0.20250129215653-11b7f67dcbf4 h1:hT9HWRvA54ujeCl4OS8voVl5oeRhyAjxKs/7ODBJoGo=
235+
github.com/pomerium/enterprise-client-go v0.28.1-0.20250129215653-11b7f67dcbf4/go.mod h1:fnT1uLizb7e1aodN9SqSiqg6iYlWoppWFdaPlSR5eKc=
234236
github.com/pomerium/pomerium v0.28.1-0.20250122205906-0bd6d8cc8315 h1:pdCpEr39m9UomjVkTp17Q4qeTbDZj7yxEffdBXZADe4=
235237
github.com/pomerium/pomerium v0.28.1-0.20250122205906-0bd6d8cc8315/go.mod h1:ujclJDq2BGZuSe2/9Lz2w4MpTVIR8DrR05qyjk1OcsU=
236238
github.com/pomerium/protoutil v0.0.0-20240813175624-47b7ac43ff46 h1:NRTg8JOXCxcIA1lAgD74iYud0rbshbWOB3Ou4+Huil8=

internal/provider/jwt_group_filter.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var (
15-
jwtGroupsFilterSchema = schema.SingleNestedAttribute{
15+
JWTGroupsFilterSchema = schema.SingleNestedAttribute{
1616
Optional: true,
1717
Description: "JWT Groups Filter",
1818
Attributes: map[string]schema.Attribute{
@@ -28,7 +28,7 @@ var (
2828
},
2929
},
3030
}
31-
jwtGroupsFilterSchemaAttr = map[string]attr.Type{
31+
JWTGroupsFilterSchemaAttr = map[string]attr.Type{
3232
"groups": types.SetType{
3333
ElemType: types.StringType,
3434
},
@@ -41,7 +41,7 @@ func JWTGroupsFilterFromPB(
4141
src *pb.JwtGroupsFilter,
4242
) {
4343
if src == nil {
44-
*dst = types.ObjectNull(jwtGroupsFilterSchemaAttr)
44+
*dst = types.ObjectNull(JWTGroupsFilterSchemaAttr)
4545
return
4646
}
4747

@@ -56,9 +56,9 @@ func JWTGroupsFilterFromPB(
5656
attrs["groups"] = types.SetValueMust(types.StringType, vals)
5757
}
5858

59-
attrs["infer_from_ppl"] = types.BoolValue(src.InferFromPpl)
59+
attrs["infer_from_ppl"] = types.BoolPointerValue(src.InferFromPpl)
6060

61-
*dst = types.ObjectValueMust(jwtGroupsFilterSchemaAttr, attrs)
61+
*dst = types.ObjectValueMust(JWTGroupsFilterSchemaAttr, attrs)
6262
}
6363

6464
func JWTGroupsFilterToPB(
@@ -74,7 +74,7 @@ func JWTGroupsFilterToPB(
7474

7575
type jwtOptions struct {
7676
Groups []string `tfsdk:"groups"`
77-
InferFromPpl bool `tfsdk:"infer_from_ppl"`
77+
InferFromPpl *bool `tfsdk:"infer_from_ppl"`
7878
}
7979
var opts jwtOptions
8080
d := src.As(ctx, &opts, basetypes.ObjectAsOptions{

internal/provider/jwt_group_filter_test.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package provider
1+
package provider_test
22

33
import (
44
"context"
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-framework/diag"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
"github.com/pomerium/enterprise-client-go/pb"
12+
"github.com/pomerium/enterprise-terraform-provider/internal/provider"
1213
"github.com/stretchr/testify/assert"
1314
"google.golang.org/protobuf/testing/protocmp"
1415
)
@@ -22,15 +23,15 @@ func TestJWTGroupsFilterFromPB(t *testing.T) {
2223
{
2324
name: "nil input",
2425
input: nil,
25-
expected: types.ObjectNull(jwtGroupsFilterSchemaAttr),
26+
expected: types.ObjectNull(provider.JWTGroupsFilterSchemaAttr),
2627
},
2728
{
2829
name: "empty groups",
2930
input: &pb.JwtGroupsFilter{
3031
Groups: []string{},
31-
InferFromPpl: false,
32+
InferFromPpl: P(false),
3233
},
33-
expected: types.ObjectValueMust(jwtGroupsFilterSchemaAttr, map[string]attr.Value{
34+
expected: types.ObjectValueMust(provider.JWTGroupsFilterSchemaAttr, map[string]attr.Value{
3435
"groups": types.SetValueMust(types.StringType, []attr.Value{}),
3536
"infer_from_ppl": types.BoolValue(false),
3637
}),
@@ -39,9 +40,9 @@ func TestJWTGroupsFilterFromPB(t *testing.T) {
3940
name: "with groups",
4041
input: &pb.JwtGroupsFilter{
4142
Groups: []string{"group1", "group2"},
42-
InferFromPpl: true,
43+
InferFromPpl: P(true),
4344
},
44-
expected: types.ObjectValueMust(jwtGroupsFilterSchemaAttr, map[string]attr.Value{
45+
expected: types.ObjectValueMust(provider.JWTGroupsFilterSchemaAttr, map[string]attr.Value{
4546
"groups": types.SetValueMust(types.StringType, []attr.Value{
4647
types.StringValue("group1"),
4748
types.StringValue("group2"),
@@ -54,7 +55,7 @@ func TestJWTGroupsFilterFromPB(t *testing.T) {
5455
for _, tc := range tests {
5556
t.Run(tc.name, func(t *testing.T) {
5657
var result types.Object
57-
JWTGroupsFilterFromPB(&result, tc.input)
58+
provider.JWTGroupsFilterFromPB(&result, tc.input)
5859
diff := cmp.Diff(tc.expected, result)
5960
assert.Empty(t, diff)
6061
})
@@ -70,23 +71,23 @@ func TestJWTGroupsFilterToPB(t *testing.T) {
7071
}{
7172
{
7273
name: "null input",
73-
input: types.ObjectNull(jwtGroupsFilterSchemaAttr),
74+
input: types.ObjectNull(provider.JWTGroupsFilterSchemaAttr),
7475
expected: nil,
7576
},
7677
{
7778
name: "empty groups",
78-
input: types.ObjectValueMust(jwtGroupsFilterSchemaAttr, map[string]attr.Value{
79+
input: types.ObjectValueMust(provider.JWTGroupsFilterSchemaAttr, map[string]attr.Value{
7980
"groups": types.SetValueMust(types.StringType, []attr.Value{}),
8081
"infer_from_ppl": types.BoolValue(false),
8182
}),
8283
expected: &pb.JwtGroupsFilter{
8384
Groups: []string{},
84-
InferFromPpl: false,
85+
InferFromPpl: P(false),
8586
},
8687
},
8788
{
8889
name: "with groups",
89-
input: types.ObjectValueMust(jwtGroupsFilterSchemaAttr, map[string]attr.Value{
90+
input: types.ObjectValueMust(provider.JWTGroupsFilterSchemaAttr, map[string]attr.Value{
9091
"groups": types.SetValueMust(types.StringType, []attr.Value{
9192
types.StringValue("group1"),
9293
types.StringValue("group2"),
@@ -95,7 +96,7 @@ func TestJWTGroupsFilterToPB(t *testing.T) {
9596
}),
9697
expected: &pb.JwtGroupsFilter{
9798
Groups: []string{"group1", "group2"},
98-
InferFromPpl: true,
99+
InferFromPpl: P(true),
99100
},
100101
},
101102
}
@@ -104,7 +105,7 @@ func TestJWTGroupsFilterToPB(t *testing.T) {
104105
t.Run(tc.name, func(t *testing.T) {
105106
var diags diag.Diagnostics
106107
var result *pb.JwtGroupsFilter
107-
JWTGroupsFilterToPB(ctx, &result, tc.input, &diags)
108+
provider.JWTGroupsFilterToPB(ctx, &result, tc.input, &diags)
108109
assert.False(t, diags.HasError())
109110
diff := cmp.Diff(tc.expected, result, protocmp.Transform())
110111
assert.Empty(t, diff)

internal/provider/route.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (r *RouteResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
198198
Optional: true,
199199
Computed: true,
200200
},
201-
"jwt_groups_filter": jwtGroupsFilterSchema,
201+
"jwt_groups_filter": JWTGroupsFilterSchema,
202202
},
203203
}
204204
}

internal/provider/settings_schema.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ var SettingsResourceSchema = schema.Schema{
190190
Optional: true,
191191
Description: "JWT claims headers mapping",
192192
},
193-
"jwt_groups_filter": jwtGroupsFilterSchema,
193+
"jwt_groups_filter": JWTGroupsFilterSchema,
194194
"default_upstream_timeout": schema.StringAttribute{
195195
Optional: true,
196196
Description: "Default upstream timeout",

0 commit comments

Comments
 (0)