terraform-wrapper
A type-safe Terraform CLI wrapper for Rust.
Installation
[]
= "0.3"
= { = "1", = ["rt-multi-thread", "macros"] }
Minimum supported Rust version: 1.85.0
Quick Start
use *;
async
Note: You must import the TerraformCommand trait to call .execute(). The prelude module re-exports everything you need.
Commands
Lifecycle
| Command | Description |
|---|---|
InitCommand |
Prepare working directory, download providers |
PlanCommand |
Preview infrastructure changes |
ApplyCommand |
Create or update infrastructure |
DestroyCommand |
Destroy infrastructure |
Inspection
| Command | Description |
|---|---|
ValidateCommand |
Check configuration validity |
ShowCommand |
Inspect current state or saved plan |
OutputCommand |
Read output values |
FmtCommand |
Format configuration files |
GraphCommand |
Generate DOT dependency graph |
ModulesCommand |
List installed modules |
ProvidersCommand |
Manage providers (lock, mirror, schema) |
TestCommand |
Run Terraform test files |
VersionCommand |
Get Terraform version info |
State and Workspace
| Command | Description |
|---|---|
WorkspaceCommand |
Manage workspaces (list, show, new, select, delete) |
StateCommand |
Advanced state management (list, show, mv, rm, pull, push) |
ImportCommand |
Import existing infrastructure into state |
ForceUnlockCommand |
Manually unlock state |
GetCommand |
Download and update modules |
RefreshCommand |
Update state to match remote (deprecated) |
Escape Hatch
| Command | Description |
|---|---|
RawCommand |
Run any subcommand not covered above |
Streaming Output
Long-running commands like apply produce streaming JSON events. Use stream_terraform to process them in real-time:
use *;
use ;
# async
See the streaming_apply example for a complete working example.
Config Builder
Define Terraform configs entirely in Rust -- no .tf files needed. Enable the config feature:
[]
= { = "0.3", = ["config"] }
use TerraformConfig;
use json;
#
See the config_builder example for a complete working example.
Features
| Feature | Default | Description |
|---|---|---|
json |
Yes | Typed JSON output parsing via serde / serde_json |
config |
No | TerraformConfig builder for .tf.json generation |
Disable defaults for raw command output only:
[]
= { = "0.3", = false }
Why terraform-wrapper?
| terraform-wrapper | terrars | terraform-rs | |
|---|---|---|---|
| Approach | CLI wrapper | CDK-style codegen | Minimal CLI wrapper |
| Async | Yes (tokio) | No | No |
| JSON output | Typed structs | N/A | No |
| Maintained | Active | Active | Unmaintained (2021) |
| Use case | Orchestration tools | Generate .tf in Rust | Basic CLI calls |
Use terraform-wrapper when you need to programmatically drive Terraform lifecycles (provision, extract outputs, tear down) from Rust with type-safe, async APIs.
Documentation
Full API reference is available on docs.rs.
See the examples/ directory for working examples:
ec2_instance-- Full AWS lifecyclegce_instance-- Full GCP lifecyclestreaming_apply-- Real-time JSON event processingconfig_builder-- Generate.tf.jsonfrom Rustworkspace_management-- Create, switch, and delete workspacesvalidate_and_fmt-- Check and fix configuration
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.