Provider Configuration
Configure the OpenClaw Terraform provider.
Example Usage
WebSocket Mode (Recommended)
Connect to a running OpenClaw gateway for live configuration:
provider "openclaw" {
gateway_url = "ws://127.0.0.1:18789"
token = var.gateway_token
}File Mode
Manage the config file directly without a running gateway:
provider "openclaw" {
config_path = "~/.openclaw/openclaw.json"
}Environment Variables Only
All provider attributes can be set via environment variables, allowing a zero-config provider block:
provider "openclaw" {}export OPENCLAW_GATEWAY_URL="ws://127.0.0.1:18789"
export OPENCLAW_GATEWAY_TOKEN="your-secret-token"
terraform applyArgument Reference
| Argument | Type | Description | Env Var | Default |
|---|---|---|---|---|
gateway_url | String | WebSocket URL of the OpenClaw gateway. When set, the provider uses WebSocket mode. | OPENCLAW_GATEWAY_URL | -- |
token | String, Sensitive | Authentication token for the gateway WebSocket API. | OPENCLAW_GATEWAY_TOKEN | -- |
config_path | String | Path to the openclaw.json config file. Used when gateway_url is not set. | OPENCLAW_CONFIG_PATH | ~/.openclaw/openclaw.json |
Mode Selection
The provider automatically selects its transport mode:
- If
gateway_urlis set (orOPENCLAW_GATEWAY_URL), WebSocket mode is used. The provider connects to the gateway's WS RPC API and applies changes viaconfig.patch. - Otherwise, File mode is used. The provider reads and writes the JSON config file at
config_path.
WebSocket Mode
- Requires a running OpenClaw gateway
- Changes are applied via the
config.patchRPC - Config reloads happen according to the gateway's
reload_modesetting - The
openclaw_healthdata source is only available in this mode - Supports authentication via
token
File Mode
- No running gateway required
- Reads and writes
openclaw.jsondirectly - Uses a mutex to safely handle parallel resource operations
- The
openclaw_healthdata source will return an error in this mode - Useful for pre-provisioning configs before deploying the gateway
Authentication
When the gateway has gateway.auth.mode set to "token", you must provide the matching token:
variable "gateway_token" {
type = string
sensitive = true
}
provider "openclaw" {
gateway_url = "ws://127.0.0.1:18789"
token = var.gateway_token
}Or via environment variable:
export OPENCLAW_GATEWAY_TOKEN="your-secret-token"If the gateway has no auth configured (auth.mode = "none"), the token argument can be omitted.