Skip to content

Commit 3bf1734

Browse files
committed
idek what I'm doing anymore apparently
1 parent 69ebed9 commit 3bf1734

File tree

3 files changed

+50
-152
lines changed

3 files changed

+50
-152
lines changed

internal/customtypes/group_sync.go

Lines changed: 0 additions & 145 deletions
This file was deleted.

internal/provider/organization_resource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe
9494
"group_sync": schema.SingleNestedBlock{
9595
Attributes: map[string]schema.Attribute{
9696
"field": schema.StringAttribute{
97-
Required: true,
97+
Optional: true,
9898
MarkdownDescription: "The claim field that specifies what groups " +
9999
"a user should be in.",
100100
Validators: []validator.String{
101101
stringvalidator.LengthAtLeast(1),
102102
},
103103
},
104104
"regex": schema.StringAttribute{
105-
Required: true,
105+
Optional: true,
106106
MarkdownDescription: "A regular expression that will be used to " +
107107
"filter the groups returned by the OIDC provider. Any group " +
108108
"not matched will be ignored.",
@@ -111,21 +111,21 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe
111111
},
112112
},
113113
"auto_create_missing": schema.BoolAttribute{
114-
Required: true,
114+
Optional: true,
115115
MarkdownDescription: "Controls whether groups will be created if " +
116116
"they are missing.",
117117
},
118118
"mapping": schema.MapAttribute{
119119
ElementType: UUIDType,
120-
Required: true,
120+
Optional: true,
121121
MarkdownDescription: "A map from OIDC group name to Coder group ID.",
122122
},
123123
},
124124
},
125125
"role_sync": schema.SingleNestedBlock{
126126
Attributes: map[string]schema.Attribute{
127127
"field": schema.StringAttribute{
128-
Required: true,
128+
Optional: true,
129129
MarkdownDescription: "The claim field that specifies what " +
130130
"organization roles a user should be given.",
131131
Validators: []validator.String{
@@ -134,7 +134,7 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe
134134
},
135135
"mapping": schema.MapAttribute{
136136
ElementType: UUIDType,
137-
Required: true,
137+
Optional: true,
138138
MarkdownDescription: "A map from OIDC group name to Coder " +
139139
"organization role.",
140140
},
@@ -285,7 +285,7 @@ func (r *OrganizationResource) Update(ctx context.Context, req resource.UpdateRe
285285
if data.GroupSync.IsNull() {
286286
err = r.patchGroupSync(ctx, orgID, data.GroupSync)
287287
if err != nil {
288-
resp.Diagnostics.AddError("Group Sync Update error", "uh oh john")
288+
resp.Diagnostics.AddError("Group Sync Update error", err.Error())
289289
return
290290
}
291291
}

internal/provider/organization_resource_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"strings"
78
"testing"
@@ -10,6 +11,7 @@ import (
1011
"github.com/coder/coder/v2/coderd/util/ptr"
1112
"github.com/coder/coder/v2/codersdk"
1213
"github.com/coder/terraform-provider-coderd/integration"
14+
"github.com/google/uuid"
1315
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1416
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
1517
"github.com/hashicorp/terraform-plugin-testing/statecheck"
@@ -40,6 +42,22 @@ func TestAccOrganizationResource(t *testing.T) {
4042
cfg2.Name = ptr.Ref("example-org-new")
4143
cfg2.DisplayName = ptr.Ref("Example Organization New")
4244

45+
cfg3 := cfg1
46+
cfg3.GroupSync = ptr.Ref(codersdk.GroupSyncSettings{
47+
Field: "wibble",
48+
Mapping: map[string][]uuid.UUID{
49+
"wibble": {uuid.MustParse("6e57187f-6543-46ab-a62c-a10065dd4314")},
50+
},
51+
})
52+
cfg3.RoleSync = ptr.Ref(codersdk.RoleSyncSettings{
53+
Field: "wibble",
54+
Mapping: map[string][]string{
55+
"wibble": {"wobble"},
56+
},
57+
})
58+
59+
fmt.Println(cfg3)
60+
4361
t.Run("CreateImportUpdateReadOk", func(t *testing.T) {
4462
resource.Test(t, resource.TestCase{
4563
IsUnitTest: true,
@@ -84,6 +102,9 @@ type testAccOrganizationResourceConfig struct {
84102
DisplayName *string
85103
Description *string
86104
Icon *string
105+
106+
GroupSync *codersdk.GroupSyncSettings
107+
RoleSync *codersdk.RoleSyncSettings
87108
}
88109

89110
func (c testAccOrganizationResourceConfig) String(t *testing.T) string {
@@ -99,6 +120,28 @@ resource "coderd_organization" "test" {
99120
display_name = {{orNull .DisplayName}}
100121
description = {{orNull .Description}}
101122
icon = {{orNull .Icon}}
123+
124+
{{- if .GroupSync}}
125+
group_sync {
126+
field = "{{.GroupSync.Field}}"
127+
mapping = {
128+
{{- range $key, $value := .GroupSync.Mapping}}
129+
{{$key}} = "{{$value}}"
130+
{{- end}}
131+
}
132+
}
133+
{{- end}}
134+
135+
{{- if .RoleSync}}
136+
role_sync {
137+
field = "{{.RoleSync.Field}}"
138+
mapping = {
139+
{{- range $key, $value := .RoleSync.Mapping}}
140+
{{$key}} = "{{$value}}"
141+
{{- end}}
142+
}
143+
}
144+
{{- end}}
102145
}
103146
`
104147
funcMap := template.FuncMap{

0 commit comments

Comments
 (0)