Skip to content

Commit

Permalink
idek what I'm doing anymore apparently
Browse files Browse the repository at this point in the history
  • Loading branch information
aslilac committed Nov 26, 2024
1 parent 69ebed9 commit 3bf1734
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 152 deletions.
145 changes: 0 additions & 145 deletions internal/customtypes/group_sync.go

This file was deleted.

14 changes: 7 additions & 7 deletions internal/provider/organization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe
"group_sync": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"field": schema.StringAttribute{
Required: true,
Optional: true,
MarkdownDescription: "The claim field that specifies what groups " +
"a user should be in.",
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
},
"regex": schema.StringAttribute{
Required: true,
Optional: true,
MarkdownDescription: "A regular expression that will be used to " +
"filter the groups returned by the OIDC provider. Any group " +
"not matched will be ignored.",
Expand All @@ -111,21 +111,21 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe
},
},
"auto_create_missing": schema.BoolAttribute{
Required: true,
Optional: true,
MarkdownDescription: "Controls whether groups will be created if " +
"they are missing.",
},
"mapping": schema.MapAttribute{
ElementType: UUIDType,
Required: true,
Optional: true,
MarkdownDescription: "A map from OIDC group name to Coder group ID.",
},
},
},
"role_sync": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"field": schema.StringAttribute{
Required: true,
Optional: true,
MarkdownDescription: "The claim field that specifies what " +
"organization roles a user should be given.",
Validators: []validator.String{
Expand All @@ -134,7 +134,7 @@ func (r *OrganizationResource) Schema(ctx context.Context, req resource.SchemaRe
},
"mapping": schema.MapAttribute{
ElementType: UUIDType,
Required: true,
Optional: true,
MarkdownDescription: "A map from OIDC group name to Coder " +
"organization role.",
},
Expand Down Expand Up @@ -285,7 +285,7 @@ func (r *OrganizationResource) Update(ctx context.Context, req resource.UpdateRe
if data.GroupSync.IsNull() {
err = r.patchGroupSync(ctx, orgID, data.GroupSync)
if err != nil {
resp.Diagnostics.AddError("Group Sync Update error", "uh oh john")
resp.Diagnostics.AddError("Group Sync Update error", err.Error())
return
}
}
Expand Down
43 changes: 43 additions & 0 deletions internal/provider/organization_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"fmt"
"os"
"strings"
"testing"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/integration"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
Expand Down Expand Up @@ -40,6 +42,22 @@ func TestAccOrganizationResource(t *testing.T) {
cfg2.Name = ptr.Ref("example-org-new")
cfg2.DisplayName = ptr.Ref("Example Organization New")

cfg3 := cfg1
cfg3.GroupSync = ptr.Ref(codersdk.GroupSyncSettings{
Field: "wibble",
Mapping: map[string][]uuid.UUID{
"wibble": {uuid.MustParse("6e57187f-6543-46ab-a62c-a10065dd4314")},
},
})
cfg3.RoleSync = ptr.Ref(codersdk.RoleSyncSettings{
Field: "wibble",
Mapping: map[string][]string{
"wibble": {"wobble"},
},
})

fmt.Println(cfg3)

t.Run("CreateImportUpdateReadOk", func(t *testing.T) {
resource.Test(t, resource.TestCase{
IsUnitTest: true,
Expand Down Expand Up @@ -84,6 +102,9 @@ type testAccOrganizationResourceConfig struct {
DisplayName *string
Description *string
Icon *string

GroupSync *codersdk.GroupSyncSettings
RoleSync *codersdk.RoleSyncSettings
}

func (c testAccOrganizationResourceConfig) String(t *testing.T) string {
Expand All @@ -99,6 +120,28 @@ resource "coderd_organization" "test" {
display_name = {{orNull .DisplayName}}
description = {{orNull .Description}}
icon = {{orNull .Icon}}
{{- if .GroupSync}}
group_sync {
field = "{{.GroupSync.Field}}"
mapping = {
{{- range $key, $value := .GroupSync.Mapping}}
{{$key}} = "{{$value}}"
{{- end}}
}
}
{{- end}}
{{- if .RoleSync}}
role_sync {
field = "{{.RoleSync.Field}}"
mapping = {
{{- range $key, $value := .RoleSync.Mapping}}
{{$key}} = "{{$value}}"
{{- end}}
}
}
{{- end}}
}
`
funcMap := template.FuncMap{
Expand Down

0 comments on commit 3bf1734

Please sign in to comment.