Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ resource "coderd_organization" "blueberry" {

### Optional

- `default_org_member_roles` (List of String) Built-in organization role names that are unioned into every member's effective roles. Changes propagate to members on their next request. Setting any value other than the deployment defaults requires the `minimum-implicit-member` experiment to be enabled on the Coder Deployment.
- `default_org_member_roles` (Set of String) Built-in organization role names that are unioned into every member's effective roles. Changes propagate to members on their next request. Requires a Coder Deployment running v2.37.0 or later.
- `description` (String)
- `display_name` (String) Display name of the organization. Defaults to name.
- `group_sync` (Block, Optional, Deprecated) Group sync settings to sync groups from an IdP.
Expand Down
22 changes: 11 additions & 11 deletions internal/provider/organization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"regexp"
"strings"

"github.com/coder/coder/v2/coderd/util/slice"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/internal/codersdkvalidator"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand All @@ -25,6 +22,10 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/coder/coder/v2/coderd/util/slice"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/internal/codersdkvalidator"
)

// Ensure provider defined types fully satisfy framework interfaces.
Expand All @@ -45,7 +46,7 @@ type OrganizationResourceModel struct {
Icon types.String `tfsdk:"icon"`
WorkspaceSharing types.String `tfsdk:"workspace_sharing"`

DefaultOrgMemberRoles types.List `tfsdk:"default_org_member_roles"`
DefaultOrgMemberRoles types.Set `tfsdk:"default_org_member_roles"`

OrgSyncIdpGroups types.Set `tfsdk:"org_sync_idp_groups"`
GroupSync types.Object `tfsdk:"group_sync"`
Expand Down Expand Up @@ -151,11 +152,10 @@ This resource is only compatible with Coder version [2.16.0](https://github.com/
},
},

"default_org_member_roles": schema.ListAttribute{
"default_org_member_roles": schema.SetAttribute{
ElementType: types.StringType,
MarkdownDescription: "Built-in organization role names that are unioned into every member's effective roles. " +
"Changes propagate to members on their next request. Setting any value other than the deployment defaults " +
"requires the `minimum-implicit-member` experiment to be enabled on the Coder Deployment.",
"Changes propagate to members on their next request. Requires a Coder Deployment running v2.37.0 or later.",
Optional: true,
Computed: true,

@ethanndickson ethanndickson Sep 14, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this resource should have a validator:

Validators: []validator.Set{
	setvalidator.ValueStringsAre(
		stringvalidator.OneOf("owner", "template-admin", "user-admin", "auditor"),
	),
},

and ideally we should import that list of strings from codersdk so it's not so brittle

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In saying that, we dont currently have an import for it on coderd_user.roles, which is where I copied that snippet from

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't think the session token from the provider block is available to us in the validator, so custom role validation is maybe impossible

We don't support custom roles here yet. So I can copy the list as it stands today.
We don't add roles very often, but the list is only static to a given version of coderd.

},
Expand Down Expand Up @@ -856,11 +856,11 @@ func isWorkspaceSharingExperimentOff(err error) bool {
}

// defaultOrgMemberRolesValueFromAPI converts the API's []string into a
// types.List[string]. A nil slice from an older server is treated as an
// empty list so the attribute always has a known value.
func defaultOrgMemberRolesValueFromAPI(ctx context.Context, roles []string) (types.List, diag.Diagnostics) {
// types.Set[string]. A nil slice from an older server is treated as an
// empty set so the attribute always has a known value.
func defaultOrgMemberRolesValueFromAPI(ctx context.Context, roles []string) (types.Set, diag.Diagnostics) {
if roles == nil {
roles = []string{}
}
return types.ListValueFrom(ctx, types.StringType, roles)
return types.SetValueFrom(ctx, types.StringType, roles)
}
4 changes: 2 additions & 2 deletions internal/provider/organization_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAccOrganizationResource(t *testing.T) {
}

ctx := t.Context()
client := integration.StartCoder(ctx, t, "organization_acc", integration.UseLicense, integration.CoderExperiments("workspace-sharing,minimum-implicit-member"))
client := integration.StartCoder(ctx, t, "organization_acc", integration.UseLicense, integration.CoderExperiments("workspace-sharing"))
_, err := client.User(ctx, codersdk.Me)
require.NoError(t, err)
runOrganizationResourceTest(t, client, true)
Expand Down Expand Up @@ -187,7 +187,7 @@ func runOrganizationResourceTest(t *testing.T, client *codersdk.Client, enableEx
resource.TestStep{
Config: cfg8.String(t),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("default_org_member_roles"), knownvalue.ListExact([]knownvalue.Check{
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("default_org_member_roles"), knownvalue.SetExact([]knownvalue.Check{
knownvalue.StringExact("organization-template-admin"),
knownvalue.StringExact("organization-workspace-access"),
})),
Expand Down