惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
宝玉的分享
宝玉的分享
美团技术团队
量子位
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
爱范儿
爱范儿
J
Java Code Geeks
博客园 - Franky
Last Week in AI
Last Week in AI
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
GbyAI
GbyAI
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
why you need hcl-linter?
Bartłomiej D · 2026-04-23 · via DEV Community

Bartłomiej Danek

Why You Need hcl-linter?

If you've worked with HCL (HashiCorp Configuration Language) in Terraform or Terragrunt, you know the pain: formatting debates in code reviews, subtle typos in block names, drift between environments, and the endless "just run terraform fmt" dance. hcl-linter exists to move those conversations from human review into deterministic, fixable checks.

More Than Just Formatting

Unlike terraform fmt or terragrunt hclfmt - which only touch whitespace - hcl-linter enforces structure. It checks block order, naming conventions, required fields, path references, duplicate labels, and more. Most importantly, many of these rules are auto-fixable, so your CI can not only fail fast but also auto-clean legacy configs.

  • hcl-linter check ./ - CI-friendly lint that exits 1 on any issue
  • hcl-linter fix ./ - Apply fixable rules in-place (block order, array formatting, blank lines, naming)
  • hcl-linter fix ./ --dry-run - See exactly what would change before committing
  • hcl-linter fix ./ --format - Bootstrap formatting without any config

Config That Matches Your Files

hcl-linter uses per-filename config matching via .hcl-linter/ directory. One file per target filename (e.g., terragrunt.hcl, root.hcl, default.hcl as fallback). Config is HCL, not YAML or JSON - no context switching required. Configs support inheritance via extends and per-directory overrides (closest wins), making it ideal for monorepos.

# .hcl-linter/default.hcl
rules {
  block_order {
    enabled = true
    order   = ["include", "locals", "terraform", "dependency", "inputs"]
  }
  required_blocks {
    required {
      type  = "terraform"
      count = "once"
      error = "missing terraform block"
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Rules That Matter in PRs

  • block_order - Enforces logical block sequencing; unlisted blocks placed after listed ones
  • array_format - 1 item inline, 2+ items multiline with trailing commas
  • name_validation - Enforces snake_case (or custom regex) on labels
  • duplicates - Catches duplicate dependency "x" or include "x" labels
  • required_fields - Ensures critical attributes exist when a block is present
  • dependency_paths - Validates config_path actually exists on disk
  • remote_state - Enforces backend when require_backend = true
  • hcl_functions - Validates find_in_parent_folders paths and warns on get_env without defaults
  • terraform_block - Checks source, version format, and deprecations
  • count_for_each - Warns on count = 0, for_each = {}, and conflicts
  • dependency_outputs - Validates dependency.x.outputs.y against actual outputs

Fix-Only Rules

Some issues can't be auto-fixed safely (e.g., missing source could hide bugs). Others - like formatting and ordering - are fix-only with no Check phase: blank_lines cleans up whitespace; array_format normalizes lists; block_order reorders blocks.

Zero-Config Fast Path

No config yet? Run hcl-linter fix ./ --format for opinionated defaults:

  • Block order: include → locals → terraform → dependency → inputs
  • Arrays with 2+ items → multiline with trailing commas
  • Blank-line cleanup within and between blocks

This is perfect for one-off formatting or bootstrapping a new project before introducing config-based rules.

CI Integration

In CI, use hcl-linter check ./ for strict non-zero exit on violations, or hcl-linter fix ./ --dry-run to detect byte-level drift - including drift from fix-only rules that check would silently pass.

# Validate configs for typos
hcl-linter validate-config

# Lint all matching files
hcl-linter lint ./ --verbose

# Enforce formatting without config
hcl-linter fix ./ --format --dry-run

Enter fullscreen mode Exit fullscreen mode

Why This Thread Matters

As teams grow and HCL files multiply, the drift compounds: noisy diffs, review time spent on layout, and ../vpc paths that silently point to moved resources. hcl-linter moves those concerns into deterministic, automated checks - not human reviewers.

The config is HCL. The rules are per-file/type. Some fixes are automatic, some not, because we still need people for some chores.

Follow the thread and stay tuned!


Originally published at https://bard.sh/posts/hcl_linter/