tfclean for Mac
tfclean is a tool for cleaning up Terraform configuration files by automatically removing applied moved, import, and removed blocks.
tfclean — overview
tfclean is a tool for cleaning up Terraform configuration files by automatically removing applied moved, import, and removed blocks. This helps maintain clean and readable Terraform configurations by eliminating blocks that have already served their purpose.
Installation
Using Homebrew
Using go install
Using aqua
aqua is a declarative CLI Version Manager. You can install tfclean using aqua:
Or add to your aqua.yaml:
Then run:
Using GitHub Actions
You can use the official GitHub Action to install tfclean in your workflows:
Manual Installation
Download the appropriate binary for your system from the releases page.
Usage
Remove All Blocks
Remove all moved/import/removed blocks regardless of their state:
Remove Only Applied Blocks
Remove only the blocks that have been successfully applied (requires access to tfstate).
When using an S3 backend, you can omit --tfstate. tfclean auto-detects the state location by reading terraform { backend "s3" { ... } } from .tf files in the given directory.
Multiple tfstate Files
When the same Terraform configuration is backed by several states — for example one per developer, per PR, and dev/prod — pass --tfstate multiple times. A block is removed only if it has been applied in all of the given states; if it is still pending in any one of them, tfclean keeps it.
In the example above, a moved block that has been applied to dev-alice and prod but not yet to dev-bob is preserved until it is applied everywhere. Because dropping a state could remove a block that is still pending elsewhere, tfclean treats a failure to read any explicitly given state as a fatal error rather than silently skipping it.
Auto-detection only resolves a single backend from your .tf files, so multiple states must be specified explicitly with --tfstate.
Child Modules
Refactorings such as splitting a module leave moved / removed blocks inside a child module. tfclean cleans those too.
tfclean follows module blocks whose source is a local path (./ or ../), recursively, and cleans the .tf files in those directories that are inside the given directory (e.g. ./modules/x). Remote modules (registry, git, etc.) are never touched. Addresses inside a child module are relative to the module, so tfclean checks them against every instance of the module in the state (module.x, module.x[0], module.x["a"], and every caller if the module is called from several places). A block is removed only if it has been applied for all of those instances.
tfclean keeps a child module's blocks when it cannot find the module (or one of its parent instances has none of it) in the state, since its resources may still be under an old address that a pending moved block elsewhere will bring there.
Modules outside the given directory
Details
删除已应用的移动块、导入块等
How to install tfclean
- Open Terminal (press ⌘ + Space and type “Terminal”).
- If Homebrew is not installed yet, run the command below first.
- Run this command:
Latest 10 releases
Last updated 2026-11-09; current version v0.0.20, with the latest 10 releases listed.
| Version | Released | Type | Size | macOS | Windows | Linux |
|---|---|---|---|---|---|---|
| v0.0.20 | 2026-11-09 | Stable | 13.0 MB | Download | Download | Download |
| v0.0.19 | 2026-07-09 | Stable | 13.0 MB | Download | Download | Download |
| v0.0.18 | 2026-05-14 | Stable | 13.0 MB | Download | Download | Download |
| v0.0.17 | 2026-05-13 | Stable | 13.0 MB | Download | Download | Download |
| v0.0.16 | 2026-01-30 | Stable | 13.0 MB | Download | Download | Download |
| v0.0.15 | 2025-11-30 | Stable | 9.3 MB | Download | Download | Download |
| v0.0.14 | 2025-11-29 | Stable | 9.3 MB | Download | Download | Download |
| v0.0.13 | 2025-11-29 | Stable | 9.3 MB | Download | Download | Download |
| v0.0.12 | 2025-09-27 | Stable | 9.3 MB | Download | Download | Download |
| v0.0.11 | 2025-08-19 | Stable | 9.3 MB | Download | Download | Download |
Data from GitHub Releases; stable releases first, each group sorted newest first.
Prebuilt bottle platforms
Official Homebrew bottles cover:
- Apple silicon · latest macOS
- Apple silicon · macOS 26 Tahoe
- Apple silicon · macOS 15 Sequoia
- Linux · ARM64
- Linux · x86_64
⚠️ No prebuilt bottle for Intel Macs; Intel users need brew install --build-from-source to build from source.
Compared with similar apps
Only public metadata is compared, with no subjective recommendation; see the compare pages for field-by-field comparisons.
| App | Version | License | Architecture | 30-day installs |
|---|---|---|---|---|
| tfclean | v0.0.20 | MIT | CLI | 0 |
| librevenge | 0.0.6 | LGPL-2.1-or-later OR MPL-2.0 | CLI | 1 |
| tmpwatch | 2.11 | GPL-2.0-only | CLI | 1 |
| format-udf | 1.8.0 | GPL-2.0-or-later | CLI | 0 |
Similar apps: Command-line Tools
librevenge
librevenge is a foundational library aimed at document processing developers, primarily used…tmpwatch
tmpwatch is a small command-line utility designed to clean up files that have not been accessed…format-udf
Bash script to format a block device (hard drive or Flash drive) in UDF.openssl@4
Cryptography and SSL/TLS Toolkitxz
General-purpose data compression with high compression ratiopkgconf
pkgconf is a program which helps to configure compiler and linker flags for development…Categories: Command-line Tools