{"id":20443,"library":"prettier-plugin-terraform-formatter","title":"Prettier Terraform Formatter Plugin","description":"A Prettier plugin that formats Terraform files by shelling out to the local `terraform fmt` command. Version 1.2.1 is the current stable release, with a maintenance cadence. Unlike other Terraform formatters (like `terraform fmt` directly), this integrates with Prettier workflows and respects Prettier's file matching and option system. The Terraform CLI must be installed separately. Supports `terraformStrictError` option to control error behavior when terraform is not found.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/elliot-nelson/prettier-plugin-terraform-formatter","tags":["javascript","plugin","prettier","terraform"],"install":[{"cmd":"npm install prettier-plugin-terraform-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-terraform-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-terraform-formatter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: plugin requires Prettier >= 1.16.0 to function.","package":"prettier","optional":false}],"imports":[{"note":"Prettier plugins are loaded via configuration, not imported directly.","wrong":"const plugin = require('prettier-plugin-terraform-formatter')","symbol":"plugin","correct":"// No explicit import needed, Prettier autoloads plugin"},{"note":"Plugin options are set in Prettier config, not imported.","wrong":"import { terraformStrictError } from 'prettier-plugin-terraform-formatter'","symbol":"options","correct":"// In .prettierrc: { \"plugins\": [\"prettier-plugin-terraform-formatter\"], \"terraformStrictError\": true }"}],"quickstart":{"code":"// 1. Install: npm i -D prettier prettier-plugin-terraform-formatter\n// 2. Ensure terraform CLI is installed: which terraform\n// 3. Create .prettierrc:\n{\n  \"plugins\": [\"prettier-plugin-terraform-formatter\"],\n  \"overrides\": [\n    {\n      \"files\": \"*.tf\",\n      \"options\": {\n        \"parser\": \"terraform\"\n      }\n    }\n  ]\n}\n// 4. Format: npx prettier --write main.tf","lang":"javascript","description":"Install plugin, set up config with terraform parser override, then format files via CLI."},"warnings":[{"fix":"Set 'terraformStrictError' to true to treat all failures as errors, or ensure terraform is installed and in PATH.","message":"Plugin silently ignores tf files if terraform CLI is not installed or fails (non-zero exit code other than 2).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider running terraform fmt directly for bulk formatting, or use Prettier's caching.","message":"The plugin shells out to terraform fmt for each file, which can be slow for many files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure consistent terraform version across team (e.g., via tfenv or Docker).","message":"Different terraform versions may produce different formatting results; plugin does not pin terraform version.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install prettier-plugin-terraform-formatter as a dev dependency.","cause":"Plugin not installed or missing from node_modules.","error":"Error: Cannot find module 'prettier-plugin-terraform-formatter'"},{"fix":"Ensure plugins field is an array: 'plugins': ['prettier-plugin-terraform-formatter']","cause":"Incorrect Prettier configuration format.","error":"[error] Invalid .prettierrc: plugins must be an array"},{"fix":"Install Terraform (e.g., via tfenv or hashicorp tap) and ensure it's executable.","cause":"Terraform CLI is not installed or not in PATH.","error":"terraform: command not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}