Skip to content

IaC · maintainability

no-comment-cruft

iac:no-comment-cruft

Commented-out Terraform/IaC or a section-banner comment — delete it; code carries the what, comments only the why.

Code
SARJ202
Default
error
Fix
none
Languages
iac

Why

Disabled declarations drift from executable infrastructure, while decorative banners duplicate structure already expressed by modules and resource blocks.

Fix

Delete disabled HCL and decorative dividers; retain only comments that explain a non-obvious reason.

Before / after

Executed by this rule’s unit tests.

Before

Disabled Terraform resource

main.tf · focus
# resource "google_storage_bucket" "old" {
resource "google_storage_bucket" "current" {}

After

Comment explaining an infrastructure constraint

main.tf · focus
# Keep this bucket in us-central1 for data residency.
resource "google_storage_bucket" "records" {}

Limits

  • Commented assignments in tfvars files are allowed because they commonly document optional inputs.
  • Directives and heredoc bodies are excluded, and disabled HCL runs must be code-dominant.