Open ketzacoatl opened 1 month ago
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!
Terraform Version
I don't see a command that would relate to this feature/capability.
Use Cases
As your Terraform codebase grows, it gets increasingly difficult to find and identify unused Terraform code. This can come in the form of unused local values, variables, outputs, and modules. There is also a difference between "this is an optional variable" and "this variable is defined but not even used". Local values are also easy to locate when defined but left unused. Unused modules are a little more difficult to find, but it's still sometimes relevant. Outputs are a bit more vague, but it might be nice to have an option to find and print outputs that aren't being used / consumed in a codebase.
Attempted Solutions
I do this manually with code review,
git grep
, and my IDE.Proposal
Terraform could provide warnings during regular plan/etc operations when it finds unused code, similar to when Terraform finds references to values that are undeclared. There could also, or alternatively, be a command similar to
fmt
which traverses a module/project or group of modules/projects to find unused code.References
The inspiration for this comes from the general idea of "removing dead code", as well as specific tools such as "weeder" for Haskell: