Skip to content

Terraform (stf)

The stf subcommand group wraps Terraform operations for infrastructure provisioning, state management, and drift detection.

Synopsis

smurf stf <command> [flags] [args]

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.

smurf stf init [flags]

Flags:

Flag Description
--dir Terraform directory (default: current)
--upgrade Upgrade modules and providers
--reconfigure Reconfigure backend
--backend-config Backend configuration (KEY=VALUE)
smurf stf init --dir=./infra
smurf stf init --upgrade

validate

Validate Terraform configuration files.

smurf stf validate [flags]
smurf stf validate
smurf stf validate --dir=./infra

plan

Generate and display an execution plan.

smurf stf plan [flags]

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
smurf stf plan --dir=./infra --var="region=us-east-1"
smurf stf plan --out=plan.out

apply

Apply Terraform changes.

smurf stf apply [flags]

Flags:

Flag Description
--auto-approve Skip interactive approval
--dir Terraform directory
--var / --var-file Input variables
--target Target specific resource
smurf stf apply --dir=./infra --auto-approve

destroy

Destroy managed infrastructure.

smurf stf destroy [flags]
smurf stf destroy --dir=./infra --auto-approve

output

Read output values from Terraform state.

smurf stf output [flags] [NAME]

show

Display Terraform state or a saved plan file.

smurf stf show [plan-file] [flags]

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.

smurf stf drift [flags]

import

Import existing infrastructure into Terraform state.

smurf stf import [flags] ADDRESS ID

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.

smurf stf state-list [--dir=PATH]

state-rm

Remove a resource from state without destroying it.

smurf stf state-rm [flags] ADDRESS
smurf stf state-rm aws_instance.old

state-pull

Pull the remote state and output to stdout.

smurf stf state-pull [flags]

state-push

Push a local state file to the remote backend.

smurf stf state-push [flags] [PATH]

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.

smurf stf provision [flags]

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
smurf stf provision
smurf stf provision --dir=./infra --auto-approve

fmt

Format Terraform configuration files.

smurf stf fmt [flags]

graph

Generate a visual dependency graph of resources.

smurf stf graph [flags]

AI-assisted mode

Many stf commands support an optional --ai flag that enables AI-powered error analysis when OPENAI_API_KEY is set:

export OPENAI_API_KEY=sk-...
smurf stf plan --ai
smurf stf apply --ai --auto-approve

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:

      - name: Terraform provision
        run: smurf stf provision --dir=./infra --auto-approve