Registry / devops / prettier-plugin-terraform-formatter

prettier-plugin-terraform-formatter

JSON →
library1.2.1jsnpmunverified

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.

npm install prettier-plugin-terraform-formatter
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-TE
P
prettier-plugin-terraform-formatter
devopsjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
// No explicit import needed, Prettier autoloads plugin
const plugin = require('prettier-plugin-terraform-formatter')
Prettier plugins are loaded via configuration, not imported directly.
options
// In .prettierrc: { "plugins": ["prettier-plugin-terraform-formatter"], "terraformStrictError": true }
import { terraformStrictError } from 'prettier-plugin-terraform-formatter'
Plugin options are set in Prettier config, not imported.

Install plugin, set up config with terraform parser override, then format files via CLI.

// 1. Install: npm i -D prettier prettier-plugin-terraform-formatter // 2. Ensure terraform CLI is installed: which terraform // 3. Create .prettierrc: { "plugins": ["prettier-plugin-terraform-formatter"], "overrides": [ { "files": "*.tf", "options": { "parser": "terraform" } } ] } // 4. Format: npx prettier --write main.tf
Debug
Known issues
gotchaPlugin silently ignores tf files if terraform CLI is not installed or fails (non-zero exit code other than 2).
fix
Set 'terraformStrictError' to true to treat all failures as errors, or ensure terraform is installed and in PATH.
affects: >=1.0.0
gotchaThe plugin shells out to terraform fmt for each file, which can be slow for many files.
fix
Consider running terraform fmt directly for bulk formatting, or use Prettier's caching.
affects: >=1.0.0
gotchaDifferent terraform versions may produce different formatting results; plugin does not pin terraform version.
fix
Ensure consistent terraform version across team (e.g., via tfenv or Docker).
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'prettier-plugin-terraform-formatter'
Plugin not installed or missing from node_modules.
fix
Run: npm install prettier-plugin-terraform-formatter as a dev dependency.
[error] Invalid .prettierrc: plugins must be an array
Incorrect Prettier configuration format.
fix
Ensure plugins field is an array: 'plugins': ['prettier-plugin-terraform-formatter']
terraform: command not found
Terraform CLI is not installed or not in PATH.
fix
Install Terraform (e.g., via tfenv or hashicorp tap) and ensure it's executable.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
prettierrequiredPeer dependency: plugin requires Prettier >= 1.16.0 to function.
Agent activity
10 hits · last 30 days
node
10
Resources
prettier-plugin-terraform-formatter — npm install prettier-plugin-terraform-formatter · libregistry