| name |
description |
license |
tags |
| terraform-style-check |
Audit Terraform and OpenTofu configurations for style, best practices, security, and compliance. Checks naming conventions, resource organization, variable usage, module structure, and IAM least-privilege patterns. |
MIT |
--- terraform infrastructure devops security iac |
Terraform Style Check
Overview
Audit Terraform (and OpenTofu) configurations for style consistency, security best practices, module structure, and compliance requirements. Provides actionable fixes with severity ratings.
When to Use
- Before merging infrastructure PRs for code review
- When onboarding a new Terraform codebase with inconsistent patterns
- When enforcing organizational IaC standards across teams
- When conducting security audits of cloud infrastructure code
- When preparing infrastructure code for compliance certification
Instructions
- Accept path to Terraform directory or specific
.tf files.
- Parse all
.tf files and build an AST representation.
- Style checks:
- Naming conventions: resources use
snake_case, descriptive names.
- File organization:
main.tf, variables.tf, outputs.tf, versions.tf separation.
- Variable declarations: all variables have
type, description, and default where appropriate.
- Output declarations: all outputs have
description.
- Resource tagging: required tags (env, owner, project) present on all taggable resources.
- Best practice checks:
- Remote state: backend configured, not using local state in production.
- Module versions: all module sources pinned to specific version.
- Provider versions: all providers pinned with
~> constraint.
- Sensitive variables: marked with
sensitive = true.
- Security checks:
- IAM policies: no
* on actions without explicit justification comment.
- Security groups: no
0.0.0.0/0 on inbound rules except ports 80/443.
- Encryption: storage resources (S3, RDS, EBS) have encryption enabled.
- Public access: S3 buckets not publicly accessible without justification.
- Generate report: issues grouped by severity (Critical, High, Medium, Low, Info).
- For each issue: file, line number, current code, and recommended fix.
Environment
CHECK_NAMING=true
CHECK_SECURITY=true
CHECK_MODULES=true
REQUIRED_TAGS=env,owner,project
STRICT_IAM=true
Examples
Input:
path: ./infrastructure/aws
profile: production
check_level: full
Output:
Terraform Style Check Report
Files scanned: 18
Total issues: 23
Critical (2):
- security_groups.tf:45 - Inbound rule allows 0.0.0.0/0 on port 22 (SSH)
- iam.tf:78 - IAM policy uses wildcard action "s3:*" without justification
High (5):
- main.tf:12 - Module source not pinned to version (add ?ref=v2.1.0)
- variables.tf:34 - Variable 'db_password' missing sensitive=true
- rds.tf:23 - RDS instance encryption not enabled
Medium (8): [naming, tagging issues]
Low (8): [style, description missing]
1---2name: terraform-style-check3description: | name | description | license | tags |4---5| name | description | license | tags |6|------|-------------|---------|------|7| terraform-style-check | Audit Terraform and OpenTofu configurations for style, best practices, security, and compliance. Checks naming conventions, resource organization, variable usage, module structure, and IAM least-privilege patterns. | MIT | --- terraform infrastructure devops security iac |89# Terraform Style Check1011## Overview1213Audit Terraform (and OpenTofu) configurations for style consistency, security best practices, module structure, and compliance requirements. Provides actionable fixes with severity ratings.1415## When to Use1617- Before merging infrastructure PRs for code review18- When onboarding a new Terraform codebase with inconsistent patterns19- When enforcing organizational IaC standards across teams20- When conducting security audits of cloud infrastructure code21- When preparing infrastructure code for compliance certification2223## Instructions24251. Accept path to Terraform directory or specific `.tf` files.262. Parse all `.tf` files and build an AST representation.273. Style checks:28 - Naming conventions: resources use `snake_case`, descriptive names.29 - File organization: `main.tf`, `variables.tf`, `outputs.tf`, `versions.tf` separation.30 - Variable declarations: all variables have `type`, `description`, and `default` where appropriate.31 - Output declarations: all outputs have `description`.32 - Resource tagging: required tags (env, owner, project) present on all taggable resources.334. Best practice checks:34 - Remote state: backend configured, not using local state in production.35 - Module versions: all module sources pinned to specific version.36 - Provider versions: all providers pinned with `~>` constraint.37 - Sensitive variables: marked with `sensitive = true`.385. Security checks:39 - IAM policies: no `*` on actions without explicit justification comment.40 - Security groups: no `0.0.0.0/0` on inbound rules except ports 80/443.41 - Encryption: storage resources (S3, RDS, EBS) have encryption enabled.42 - Public access: S3 buckets not publicly accessible without justification.436. Generate report: issues grouped by severity (Critical, High, Medium, Low, Info).447. For each issue: file, line number, current code, and recommended fix.4546## Environment4748```49CHECK_NAMING=true50CHECK_SECURITY=true51CHECK_MODULES=true52REQUIRED_TAGS=env,owner,project53STRICT_IAM=true54```5556## Examples5758**Input:**59```60path: ./infrastructure/aws61profile: production62check_level: full63```6465**Output:**66```67Terraform Style Check Report68Files scanned: 1869Total issues: 237071Critical (2):72- security_groups.tf:45 - Inbound rule allows 0.0.0.0/0 on port 22 (SSH)73- iam.tf:78 - IAM policy uses wildcard action "s3:*" without justification7475High (5):76- main.tf:12 - Module source not pinned to version (add ?ref=v2.1.0)77- variables.tf:34 - Variable 'db_password' missing sensitive=true78- rds.tf:23 - RDS instance encryption not enabled7980Medium (8): [naming, tagging issues]81Low (8): [style, description missing]82```