A Terraform provider for managing Portkey workspaces, users, and organization resources through the Portkey Admin API.
This provider enables you to manage:
- Workspaces: Create, update, and manage workspaces for organizing teams and projects
- Workspace Members: Assign users to workspaces with specific roles
- User Invitations: Send invitations to users with organization and workspace access
- Users: Query and manage existing users in your organization
terraform {
required_providers {
portkey = {
source = "portkey-ai/portkey"
version = "~> 0.1"
}
}
}git clone https://github.com/Portkey-AI/terraform-provider-portkey
cd terraform-provider-portkey
make installThis will build and install the provider in your local Terraform plugins directory.
The provider requires a Portkey Admin API key. You can provide this in one of two ways:
export PORTKEY_API_KEY="your-admin-api-key"provider "portkey" {
api_key = "your-admin-api-key"
}- Log in to your Portkey dashboard
- Navigate to Admin Settings
- Create an Organization Admin API key
- Ensure you have Organization Owner or Admin role
Note: Admin API keys provide broad access to your organization. Store them securely and never commit them to version control.
terraform {
required_providers {
portkey = {
source = "portkey-ai/portkey"
}
}
}
provider "portkey" {
# API key read from PORTKEY_API_KEY environment variable
}
# Create a workspace
resource "portkey_workspace" "production" {
name = "Production"
description = "Production environment workspace"
}# Create multiple workspaces
resource "portkey_workspace" "engineering" {
name = "Engineering"
description = "Engineering team workspace"
}
resource "portkey_workspace" "ml_research" {
name = "ML Research"
description = "Machine Learning research workspace"
}
# Invite a user with workspace access
resource "portkey_user_invite" "data_scientist" {
email = "[email protected]"
role = "member"
workspaces = [
{
id = portkey_workspace.ml_research.id
role = "admin"
},
{
id = portkey_workspace.engineering.id
role = "member"
}
]
scopes = [
"logs.export",
"logs.list",
"logs.view",
"configs.read",
"configs.list",
"virtual_keys.read",
"virtual_keys.list"
]
}
# Add an existing user to a workspace
resource "portkey_workspace_member" "senior_engineer" {
workspace_id = portkey_workspace.engineering.id
user_id = "existing-user-id"
role = "manager"
}
# Query all workspaces
data "portkey_workspaces" "all" {}
# Query all users
data "portkey_users" "all" {}
output "workspace_count" {
value = length(data.portkey_workspaces.all.workspaces)
}For self-hosted Portkey deployments, configure the base URL:
provider "portkey" {
api_key = var.portkey_api_key
base_url = "https://your-portkey-instance.com/v1"
}Manages a Portkey workspace.
name(Required, String) - Name of the workspacedescription(Optional, String) - Description of the workspace
id(String) - Workspace identifiercreated_at(String) - Creation timestampupdated_at(String) - Last update timestamp
terraform import portkey_workspace.example workspace-idManages workspace membership for users.
workspace_id(Required, String) - ID of the workspaceuser_id(Required, String) - ID of the userrole(Required, String) - Role in the workspace (admin,manager,member)
id(String) - Workspace member identifiercreated_at(String) - Timestamp when member was added
terraform import portkey_workspace_member.example workspace-id/member-idSends invitations to users.
email(Required, String) - Email address of the user to inviterole(Required, String) - Organization role (admin,member)workspaces(Optional, List of Objects) - Workspaces to add the user toid(Required, String) - Workspace IDrole(Required, String) - Role in the workspace
scopes(Optional, List of Strings) - API scopes for the user's workspace API key
id(String) - Invitation identifierstatus(String) - Invitation status (pending,accepted,expired)created_at(String) - Creation timestampexpires_at(String) - Expiration timestamp
Note: User invitations cannot be updated. To change an invitation, delete and recreate it.
Fetches a single workspace by ID.
id(Required, String) - Workspace identifier
name(String) - Workspace namedescription(String) - Workspace descriptioncreated_at(String) - Creation timestampupdated_at(String) - Last update timestamp
Fetches all workspaces in the organization.
workspaces(List of Objects) - List of all workspaces
Fetches a single user by ID.
id(Required, String) - User identifier
email(String) - User emailrole(String) - Organization rolestatus(String) - Account statuscreated_at(String) - Creation timestampupdated_at(String) - Last update timestamp
Fetches all users in the organization.
users(List of Objects) - List of all users
make build# Run unit tests
go test ./...
# Run acceptance tests (requires valid API key)
make testaccmake installmake generateWhen inviting users, you can grant the following API scopes:
logs.export,logs.list,logs.view- Log accessconfigs.create,configs.update,configs.delete,configs.read,configs.list- Configuration managementvirtual_keys.create,virtual_keys.update,virtual_keys.delete,virtual_keys.read,virtual_keys.list,virtual_keys.copy- Virtual key managementcompletions.write- Completion API access
admin- Full organization accessmember- Standard user access
admin- Full workspace accessmanager- Manage workspace resources and membersmember- Standard workspace access
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
This provider is distributed under the Mozilla Public License 2.0. See LICENSE for more information.
- Documentation: Portkey Docs
- Admin API Reference: Admin API Docs
- Issues: GitHub Issues
- Community: Discord
- Portkey Gateway - Open-source AI Gateway
- Portkey Python SDK
- Portkey Node SDK