> ## Documentation Index
> Fetch the complete documentation index at: https://portkey-docs-mintlify-add-terraform-provider-docs-72855.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Terraform

> Use the Portkey Terraform provider to manage workspaces, users, and organization resources as infrastructure as code.

The [Portkey Terraform provider](https://github.com/Portkey-AI/terraform-provider-portkey) enables you to manage Portkey resources through the [Admin API](/api-reference/admin-api/introduction) using infrastructure as code.

## Features

* **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

## Requirements

* Terraform >= 1.0
* A Portkey account with Admin API access

## Installation

Add the provider to your Terraform configuration:

```hcl theme={null}
terraform {
  required_providers {
    portkey = {
      source  = "portkey-ai/portkey"
      version = "~> 0.1"
    }
  }
}
```

## Authentication

The provider requires a Portkey Admin API key. Set it via environment variable (recommended):

```bash theme={null}
export PORTKEY_API_KEY="your-admin-api-key"
```

Or in the provider configuration:

```hcl theme={null}
provider "portkey" {
  api_key = "your-admin-api-key"
}
```

<Note>
  Admin API keys provide broad access to your organization. Store them securely and never commit them to version control.
</Note>

## Quick start

```hcl theme={null}
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"
}

# Invite a user with workspace access
resource "portkey_user_invite" "engineer" {
  email = "engineer@example.com"
  role  = "member"

  workspaces = [
    {
      id   = portkey_workspace.production.id
      role = "admin"
    }
  ]

  scopes = [
    "logs.view",
    "configs.read",
    "virtual_keys.read"
  ]
}
```

## Self-hosted deployments

For self-hosted Portkey deployments, configure the base URL:

```hcl theme={null}
provider "portkey" {
  api_key  = var.portkey_api_key
  base_url = "https://your-portkey-instance.com/v1"
}
```

## Resources and data sources

For complete documentation on available resources, data sources, and their arguments, see the [Terraform provider repository](https://github.com/Portkey-AI/terraform-provider-portkey).

| Resource                   | Description                 |
| -------------------------- | --------------------------- |
| `portkey_workspace`        | Manage workspaces           |
| `portkey_workspace_member` | Manage workspace membership |
| `portkey_user_invite`      | Send user invitations       |

| Data Source          | Description              |
| -------------------- | ------------------------ |
| `portkey_workspace`  | Fetch a single workspace |
| `portkey_workspaces` | Fetch all workspaces     |
| `portkey_user`       | Fetch a single user      |
| `portkey_users`      | Fetch all users          |

## Support

* [GitHub repository](https://github.com/Portkey-AI/terraform-provider-portkey)
* [Terraform Registry](https://registry.terraform.io/providers/portkey-ai/portkey/latest)
* [Admin API reference](/api-reference/admin-api/introduction)
