The Complete Production SOP: How to Deploy and Run tfsec Static Security Scanner for Terraform Code in Autonomous AI Agents
Production SOP to install and run the tfsec Static Security Scanner for Terraform in Claude Code, Codex, and Cursor. Audit rules, SARIF exports, and fixes.
Technical Overview & Architectural Context
Autonomous coding agents frequently generate insecure Terraform configurations—such as open egress/ingress rules (0.0.0.0/0), unencrypted AWS S3 buckets, permissive IAM policies, and unversioned state storage—because standard LLM training data prioritizes functional deployment speed over least-privilege security controls. When instructed to provision cloud infrastructure, agents lack native deterministic validation to catch policy regressions prior to plan generation. The tfsec Static Security Scanner skill injects rigorous static analysis routines directly into the agent's execution loop. By binding strict procedural rules to autonomous tools like Codex, Claude Code, Cursor, and Windsurf, this skill prevents uninspected Terraform commits. It forces agents to parse rule violations, apply explicit `#tfsec:ignore` annotations with logged audit rationales for intentional edge cases, and output SARIF (Static Analysis Results Interchange Format) reports compatible with enterprise GitHub Code Scanning pipelines.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the tfsec skill manifest into your agent's shared skill registry directory.
To make the scanner available across IDE runtimes like Claude Code CLI, Cursor, and Windsurf, place the SKILL.md manifest into the agent's designated workspace or global skill definitions folder (`.agents/skills/tfsec-static-security-scanner`). The agent runtime automatically parses the frontmatter metadata, registering trigger keywords such as 'scan terraform with tfsec' and enforcing the declared filesystem read/write boundary.
mkdir -p .agents/skills/tfsec-static-security-scanner && cat << 'EOF' > .agents/skills/tfsec-static-security-scanner/SKILL.md
---
name: "tfsec-static-security-scanner"
description: "Scan Terraform templates for security vulnerabilities and compliance misconfigurations."
metadata:
author: "Aqua Security"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "scan terraform with tfsec"
- "fix tfsec security warnings"
- "export tfsec sarif report"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: false
---
EOF---
name: "tfsec-static-security-scanner"
description: "Scan Terraform templates for security vulnerabilities and compliance misconfigurations."
metadata:
author: "Aqua Security"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "scan terraform with tfsec"
- "fix tfsec security warnings"
- "export tfsec sarif report"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: false
---Use `--concise-output` during initial scans to reduce token consumption by up to 70% compared to verbose AST JSON output.
Ensure `shell_exec` permission is enabled in environments that isolate command execution, otherwise the agent cannot invoke the local `tfsec` CLI binary.
CLI Binary Availability & Version Validation
Verify tfsec or Trivy is installed locally in the container or host PATH.
Autonomous agents will fail mid-execution if the underlying static analysis binary is missing. Execute a sanity check to verify `tfsec` is functional and check whether modern Trivy integration is preferred for unified SARIF outputs.
tfsec --version || brew install tfsec || curl -s https://raw.githubusercontent.com/aquasecurity/tfsec/master/scripts/install_linux.sh | bashIf using Trivy instead of legacy standalone tfsec, symlink or create an alias `alias tfsec="trivy config"` so default skill triggers execute transparently.
On macOS arm64/Apple Silicon running inside Cursor devcontainers, ensure Rosetta or native aarch64 binaries are selected to avoid silent `SIGILL` exit codes.
Intent Matching & Trigger Invocation
Invoke deterministic security scanning using specific trigger phrases.
Provide the agent with targeted instructions matching the registered frontmatter triggers. The agent matches 'scan terraform with tfsec' or 'fix tfsec security warnings' and executes the defined SOP instead of hallucinating ad-hoc regex validation.
Anchor prompts to clear severity thresholds, e.g., 'Scan Terraform with tfsec and resolve all CRITICAL and HIGH severity findings before running plan.'
Do not pass unformatted nested directories without specifying the module root path; always specify the target directory (e.g., `tfsec ./terraform`).
Verification, SARIF Generation & Quality Gate
Generate standard SARIF artifacts and confirm zero non-ignored findings.
Validate that the agent produced structured artifacts for CI integration and that all remaining security exceptions are annotated with explicit `#tfsec:ignore:<rule-id>:reason=<explanation>` comments directly above the offending blocks.
tfsec . --format sarif --out tfsec.sarif && test -s tfsec.sarifAdd `tfsec.sarif` to `.gitignore` if reports should only be generated as temporary CI pipeline artifacts to prevent workspace file bloat.
Reject agent responses that comment out security blocks entirely instead of applying correct terraform resource configurations or approved ignore flags.
Real-World Scenario: Remediating Insecure S3 Buckets and Security Groups in a Root Module
“We have new infrastructure files in ./infra. Scan terraform with tfsec, fix all CRITICAL and HIGH security warnings, annotate any intentional public assets, and export tfsec sarif report to ./reports/tfsec.sarif.”
Runtime Troubleshooting & Failure Modes
Root Cause: tfsec is attempting to parse external modules or providers referenced in the Terraform code, but child module source trees are missing because `terraform init` was skipped.
terraform init -backend=false && tfsec . --concise-outputRoot Cause: tfsec returns an exit code of 1 whenever issues equal to or higher than the default failure threshold are encountered, causing non-zero aborts in agent scripts.
tfsec . --soft-fail --format sarif --out tfsec.sarif || tfsec . --concise-outputFrequently Asked Questions (tfsec Static Security Scanner for Terraform Code SOP)
Q:Can I use tfsec Static Security Scanner for Terraform Code across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. Once installed in your shared `.agents/skills` directory, any compatible runtime (Codex, Claude Code, Cursor, or Windsurf) will recognize the metadata triggers and adhere to the procedural boundaries.
Q:How does tfsec Static Security Scanner for Terraform Code prevent context window overflow during long agent sessions?
The skill enforces the `--concise-output` flag and requires agents to parse structured findings rather than loading the complete AST or verbose JSON output into the context window, conserving thousands of LLM tokens per iteration.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It requires only standard workspace file read/write permissions and local non-root execution privileges to invoke the tfsec binary without outbound network access.
Ready to equip your autonomous agent with tfsec Static Security Scanner for Terraform Code?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.