Terraform provider for managing WorkOS resources including organizations, users, organization memberships, and roles.
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
}resource "workos_organization" "example" {
name = "Acme Corporation"
domains = ["acme.com", "acmecorp.com"]
}resource "workos_user" "admin" {
email = "admin@example.com"
first_name = "Admin"
last_name = "User"
email_verified = true
}
resource "workos_organization_membership" "admin" {
user_id = workos_user.admin.id
organization_id = workos_organization.example.id
role_slug = "admin"
}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"
}# 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 user by email
data "workos_user" "john" {
email = "john@example.com"
}
# Look up organization role by slug
data "workos_organization_role" "billing" {
organization_id = workos_organization.example.id
slug = "org-billing-admin"
}| Resource | Description |
|---|---|
workos_organization |
Manages WorkOS organizations |
workos_user |
Manages AuthKit users |
workos_organization_membership |
Manages user-organization memberships |
workos_organization_role |
Manages organization authorization roles |
| Data Source | Description |
|---|---|
workos_organization |
Retrieves organization by ID or domain |
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 or email |
workos_organization_role |
Retrieves organization role by slug or ID |
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.