Terraform provider

The agynio/terraform-provider-agyn provider wraps the Gateway API as Terraform resources and data sources. Use it to declare organizations, agents, models, secrets, runners, and apps in .tf files.

For the user-facing introduction, see Administer → Terraform. This page is the developer reference.

Provider configuration

hcl
terraform {
  required_providers {
    agyn = {
      source  = "agynio/agyn"
      version = "~> 1.0"
    }
  }
}

provider "agyn" {
  gateway = "https://gateway.agyn.example.com"
  token   = var.agyn_api_token
}
ArgumentDescription
gatewayGateway endpoint URL (e.g. https://gateway.agyn.example.com). Required.
tokenAPI token. Use the AGYN_TOKEN env var instead in CI. Required.
insecure_skip_verifySkip TLS verification. Local development only.

Resources

ResourceWhat it manages
agyn_organizationOrganization.
agyn_organization_memberMembership in an organization.
agyn_cluster_adminCluster admin tuple (cluster admin only).
agyn_agentAgent.
agyn_agent_rolePer-agent role assignment.
agyn_agent_mcpMCP server attached to an agent.
agyn_agent_skillSkill on an agent.
agyn_agent_hookHook on an agent.
agyn_agent_envEnvironment variable on an agent / MCP / hook.
agyn_agent_init_scriptInit script on an agent / MCP / hook.
agyn_volumeVolume definition.
agyn_agent_volume_attachmentAttaches a volume to an agent / MCP / hook.
agyn_image_pull_secretImage pull secret.
agyn_agent_image_pull_secret_attachmentAttaches an image pull secret to an agent / MCP / hook.
agyn_llm_providerLLM provider.
agyn_llm_modelLLM model mapping.
agyn_secret_providerExternal secret store (Vault, etc.).
agyn_secretSecret value (local or remote reference).
agyn_runnerRunner registration.
agyn_appApp publication.
agyn_app_installationApp installation in an organization.

Data sources

Data sourceDescription
agyn_userLook up a user by username or OIDC subject. Returns identity_id.
agyn_agentLook up an agent by name.
agyn_appLook up a published app by slug.
agyn_organizationLook up an organization by name.
agyn_runnerLook up a registered runner.

End-to-end example

hcl
resource "agyn_organization" "acme" {
  name = "Acme"
}

resource "agyn_organization_member" "alice" {
  organization_id = agyn_organization.acme.id
  username        = "alice"
  role            = "owner"
}

resource "agyn_secret" "openai_key" {
  organization_id = agyn_organization.acme.id
  name            = "openai-api-key"
  value           = var.openai_api_key
}

resource "agyn_llm_provider" "openai" {
  organization_id = agyn_organization.acme.id

  name        = "openai-prod"
  endpoint    = "https://api.openai.com/v1"
  protocol    = "responses"
  auth_method = "bearer"

  token_secret_id = agyn_secret.openai_key.id
}

resource "agyn_llm_model" "gpt_4o" {
  organization_id   = agyn_organization.acme.id
  provider_id       = agyn_llm_provider.openai.id

  name              = "gpt-4o"
  remote_model_name = "gpt-4o-2024-08-06"
}

resource "agyn_runner" "acme_runner" {
  organization_id = agyn_organization.acme.id
  name            = "acme-runner"
  labels          = { region = "us-east-1" }
  capabilities    = ["docker"]
}

resource "agyn_agent" "support" {
  organization_id = agyn_organization.acme.id

  name        = "Support Agent"
  nickname    = "support"
  description = "Front-line support."

  model      = agyn_llm_model.gpt_4o.name
  image      = "ghcr.io/agynio/agent-runtime:v1.0.0"
  init_image = "ghcr.io/agynio/agent-init-codex:v1.0.0"

  idle_timeout = "5m"
  availability = "internal"

  runner_labels = { region = "us-east-1" }
}

resource "agyn_agent_mcp" "files" {
  agent_id = agyn_agent.support.id
  name     = "files"
  image    = "ghcr.io/agynio/files-mcp:latest"
}

resource "agyn_agent_skill" "tone_guide" {
  agent_id = agyn_agent.support.id
  name     = "tone-guide"
  body     = file("${path.module}/skills/tone-guide.md")
}

terraform apply produces a working agent reachable from chat.

State and sensitive values

  • agyn_secret's value is stored in Terraform state. Use a remote state backend with encryption.
  • agyn_runner's service_token is a sensitive output. Pipe it to a Secret on the runner cluster — do not commit it.
  • agyn_app's service_token is the same.

Treat the Terraform state as production secret material.

Imports

To bring an existing Console-created resource under Terraform:

sh
terraform import agyn_agent.support <agent_id>

After import, write the matching .tf block and run terraform plan to see any drift. Most resources support import; secrets do not (the value is not retrievable).

CI workflow

yaml
- run: terraform init
- run: terraform plan -out plan
  env:
    AGYN_TOKEN: ${{ secrets.AGYN_TOKEN }}
- run: terraform apply plan
  if: github.ref == 'refs/heads/main'

Use a dedicated CI token (one per environment) with org owner scope on the target organization. Grant cluster admin only when managing cluster-scoped resources.