Terraform (stf)
The stf subcommand group wraps Terraform operations for infrastructure provisioning, state management, and drift detection.
Synopsis
Commands
| Command | Description |
|---|---|
init |
Initialize a Terraform working directory |
validate |
Validate Terraform configuration |
plan |
Generate an execution plan |
apply |
Apply changes to infrastructure |
destroy |
Destroy managed infrastructure |
output |
Read output values from state |
show |
Show state or saved plan details |
refresh |
Update state to match real infrastructure |
fmt |
Format Terraform files |
graph |
Generate a dependency graph |
drift |
Detect configuration drift |
import |
Import existing resources into state |
state-list |
List resources in state |
state-rm |
Remove a resource from state |
state-pull |
Pull remote state to stdout |
state-push |
Push local state to remote backend |
provision |
Run init → plan → apply → output (applying requires --auto-approve, default false) |
init
Initialize a Terraform working directory.
Flags:
| Flag | Description |
|---|---|
--dir |
Terraform directory (default: current) |
--upgrade |
Upgrade modules and providers |
--reconfigure |
Reconfigure backend |
--backend-config |
Backend configuration (KEY=VALUE) |
validate
Validate Terraform configuration files.
plan
Generate and display an execution plan.
Flags:
| Flag | Description |
|---|---|
--dir |
Terraform directory |
--var |
Set variable (NAME=VALUE) |
--var-file |
Variable file path |
--out |
Save plan to file |
--destroy |
Create a destroy plan |
--target |
Target specific resource |
--refresh |
Refresh state before planning |
apply
Apply Terraform changes.
Flags:
| Flag | Description |
|---|---|
--auto-approve |
Skip interactive approval |
--dir |
Terraform directory |
--var / --var-file |
Input variables |
--target |
Target specific resource |
destroy
Destroy managed infrastructure.
output
Read output values from Terraform state.
show
Display Terraform state or a saved plan file.
Examples:
smurf stf show # current state
smurf stf show --json # state as JSON
smurf stf show plan.out # saved plan
smurf stf show --resource=aws_instance.web
smurf stf show --dir=environments/prod
drift
Detect drift between state and real infrastructure.
import
Import existing infrastructure into Terraform state.
Examples:
smurf stf import aws_instance.web i-1234567890abcdef0
smurf stf import module.vpc.aws_vpc.main vpc-12345678
smurf stf import --dir=./infra aws_s3_bucket.data my-bucket-name
State management
state-list
List all resources in the current state.
state-rm
Remove a resource from state without destroying it.
state-pull
Pull the remote state and output to stdout.
state-push
Push a local state file to the remote backend.
Warning
State push can overwrite remote state. Use with caution and ensure no concurrent operations are running.
provision
Run the full Terraform workflow in one command: init → plan → apply → output. Applying requires --auto-approve (default false); without it, provision stops after generating the plan and does not apply.
Flags:
| Flag | Description |
|---|---|
--dir |
Terraform directory |
--auto-approve |
Skip interactive approval and apply the plan (default false) |
--var / --var-file |
Input variables |
--upgrade |
Upgrade modules during init |
--out |
Save plan to file |
fmt
Format Terraform configuration files.
graph
Generate a visual dependency graph of resources.
AI-assisted mode
Many stf commands support an optional --ai flag that enables AI-powered error analysis when OPENAI_API_KEY is set:
See Advanced for details.
GitHub Actions example
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup Smurf
uses: clouddrove/[email protected]
with:
version: v1.1.9
- name: Terraform init
run: smurf stf init --dir=./infra
- name: Terraform validate
run: smurf stf validate --dir=./infra
- name: Terraform plan
run: smurf stf plan --dir=./infra
- name: Terraform apply
if: github.ref == 'refs/heads/main'
run: smurf stf apply --dir=./infra --auto-approve
Or use the combined provision command: