Skip to content

Commit f83b755

Browse files
committed
Merge branch 'main' into wasaga/route-data-sources
2 parents 7ecb622 + d436f6e commit f83b755

11 files changed

+62
-15
lines changed

example/main.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ data "pomerium_namespace" "existing_namespace" {
161161
id = pomerium_namespace.test_namespace.id
162162
}
163163

164-
data "pomerium_route" "existing_route" {
165-
id = pomerium_route.test_route.id
166-
}
164+
# data "pomerium_route" "existing_route" {
165+
# id = pomerium_route.test_route.id
166+
# }
167167

168168
# Output examples
169169
output "namespace_name" {
170170
value = data.pomerium_namespace.existing_namespace.name
171171
}
172172

173-
output "route_from" {
174-
value = data.pomerium_route.existing_route.from
175-
}
173+
# output "route_from" {
174+
# value = data.pomerium_route.existing_route.from
175+
# }
176176

177177
output "all_namespaces" {
178178
value = data.pomerium_namespaces.all_namespaces.namespaces

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ require (
6666
golang.org/x/crypto v0.31.0 // indirect
6767
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
6868
golang.org/x/mod v0.21.0 // indirect
69-
golang.org/x/net v0.31.0 // indirect
69+
golang.org/x/net v0.33.0 // indirect
7070
golang.org/x/sync v0.10.0 // indirect
7171
golang.org/x/sys v0.28.0 // indirect
7272
golang.org/x/text v0.21.0 // indirect

go.sum

+2-6
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
239239
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
240240
github.com/pomerium/csrf v1.7.0 h1:Qp4t6oyEod3svQtKfJZs589mdUTWKVf7q0PgCKYCshY=
241241
github.com/pomerium/csrf v1.7.0/go.mod h1:hAPZV47mEj2T9xFs+ysbum4l7SF1IdrryYaY6PdoIqw=
242-
github.com/pomerium/enterprise-client-go v0.18.1-0.20241202185616-83189ffe78a8 h1:gUf1q1LuvYP5/IK/BQo1CcLfH1PsDm7SkPaMZQnNQGg=
243-
github.com/pomerium/enterprise-client-go v0.18.1-0.20241202185616-83189ffe78a8/go.mod h1:VdYFbxVuHkC9/CEQBSwAu6k69S5uUkwM7bM708YSZJ8=
244-
github.com/pomerium/enterprise-client-go v0.18.1-0.20241202185750-aab20a674922 h1:On4g0z92DXMKNFHhOhpaUJpj+gobumEQcBw3KeFbuQ8=
245-
github.com/pomerium/enterprise-client-go v0.18.1-0.20241202185750-aab20a674922/go.mod h1:+l5FjwKlXDsHahK6JE4anAqx691G6uN/3s5HBcLkPrQ=
246242
github.com/pomerium/enterprise-client-go v0.18.1-0.20241231202145-17196aa57a93 h1:XBOdbvUcrnFHjpfjRG1oS1g58g7V1IETAaTVjzz/19I=
247243
github.com/pomerium/enterprise-client-go v0.18.1-0.20241231202145-17196aa57a93/go.mod h1:+l5FjwKlXDsHahK6JE4anAqx691G6uN/3s5HBcLkPrQ=
248244
github.com/pomerium/pomerium v0.28.0 h1:oNUw623093ybLB+a/W7fZgJXRlZiLlbwXMWXpdMTs3E=
@@ -362,8 +358,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
362358
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
363359
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
364360
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
365-
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
366-
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
361+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
362+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
367363
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
368364
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
369365
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

internal/provider/convert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func ToStringSlice(ctx context.Context, dst *[]string, list types.List, diagnost
8888
}
8989
}
9090

91-
// ToDuration converts a types.String containing a duration to a durationpb.Duration and handles diagnostics internally
91+
// ToDuration converts a timetypes.Duration to durationpb.Duration
9292
func ToDuration(dst **durationpb.Duration, src timetypes.GoDuration, diagnostics *diag.Diagnostics) {
9393
if src.IsNull() || src.IsUnknown() {
9494
*dst = nil
@@ -103,7 +103,7 @@ func ToDuration(dst **durationpb.Duration, src timetypes.GoDuration, diagnostics
103103
*dst = durationpb.New(d)
104104
}
105105

106-
// FromDuration converts a durationpb.Duration to a types.String
106+
// FromDuration converts a durationpb.Duration to a timetypes.GoDuration
107107
func FromDuration(d *durationpb.Duration) timetypes.GoDuration {
108108
if d == nil {
109109
return timetypes.NewGoDurationNull()

internal/provider/keychain.go

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
1313
"github.com/hashicorp/terraform-plugin-log/tflog"
14+
"google.golang.org/grpc/codes"
15+
"google.golang.org/grpc/status"
1416

1517
client "github.com/pomerium/enterprise-client-go"
1618
"github.com/pomerium/enterprise-client-go/pb"
@@ -131,6 +133,10 @@ func (r *KeyChainResource) Read(ctx context.Context, req resource.ReadRequest, r
131133
Id: state.ID.ValueString(),
132134
})
133135
if err != nil {
136+
if status.Code(err) == codes.NotFound {
137+
resp.State.RemoveResource(ctx)
138+
return
139+
}
134140
resp.Diagnostics.AddError("Error reading key pair", err.Error())
135141
return
136142
}

internal/provider/namespace.go

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
"github.com/hashicorp/terraform-plugin-log/tflog"
12+
"google.golang.org/grpc/codes"
13+
"google.golang.org/grpc/status"
1214

1315
client "github.com/pomerium/enterprise-client-go"
1416
"github.com/pomerium/enterprise-client-go/pb"
@@ -108,6 +110,10 @@ func (r *NamespaceResource) Read(ctx context.Context, req resource.ReadRequest,
108110
Id: state.ID.ValueString(),
109111
})
110112
if err != nil {
113+
if status.Code(err) == codes.NotFound {
114+
resp.State.RemoveResource(ctx)
115+
return
116+
}
111117
resp.Diagnostics.AddError("Error reading namespace", err.Error())
112118
return
113119
}

internal/provider/namespace_permission.go

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/hashicorp/terraform-plugin-log/tflog"
1515
client "github.com/pomerium/enterprise-client-go"
1616
"github.com/pomerium/enterprise-client-go/pb"
17+
"google.golang.org/grpc/codes"
18+
"google.golang.org/grpc/status"
1719
)
1820

1921
//go:embed help/namespace_permissions.md
@@ -118,6 +120,10 @@ func (r *NamespacePermissionResource) Read(ctx context.Context, req resource.Rea
118120
Id: state.ID.ValueString(),
119121
})
120122
if err != nil {
123+
if status.Code(err) == codes.NotFound {
124+
resp.State.RemoveResource(ctx)
125+
return
126+
}
121127
resp.Diagnostics.AddError("failed to read namespace permission", err.Error())
122128
return
123129
}

internal/provider/policy.go

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
1313
"github.com/hashicorp/terraform-plugin-log/tflog"
14+
"google.golang.org/grpc/codes"
15+
"google.golang.org/grpc/status"
1416

1517
client "github.com/pomerium/enterprise-client-go"
1618
"github.com/pomerium/enterprise-client-go/pb"
@@ -150,6 +152,10 @@ func (r *PolicyResource) Read(ctx context.Context, req resource.ReadRequest, res
150152
Id: state.ID.ValueString(),
151153
})
152154
if err != nil {
155+
if status.Code(err) == codes.NotFound {
156+
resp.State.RemoveResource(ctx)
157+
return
158+
}
153159
resp.Diagnostics.AddError("Error reading policy", err.Error())
154160
return
155161
}

