Terraform provider for managing WorkOS resources including organizations, users, organization memberships, roles, and permissions.
terraform {
required_providers {
workos = {
source = "osodevops/workos"
version = "~> 1.0"
}
}
}
provider "workos" {
api_key = var.workos_api_key
}# Clone the repository
git clone https://github.com/osodevops/terraform-provider-workos.git
cd terraform-provider-workos
# Build the provider
make build
# Install locally
make installprovider "workos" {
api_key = var.workos_api_key # Or set WORKOS_API_KEY env var
client_id = var.workos_client_id # Or set WORKOS_CLIENT_ID env var (optional)
base_url = "https://api.workos.com" # Optional, defaults to production API
}The configuration resources manage an existing environment and its default AuthKit application. They do not create environments, applications, organizations, or users.
Experimental. These two resources use the WorkOS dashboard ("account plane") GraphQL API through the same operations as the official WorkOS CLI. It is not a documented, versioned public API: WorkOS gates it per team and may change it without notice, so pin the provider version.
Supply a separate account OAuth token through WORKOS_ACCOUNT_ACCESS_TOKEN and the expected
team ID through WORKOS_ACCOUNT_TEAM_ID. WorkOS must enable account-plane access for that team;
an expired token or a disabled feature flag stops Terraform before any resource mutation. Keep
WORKOS_API_KEY for existing REST role resources. The account token is a Terraform credential
and must never be passed to application runtime. It is the short-lived access token that
workos auth login stores for the WorkOS CLI; the CLI refreshes it, this provider does not, so
supply a current token for each run.
provider "workos" {
client_id = var.workos_client_id
environment_id = var.workos_environment_id
application_id = var.workos_application_id
}
resource "workos_authkit_configuration" "app" {
depends_on = [workos_environment_role_configuration.app]
environment_id = var.workos_environment_id
application_id = var.workos_application_id
redirect_uris = ["https://app.example.com/callback"]
default_redirect_uri = "https://app.example.com/callback"
logout_uris = ["https://app.example.com/signed-out"]
default_logout_uri = "https://app.example.com/signed-out"
cors_origins = ["https://app.example.com"]
initiate_login_uri = "https://app.example.com/login"
authkit_enabled = true
allow_signup = true
waitlist_enabled = false
}
resource "workos_environment_role" "viewer" {
slug = "viewer"
name = "Viewer"
permissions = []
}
resource "workos_environment_role_configuration" "app" {
environment_id = var.workos_environment_id
default_role_slug = workos_environment_role.viewer.slug
}The dependency sets the default viewer role before enabling public signup.
The provider verifies team, environment, application, and REST-key ownership before any resources
can run. After apply, refresh reads back the managed values; the next plan should show no changes.
The URI and origin sets are authoritative: omitted entries are removed. Use one configuration
owner per environment and do not also manage its callbacks with workos_redirect_uri.
Import existing configurations and roles before changing them. Destroying either configuration singleton only detaches Terraform ownership, emits a warning, and leaves remote settings unchanged. It does not reset configuration or delete WorkOS data. See AuthKit configuration and default role configuration for imports, recovery, validation limits, and account API requirements.
resource "workos_organization" "example" {
name = "Acme Corporation"
external_id = "acme-corp-123"
domains = ["acme.com", "acmecorp.com"]
metadata = {
tier = "enterprise"
region = "us-east-1"
}
}resource "workos_user" "admin" {
email = "admin@example.com"
first_name = "Admin"
last_name = "User"
external_id = "admin-001"
email_verified = true
metadata = {
department = "Engineering"
title = "Platform Lead"
}
}
resource "workos_organization_membership" "admin" {
user_id = workos_user.admin.id
organization_id = workos_organization.example.id
role_slug = "admin"
}resource "workos_environment_role" "billing_admin" {
slug = "billing-admin"
name = "Billing Admin"
description = "Can manage billing across organizations"
permissions = [
workos_permission.billing_read.slug,
workos_permission.billing_write.slug,
]
}
resource "workos_organization_role" "billing_admin" {
organization_id = workos_organization.example.id
slug = "org-billing-admin"
name = "Billing Admin"
description = "Can manage billing and invoices"
}
resource "workos_organization_role" "viewer" {
organization_id = workos_organization.example.id
slug = "org-viewer"
name = "Viewer"
}resource "workos_permission" "billing_read" {
slug = "billing:read"
name = "Read Billing"
description = "Allows reading billing data"
}
resource "workos_permission" "billing_write" {
slug = "billing:write"
name = "Write Billing"
description = "Allows modifying billing data"
}resource "workos_organization_role_permission" "billing_admin_read" {
organization_id = workos_organization.example.id
role_slug = workos_organization_role.billing_admin.slug
permission = workos_permission.billing_read.slug
}
resource "workos_organization_role_permission" "billing_admin_write" {
organization_id = workos_organization.example.id
role_slug = workos_organization_role.billing_admin.slug
permission = workos_permission.billing_write.slug
}# Look up organization by ID
data "workos_organization" "by_id" {
id = "org_01HXYZ..."
}
# Look up organization by domain
data "workos_organization" "by_domain" {
domain = "acme.com"
}
# Look up organization by external ID
data "workos_organization" "by_external_id" {
external_id = "acme-corp-123"
}
# Look up user by email
data "workos_user" "john" {
email = "john@example.com"
}
# Look up user by external ID
data "workos_user" "by_ext" {
external_id = "admin-001"
}
# Look up organization role by slug
data "workos_organization_role" "billing" {
organization_id = workos_organization.example.id
slug = "org-billing-admin"
}
# Look up environment role by slug
data "workos_environment_role" "admin" {
slug = "admin"
}
# Look up permission by slug
data "workos_permission" "billing_read" {
slug = "billing:read"
}The provider does not automatically discover and adopt existing WorkOS objects. Import existing resources into Terraform or OpenTofu state before managing them in configuration.
terraform import workos_organization.example org_01HXYZ...
terraform import workos_permission.billing_read billing:read
terraform import workos_environment_role.admin admin
terraform import workos_organization_role.billing_admin org_01HXYZ.../org-billing-admin
terraform import workos_organization_role_permission.billing_admin_read org_01HXYZ.../org-billing-admin/billing:read
terraform import workos_redirect_uri.example redir_01HXYZ...
terraform import workos_authkit_configuration.app environment_01HXYZ.../application_01HXYZ...
terraform import workos_environment_role_configuration.app environment_01HXYZ...
terraform import workos_connect_application_client_secret.m2m connect_app_01HXYZ.../connect_app_secret_01HXYZ...OpenTofu uses the same import IDs with tofu import.
| Resource | Description |
|---|---|
workos_organization |
Manages WorkOS organizations |
workos_user |
Manages AuthKit users |
workos_organization_membership |
Manages user-organization memberships |
workos_environment_role |
Manages environment-level authorization roles |
workos_authkit_configuration |
Owns complete AuthKit URL/origin sets, enablement, and signup settings for an existing environment |
workos_environment_role_configuration |
Sets an existing environment's default role without changing role definitions |
workos_organization_role |
Manages organization authorization roles |
workos_permission |
Manages environment-level permissions |
workos_organization_role_permission |
Assigns a permission to an organization role |
workos_redirect_uri |
Manages AuthKit login callback URIs |
workos_connect_application_client_secret |
Mints and revokes Connect application client secrets |
| Data Source | Description |
|---|---|
workos_organization |
Retrieves organization by ID, domain, or external ID |
workos_connection |
Retrieves SSO connection by ID or org/type (read-only) |
workos_directory |
Retrieves directory by ID or organization (read-only) |
workos_directory_user |
Retrieves directory-synced user |
workos_directory_group |
Retrieves directory-synced group |
workos_user |
Retrieves AuthKit user by ID, email, or external ID |
workos_environment_role |
Retrieves environment-level role by slug or ID |
workos_organization_role |
Retrieves organization role by slug or ID |
workos_permission |
Retrieves permission by slug |
make build# Unit tests
make test
# Acceptance tests (requires WorkOS API credentials)
export WORKOS_API_KEY="sk_test_..."
export WORKOS_CLIENT_ID="client_..."
make testaccmake docsmake lint- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
feat(resource): add new attribute support
fix(organization): handle domain validation
docs(readme): update installation instructions
test(connection): add acceptance tests
MPL-2.0 - See LICENSE for details.