Skip to content

Commit 2858c7b

Browse files
committed
Merge branch 'main' into wasaga/jwt-groups-filter
2 parents 980dab8 + 00eb7a6 commit 2858c7b

20 files changed

+863
-263
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: go mod download
2424

2525
- name: Run tests
26-
run: go test -v -cover ./internal/provider/...
26+
run: make test
2727

2828
- name: Run acceptance tests
2929
run: |

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ go.work.sum
2525
.env
2626
.DS_Store
2727
bin
28+
29+
.vscode

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ build:
1212

1313
.PHONY: docs
1414
docs:
15+
@echo "@==> $@"
1516
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest generate --provider-dir . -provider-name pomerium
17+
18+
.PHONY: test
19+
test:
20+
@echo "@==> $@"
21+
@go test ./internal/provider/...

example/main.tf

+19-1
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,30 @@ resource "pomerium_policy" "test_policy" {
8080
})
8181
}
8282

83+
resource "pomerium_policy" "test_policy_group" {
84+
name = "group test policy"
85+
namespace_id = pomerium_namespace.test_namespace.id
86+
ppl = yamlencode({
87+
allow = {
88+
and = [
89+
{
90+
groups = {
91+
has = "gid-123456"
92+
}
93+
}
94+
]
95+
}
96+
})
97+
}
8398
resource "pomerium_route" "test_route" {
8499
name = "test-route"
85100
namespace_id = pomerium_namespace.test_namespace.id
86101
from = "https://verify-tf.localhost.pomerium.io"
87102
to = ["https://verify.pomerium.com"]
88-
policies = [pomerium_policy.test_policy.id]
103+
policies = [
104+
pomerium_policy.test_policy_group.id,
105+
pomerium_policy.test_policy.id,
106+
]
89107
jwt_groups_filter = {
90108
infer_from_ppl = true
91109
}

internal/provider/convert.go

+32-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ import (
1717
"google.golang.org/protobuf/types/known/structpb"
1818
)
1919

20-
func FromStringSlice(slice []string) types.List {
20+
func FromStringSliceToSet(slice []string) types.Set {
21+
if slice == nil {
22+
return types.SetNull(types.StringType)
23+
}
24+
fields := make([]attr.Value, 0)
25+
for _, v := range slice {
26+
fields = append(fields, types.StringValue(v))
27+
}
28+
return types.SetValueMust(types.StringType, fields)
29+
}
30+
31+
func FromStringSliceToList(slice []string) types.List {
2132
if slice == nil {
2233
return types.ListNull(types.StringType)
2334
}
@@ -28,12 +39,12 @@ func FromStringSlice(slice []string) types.List {
2839
return types.ListValueMust(types.StringType, fields)
2940
}
3041

31-
// FromStringList converts a Settings_StringList to a types.List
32-
func FromStringList(sl *pb.Settings_StringList) types.List {
42+
// FromStringListToSet converts a Settings_StringList to a types.List
43+
func FromStringListToSet(sl *pb.Settings_StringList) types.Set {
3344
if sl == nil {
34-
return types.ListNull(types.StringType)
45+
return types.SetNull(types.StringType)
3546
}
36-
return FromStringSlice(sl.Values)
47+
return FromStringSliceToSet(sl.Values)
3748
}
3849

3950
// FromStringMap converts a map[string]string to a types.Map
@@ -49,14 +60,14 @@ func FromStringMap(m map[string]string) types.Map {
4960
}
5061

5162
// ToStringList converts a types.List to Settings_StringList and handles diagnostics internally
52-
func ToStringList(ctx context.Context, dst **pb.Settings_StringList, list types.List, diagnostics *diag.Diagnostics) {
53-
if list.IsNull() {
63+
func ToStringListFromSet(ctx context.Context, dst **pb.Settings_StringList, set types.Set, diagnostics *diag.Diagnostics) {
64+
if set.IsNull() {
5465
*dst = nil
5566
return
5667
}
5768

5869
var values []string
59-
diagnostics.Append(list.ElementsAs(ctx, &values, false)...)
70+
diagnostics.Append(set.ElementsAs(ctx, &values, false)...)
6071
if !diagnostics.HasError() {
6172
*dst = &pb.Settings_StringList{Values: values}
6273
}
@@ -76,8 +87,19 @@ func ToStringMap(ctx context.Context, dst *map[string]string, m types.Map, diagn
7687
}
7788
}
7889

79-
// ToStringSlice converts a types.List to string slice and handles diagnostics internally
80-
func ToStringSlice(ctx context.Context, dst *[]string, list types.List, diagnostics *diag.Diagnostics) {
90+
func ToStringSliceFromSet(ctx context.Context, dst *[]string, set types.Set, diagnostics *diag.Diagnostics) {
91+
*dst = make([]string, 0)
92+
if !set.IsNull() {
93+
var values []string
94+
diagnostics.Append(set.ElementsAs(ctx, &values, false)...)
95+
if !diagnostics.HasError() {
96+
*dst = values
97+
}
98+
}
99+
}
100+
101+
// ToStringSliceFromList converts a types.List to string slice and handles diagnostics internally
102+
func ToStringSliceFromList(ctx context.Context, dst *[]string, list types.List, diagnostics *diag.Diagnostics) {
81103
*dst = make([]string, 0)
82104
if !list.IsNull() {
83105
var values []string

0 commit comments

Comments
 (0)