Skip to content
Configuration As Code

Configuration As Code

Configuration As Code

Partite.ai Mesh supports managing all configuration as code using Terraform. Both code-first and UI first approaches are supported.

Prerequisites

To use the Partite.ai Terraform provider, you need an API key with the Read configuration and Write configuration scopes.

Provider Configuration

The next step is to configure Terraform to use the Partite.ai provider. This is done in two parts:

  • In the terraform block, declare the provider as required for this configuration
  • Declare a provider block containing the configuration for the Partite.ai provider

An example configuration looks like:

terraform {
  required_providers {
    partiteai = {
      source  = "tf.partite.ai/partite-ai/partiteai"
      version = "1.0.21"
    }
  }
}

provider "partiteai" {
  api_token = var.partite_api_token
}

variable "partite_api_token" {
  type      = string
  sensitive = true
}

api_token is the API key’s token, which starts with prt_ak_. Instead of setting it in the configuration, you can set the PARTITE_AI_API_TOKEN environment variable. This is useful when a CI/CD system or another secret store holds the token.

The older api_key and api_secret settings, and the PARTITE_AI_API_KEY and PARTITE_AI_API_SECRET environment variables, are deprecated. Use api_token.

By default, the provider connects to the hosted service. To connect to a self-hosted Partite Mesh, set endpoint to its GraphQL URL:

provider "partiteai" {
  api_token = var.partite_api_token
  endpoint  = "http://localhost:8080/graphql"
}

You can also set the PARTITE_AI_ENDPOINT environment variable.

The enterprise boolean turns on the evaluation resources: partiteai_judge_metric, partiteai_rubric, partiteai_eval_mesh_monitor and the partiteai_computed_metric data source. It defaults to true when the endpoint host ends in .partite.ai. Set it to false for a self-hosted Partite Mesh, which does not serve them.

State Storage

Terraform requires storage of a state file that tracks the state of the last apply of the configuration. If you have an existing strategy to store your Terraform state files, you may skip this section, otherwise read on for options.

If you’re unfamiliar with Terraform’s state storage, you might want to read the Terraform Documentation covering state storage backends.

Local State Storage

One option for storing the state is to use the Terraform default local state storage. In this case, the state file will be stored as a file called terraform.tfstate in the directory where your Terraform files are stored. After each run, you must preserve this file, for example by committing it to source control. If you configure API Keys or Webhook Destinations in your Terraform, this state file may contain sensitive information, so you should encrypt it prior to storage.

See Terraform local Backend Documentation for more information on this option.

Cloud Hosted State Storage

To simplify the usage of Partite.ai, we provide the ability to store Terraform state in the Partite.ai Cloud using Terraform’s http backend. The Cloud hosted service supports storing multiple state files so you can maintain multiple different Terraform configurations for different projects.

To use the Cloud hosted state storage, configure Terraform’s http Backend to use https://api.partite.ai/tfstate/<state file name> as the address, lock_address and unlock_address. Set username to x-api-key and password to the API key’s token. <state file name> can be any string that uniquely identifies the current project within your account, for example project1 or myapp-prod. <state file name> may contain slashes. The API key needs the Write configuration scope.

Example:

terraform {
  required_providers {
    partiteai = {
      source  = "tf.partite.ai/partite-ai/partiteai"
      version = "1.0.21"
    }
  }

  backend "http" {
    address        = "https://api.partite.ai/tfstate/<state file name>"
    lock_address   = "https://api.partite.ai/tfstate/<state file name>"
    unlock_address = "https://api.partite.ai/tfstate/<state file name>"
    username       = "x-api-key"
  }
}

Leave the token out of the file. Terraform reads the password from the TF_HTTP_PASSWORD environment variable.

Resources

Once you’ve configured the provider, you’re ready to define your resources. This can be done code first by writing Terraform, or UI first by configuring in the Partite.ai UI and using the export to Terraform functionality. A common workflow is to create an initial version in the UI, and then as the configuration solidifies export to Terraform to manage as code.

To export a resource as Terraform in the UI, navigate to the list page for that resource. In the Actions column on each row, you’ll find a button labeled “Export as Terraform”. Clicking this button will bring up a dialog with the Terraform definitions of that resource, along with all dependent resources by default. If you wish, you can turn off the export of the dependent resources. By default, import blocks for each resource are also generated to allow the initial apply of the Terraform resources to import the resources that have been configured in the UI.

The CLI can also export Terraform, with partite export.

The resource and data source reference, generated from the provider, is in the provider repository: terraform-provider-partiteai/docs.

Resource types

  • Models: partiteai_model_provider, partiteai_model_profile, partiteai_embedding_profile, partiteai_model_set
  • Memory: partiteai_memory_store, partiteai_memory_interaction_profile
  • Tools: partiteai_mcp_connection, partiteai_mcp_connection_subscription, partiteai_mcp_connection_tunnel_key, partiteai_particle_artifact, partiteai_installed_particle, partiteai_workspace, partiteai_skill, partiteai_client_task_definition
  • Agents: partiteai_agent
  • Meshes: partiteai_mesh, partiteai_mesh_input, partiteai_mesh_link, partiteai_mesh_version_label, partiteai_route
  • Observability (hosted service only): partiteai_judge_metric, partiteai_rubric, partiteai_eval_mesh_monitor
  • Access: partiteai_api_key, partiteai_access_point, partiteai_access_point_client, partiteai_access_point_client_secret, partiteai_boundary
  • Triggers: partiteai_webhook_destination

Schedules have no Terraform resource yet.

Exporting

The Export as Terraform dialog offers these options:

  • Include import blocks, on every entity.
  • Include MCP connections, particles, skills, client tasks and memory, for agents and meshes.
  • Include agents, boundaries, model sets and model providers, for meshes.
  • Include model providers, for model sets.
  • Include boundaries, for access points.
  • Include mesh, for webhook destinations.

These entities have an Export action: agents, meshes, model sets, model providers, MCP connections, particles, skills, client tasks, API keys, access points, boundaries and webhook destinations.

Some resources are exported only with others:

  • Memory stores and interaction profiles, with an agent or mesh when Include memory is on.
  • Workspaces, with the particles that use them.
  • An access point’s clients, with the access point.
  • A mesh’s routes and version labels, with the mesh, but only when Include import blocks is on. Without import blocks, a route could name a version that a new organization doesn’t have, and applying a label resource would freeze the current draft as a new version and label that.

You cannot export schedules, evaluation objects, tunnel keys, access point client secrets and webhook handlers. Manage these by hand, or write the resources yourself.

Applying

Once your provider configuration and resources are defined, you can use terraform plan and terraform apply to apply changes to your Partite.ai configuration.