Skip to content

Commit 70566a7

Browse files
committed
tests and docs and such
1 parent a2f1177 commit 70566a7

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

docs/resources/organization.md

+29
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,35 @@ An organization on the Coder deployment.
1515
~> **Warning**
1616
This resource is only compatible with Coder version [2.16.0](https://github.com/coder/coder/releases/tag/v2.16.0) and later.
1717

18+
## Example Usage
1819

20+
```terraform
21+
resource "coderd_organization" "blueberry" {
22+
name = "blueberry"
23+
display_name = "Blueberry"
24+
description = "The organization for blueberries"
25+
icon = "/emojis/1fad0.png"
26+
27+
sync_mapping = [
28+
"wibble",
29+
"wobble",
30+
]
31+
32+
group_sync {
33+
field = "coder_groups"
34+
mapping = {
35+
toast = [coderd_group.bread.id]
36+
}
37+
}
38+
39+
role_sync {
40+
field = "coder_roles"
41+
mapping = {
42+
manager = ["organization-user-admin"]
43+
}
44+
}
45+
}
46+
```
1947

2048
<!-- schema generated by tfplugindocs -->
2149
## Schema
@@ -31,6 +59,7 @@ This resource is only compatible with Coder version [2.16.0](https://github.com/
3159
- `group_sync` (Block, Optional) Group sync settings to sync groups from an IdP. (see [below for nested schema](#nestedblock--group_sync))
3260
- `icon` (String)
3361
- `role_sync` (Block, Optional) Role sync settings to sync organization roles from an IdP. (see [below for nested schema](#nestedblock--role_sync))
62+
- `sync_mapping` (Set of String) Claims from the IdP provider that will give users access to this organization.
3463

3564
### Read-Only
3665

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "coderd_organization" "blueberry" {
2+
name = "blueberry"
3+
display_name = "Blueberry"
4+
description = "The organization for blueberries"
5+
icon = "/emojis/1fad0.png"
6+
7+
sync_mapping = [
8+
"wibble",
9+
"wobble",
10+
]
11+
12+
group_sync {
13+
field = "coder_groups"
14+
mapping = {
15+
toast = [coderd_group.bread.id]
16+
}
17+
}
18+
19+
role_sync {
20+
field = "coder_roles"
21+
mapping = {
22+
manager = ["organization-user-admin"]
23+
}
24+
}
25+
}

internal/provider/organization_resource.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (r *OrganizationResource) Update(ctx context.Context, req resource.UpdateRe
457457
var state OrganizationResourceModel
458458
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
459459
var currentClaims []string
460-
resp.Diagnostics.Append(data.SyncMapping.ElementsAs(ctx, &currentClaims, false)...)
460+
resp.Diagnostics.Append(state.SyncMapping.ElementsAs(ctx, &currentClaims, false)...)
461461

462462
var plannedClaims []string
463463
resp.Diagnostics.Append(data.SyncMapping.ElementsAs(ctx, &plannedClaims, false)...)
@@ -635,7 +635,7 @@ func (r *OrganizationResource) patchOrgSyncMapping(
635635
}
636636
var removeMappings []codersdk.IDPSyncMapping[uuid.UUID]
637637
for _, claim := range remove {
638-
addMappings = append(removeMappings, codersdk.IDPSyncMapping[uuid.UUID]{
638+
removeMappings = append(removeMappings, codersdk.IDPSyncMapping[uuid.UUID]{
639639
Given: claim,
640640
Gets: orgID,
641641
})

internal/provider/organization_resource_test.go

+33-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func TestAccOrganizationResource(t *testing.T) {
5555
},
5656
})
5757

58+
cfg4 := cfg2
59+
cfg4.SyncMapping = []string{"wibble", "wobble"}
60+
61+
cfg5 := cfg4
62+
cfg5.SyncMapping = []string{"wibbley", "wobbley"}
63+
5864
t.Run("CreateImportUpdateReadOk", func(t *testing.T) {
5965
resource.Test(t, resource.TestCase{
6066
IsUnitTest: true,
@@ -96,6 +102,22 @@ func TestAccOrganizationResource(t *testing.T) {
96102
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("role_sync").AtMapKey("mapping").AtMapKey("wobble").AtSliceIndex(0), knownvalue.StringExact("wobbly")),
97103
},
98104
},
105+
// Add org sync
106+
{
107+
Config: cfg4.String(t),
108+
ConfigStateChecks: []statecheck.StateCheck{
109+
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("sync_mapping").AtSliceIndex(0), knownvalue.StringExact("wibble")),
110+
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("sync_mapping").AtSliceIndex(1), knownvalue.StringExact("wobble")),
111+
},
112+
},
113+
// Patch org sync
114+
{
115+
Config: cfg5.String(t),
116+
ConfigStateChecks: []statecheck.StateCheck{
117+
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("sync_mapping").AtSliceIndex(0), knownvalue.StringExact("wibbley")),
118+
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("sync_mapping").AtSliceIndex(1), knownvalue.StringExact("wobbley")),
119+
},
120+
},
99121
},
100122
})
101123
})
@@ -110,8 +132,9 @@ type testAccOrganizationResourceConfig struct {
110132
Description *string
111133
Icon *string
112134

113-
GroupSync *codersdk.GroupSyncSettings
114-
RoleSync *codersdk.RoleSyncSettings
135+
SyncMapping []string
136+
GroupSync *codersdk.GroupSyncSettings
137+
RoleSync *codersdk.RoleSyncSettings
115138
}
116139

117140
func (c testAccOrganizationResourceConfig) String(t *testing.T) string {
@@ -128,6 +151,14 @@ resource "coderd_organization" "test" {
128151
description = {{orNull .Description}}
129152
icon = {{orNull .Icon}}
130153
154+
{{- if .SyncMapping}}
155+
sync_mapping = [
156+
{{- range $name := .SyncMapping }}
157+
"{{$name}}",
158+
{{- end}}
159+
]
160+
{{- end}}
161+
131162
{{- if .GroupSync}}
132163
group_sync {
133164
field = "{{.GroupSync.Field}}"

0 commit comments

Comments
 (0)