🦞

OpenClaw Terraform Provider

Declarative configuration management for the OpenClaw AI gateway.

OpenClaw Terraform Provider

Unofficial community provider — This project is not affiliated with, endorsed by, or sponsored by the OpenClaw project or OpenAI. It is an independent, community-maintained Terraform provider.

The OpenClaw Terraform provider enables declarative, version-controlled management of your OpenClaw AI gateway configuration. Instead of editing openclaw.json by hand, define your gateway, channels, agents, and routing rules as Terraform resources.

Why Terraform for OpenClaw?

  • Version control -- track every config change in git
  • Review workflows -- PR-based approval for gateway changes
  • Reproducibility -- spin up identical configurations across environments
  • Composition -- combine OpenClaw config with cloud infrastructure in a single plan
  • Drift detection -- terraform plan shows exactly what changed outside Terraform

Architecture

The provider has two transport backends:

Infrastructure as Code
Terraform CLI
openclaw provider
WSClient
Live JSON-RPC
OpenClaw Gateway
:18789
FileClient
Direct read/write
~/.openclaw/
openclaw.json

WebSocket mode connects to a running gateway and patches config via the config.patch RPC. Changes take effect immediately (depending on reload_mode).

File mode reads and writes the JSON config file directly. Useful for pre-provisioning a config before the gateway starts, or in CI/CD pipelines.

Provider Configuration

See Provider Configuration for all options including authentication and environment variables.

Getting Started

1. Install OpenClaw

npm install -g openclaw

2. Start the gateway

openclaw gateway --port 18789

3. Write your Terraform config

terraform {
  required_providers {
    openclaw = {
      source = "registry.terraform.io/kylemclaren/openclaw"
    }
  }
}

provider "openclaw" {
  gateway_url = "ws://127.0.0.1:18789"
  token       = var.gateway_token
}

resource "openclaw_gateway" "main" {
  port        = 18789
  bind        = "loopback"
  reload_mode = "hybrid"
}

resource "openclaw_agent_defaults" "main" {
  model_primary   = "anthropic/claude-sonnet-4-20250514"
  workspace       = "~/.openclaw/workspace"
  timeout_seconds = 600
  heartbeat_every = "30m"
}

resource "openclaw_channel_whatsapp" "main" {
  dm_policy  = "pairing"
  allow_from = ["+15555550123"]
}

4. Apply

terraform init
terraform plan
terraform apply

5. Verify

cat ~/.openclaw/openclaw.json

File Mode (Offline Provisioning)

If no gateway_url is set, the provider operates on the config file directly:

provider "openclaw" {
  config_path = "/etc/openclaw/openclaw.json"
}

This is useful for:

  • Building a config before deploying the gateway
  • CI/CD pipelines that generate configs for deployment
  • Environments where the gateway isn't running during provisioning

Resource Overview

Core

ResourceDescriptionDoc
openclaw_gatewayServer settingsReference
openclaw_agent_defaultsDefault agent configReference
openclaw_agentIndividual agentReference
openclaw_bindingAgent routing rulesReference
openclaw_sessionSession lifecycleReference
openclaw_messagesMessage handlingReference

Channels

ResourceDescriptionDoc
openclaw_channel_whatsappWhatsAppReference
openclaw_channel_telegramTelegramReference
openclaw_channel_discordDiscordReference
openclaw_channel_slackSlackReference
openclaw_channel_signalSignalReference
openclaw_channel_imessageiMessageReference
openclaw_channel_googlechatGoogle ChatReference

Extensions

ResourceDescriptionDoc
openclaw_pluginPlugin entryReference
openclaw_skillSkill entryReference
openclaw_hookWebhooksReference
openclaw_cronCron jobsReference
openclaw_toolsTool access controlReference

Data Sources

Data SourceDescriptionDoc
openclaw_gatewayGateway settings (read-only)Reference
openclaw_agent_defaultsAgent default settings (read-only)Reference
openclaw_agentsAll configured agents (read-only)Reference
openclaw_channelsAll configured channels (read-only)Reference
openclaw_configFull raw config + hashReference
openclaw_healthGateway health (WS only)Reference

Import

All resources support terraform import. Singleton resources use a fixed ID:

terraform import openclaw_gateway.main gateway
terraform import openclaw_session.main session

Array-based resources use their identifier:

terraform import openclaw_agent.research research
terraform import openclaw_binding.discord_research "research/discord"
terraform import openclaw_plugin.web_search web_search
terraform import openclaw_skill.calculator calculator

Examples

On this page