terratidy is a powerful tool designed to format and lint your Terraform code, ensuring it adheres to best practices. By analyzing your code, terratidy can identify common issues and automatically fix them, making your configurations cleaner, more consistent, and easier to maintain. Forked from the AVMFIX tool.
While many issues can be resolved automatically, some may require manual adjustments. Following established best practices, such as proper directory structures, naming conventions, and clear documentation, will help you maintain high-quality Terraform modules.
terratidy can fix the following issues:
- Orders Within resource and data Blocks
- Order to define variable
- Do not declare
nullable = true
forvariable
- Do not declare
sensitive = false
forvariable
output
should be arranged alphabetically- Do not declare
sensitive = false
foroutput
local
should be arranged alphabetically- Orders in
moved
block. (from
thento
)
go install github.com/davenicoll/terratidy@latest
To use terratidy
, open a shell or terminal and run the following command:
terratidy -folder /path/to/your/terraform/module
Replace /path/to/your/terraform/module
with the path to the directory containing your Terraform module.
You can also use terratidy
in your pre-commit config to enforce consistent standards in your repositories.
- hooks:
- id: terratidy
name: terratidy
entry: /usr/bin/env bash -c 'for dir in $(git diff --cached --name-only --diff-filter=ACM | grep ".tf$" | xargs -n1 dirname | sort -u); do terratidy --folder "$dir"; done'
language: script
files: \.tf$
repo: local
The tool will analyze the specified directory and automatically apply fixes for any issues it identifies. If the process completes successfully, you'll see the message "Tidy completed successfully." If an error occurs during the process, terratidy
will display an error message.
Keep in mind that terratidy
may not be able to resolve all issues automatically. Manual intervention may be required for some problems.
terratidy
is provider-agnostic, seamlessly supporting AWS, Azure, Google Cloud Platform, and more.