terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Unused variables in Terraform Files

Open cemo opened this issue 8 years ago • 8 comments

It would be cool to detect unused variables in especially in module files. I usually include a module and check that required parameters for module for how they are used. Sometimes I can see that author is not using a required variable which is simply can be deleted.

cemo avatar Jan 25 '17 15:01 cemo

This! I was just looking for the same thing, where I could clean up unused vars.

bencoughlan avatar Sep 26 '17 14:09 bencoughlan

You can use something like: https://github.com/ContainerLabs/terraform-unused-vars or if you use pre-commit: https://github.com/pecigonzalo/pre-commit-terraform-vars

But It would be great to have it integrated onto validate or similar

pecigonzalo avatar Nov 22 '17 16:11 pecigonzalo

This needs to be a thing!!

mohanidragel avatar May 15 '18 15:05 mohanidragel

@pecigonzalo ContainerLabs/terraform-unused-vars is gone, do you have any replacements to suggest?

dserodio avatar Aug 21 '18 16:08 dserodio

@dserodio there seems to be a copy of the original ContainerLabs/terraform-unused-vars script within @pecigonzalo 's repo here: https://github.com/pecigonzalo/pre-commit-terraform-vars/blob/master/terraform_unused_vars/main.py which worked for me 😄

Still would be great to see this feature built in to Terraform

marcjay avatar Jan 11 '19 11:01 marcjay

Working on adding this to tflint, keep an eye out for a release soon:

https://github.com/terraform-linters/tflint/pull/739

In addition to variables, it will also detect locals and and data sources that have been declared but not referenced.

bendrucker avatar May 06 '20 05:05 bendrucker

I hope terraform would consider what people want faster. Why people should use 3rd party open source tools if it's easily can be implemented with terraform.

Arlington1985 avatar May 20 '22 14:05 Arlington1985

I'm looking for this as well. Incorporating this into 'terraform validate' even if it was an extra argument would be super useful.

abower-digimarc avatar May 08 '24 00:05 abower-digimarc