internal/provider/provider.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import (
66
"net"
77
"net/url"
88

9+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
910
"github.com/hashicorp/terraform-plugin-framework/datasource"
1011
"github.com/hashicorp/terraform-plugin-framework/function"
12+
"github.com/hashicorp/terraform-plugin-framework/path"
1113
"github.com/hashicorp/terraform-plugin-framework/provider"
1214
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
1315
"github.com/hashicorp/terraform-plugin-framework/resource"
16+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1417
"github.com/hashicorp/terraform-plugin-framework/types"
1518
client "github.com/pomerium/enterprise-client-go"
1619
)
@@ -52,6 +55,12 @@ func (p *PomeriumProvider) Schema(_ context.Context, _ provider.SchemaRequest, r
5255
MarkdownDescription: "Pomerium Enterprise Service Account Token",
5356
Optional: true,
5457
Sensitive: true,
58+
Validators: []validator.String{
59+
stringvalidator.ExactlyOneOf(path.Expressions{
60+
path.MatchRoot("service_account_token"),
61+
path.MatchRoot("shared_secret_b64"),
62+
}...),
63+
},
5564
},
5665
"shared_secret_b64": schema.StringAttribute{
5766
MarkdownDescription: "Pomerium Shared Secret (base64 encoded)",

internal/provider/route.go

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/hashicorp/terraform-plugin-log/tflog"
1515
client "github.com/pomerium/enterprise-client-go"
1616
"github.com/pomerium/enterprise-client-go/pb"
17+
"google.golang.org/grpc/codes"
18+
"google.golang.org/grpc/status"
1719
)
1820

1921
// Ensure provider defined types fully satisfy framework interfaces.
@@ -124,13 +126,19 @@ func (r *RouteResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
124126
Description: "Timeout.",
125127
Optional: true,
126128
CustomType: timetypes.GoDurationType{},
129+
<<<<<<< HEAD
127130
Computed: true,
131+
=======
132+
>>>>>>> main
128133
},
129134
"idle_timeout": schema.StringAttribute{
130135
Description: "Idle timeout.",
131136
Optional: true,
132137
CustomType: timetypes.GoDurationType{},
138+
<<<<<<< HEAD
133139
Computed: true,
140+
=======
141+
>>>>>>> main
134142
},
135143
"allow_websockets": schema.BoolAttribute{
136144
Description: "Allow websockets.",
@@ -267,6 +275,10 @@ func (r *RouteResource) Read(ctx context.Context, req resource.ReadRequest, resp
267275
Id: state.ID.ValueString(),
268276
})
269277
if err != nil {
278+
if status.Code(err) == codes.NotFound {
279+
resp.State.RemoveResource(ctx)
280+
return
281+
}
270282
resp.Diagnostics.AddError("get route", err.Error())
271283
return
272284
}

internal/provider/service_account.go

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
1313
"github.com/hashicorp/terraform-plugin-log/tflog"
14+
"google.golang.org/grpc/codes"
15+
"google.golang.org/grpc/status"
1416

1517
client "github.com/pomerium/enterprise-client-go"
1618
"github.com/pomerium/enterprise-client-go/pb"
@@ -131,6 +133,10 @@ func (r *ServiceAccountResource) Read(ctx context.Context, req resource.ReadRequ
131133
Id: state.ID.ValueString(),
132134
})
133135
if err != nil {
136+
if status.Code(err) == codes.NotFound {
137+
resp.State.RemoveResource(ctx)
138+
return
139+
}
134140
resp.Diagnostics.AddError("Error reading service account", err.Error())
135141
return
136142
}

0 commit comments

Comments
 (0)