Skip to content

Commit 9623788

Browse files
committed
policy: set defaults
1 parent 1f5abc3 commit 9623788

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

example/main.tf

+19-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ provider "pomerium" {
1616

1717
locals {
1818
root_namespace_id = "9d8dbd2c-8cce-4e66-9c1f-c490b4a07243"
19+
20+
any_authenticated_user_ppl = {
21+
allow = {
22+
and = [
23+
{
24+
authenticated_user = true
25+
}
26+
]
27+
}
28+
}
1929
}
30+
2031
# Create resources
2132
resource "pomerium_namespace" "test_namespace" {
2233
name = "test-namespace"
@@ -36,16 +47,20 @@ resource "pomerium_settings" "settings" {
3647
api_key = "key"
3748
url = "http://localhost"
3849
}
50+
51+
log_level = "info"
52+
proxy_log_level = "info"
53+
# tracing_provider = "jaeger"
54+
# tracing_sample_rate = 1
55+
# tracing_jaeger_collector_endpoint = "http://localhost:14268/api/traces"
56+
# tracing_jaeger_agent_endpoint = "localhost:6831"
57+
3958
timeout_idle = "5m"
4059
}
4160

4261
resource "pomerium_policy" "test_policy" {
4362
name = "test-policy"
4463
namespace_id = pomerium_namespace.test_namespace.id
45-
description = "test policy"
46-
enforced = false
47-
explanation = "test policy explanation"
48-
remediation = "test policy remediation"
4964
ppl = <<EOF
5065
- allow:
5166
and:

internal/provider/policy.go

+10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/path"
88
"github.com/hashicorp/terraform-plugin-framework/resource"
99
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
10+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
1011
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1113
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1214
"github.com/hashicorp/terraform-plugin-framework/types"
1315
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -56,6 +58,8 @@ func (r *PolicyResource) Schema(_ context.Context, _ resource.SchemaRequest, res
5658
"description": schema.StringAttribute{
5759
Description: "Description of the policy.",
5860
Optional: true,
61+
Computed: true,
62+
Default: stringdefault.StaticString(""),
5963
},
6064
"name": schema.StringAttribute{
6165
Description: "Name of the policy.",
@@ -78,14 +82,20 @@ func (r *PolicyResource) Schema(_ context.Context, _ resource.SchemaRequest, res
7882
"enforced": schema.BoolAttribute{
7983
Description: "Whether the policy is enforced within the namespace hierarchy.",
8084
Optional: true,
85+
Computed: true,
86+
Default: booldefault.StaticBool(false),
8187
},
8288
"explanation": schema.StringAttribute{
8389
Description: "Explanation of the policy.",
8490
Optional: true,
91+
Computed: true,
92+
Default: stringdefault.StaticString(""),
8593
},
8694
"remediation": schema.StringAttribute{
8795
Description: "Remediation of the policy.",
8896
Optional: true,
97+
Computed: true,
98+
Default: stringdefault.StaticString(""),
8999
},
90100
},
91101
}

internal/provider/policy_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (PolicyLanguageType) ValueFromString(
6767
var diag diag.Diagnostics
6868
v, err := PolicyLanguageType{}.Parse(in)
6969
if err != nil {
70-
diag.AddError("failed to parse PPL", err.Error())
70+
diag.AddError("failed to parse PPL", err.Error()+">>"+in.ValueString()+"<<")
7171
return nil, diag
7272
}
7373
return v, nil

0 commit comments

Comments
 (0)