terraform
terraform copied to clipboard
Unused variables in Terraform Files
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.
This! I was just looking for the same thing, where I could clean up unused vars.
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
This needs to be a thing!!
@pecigonzalo ContainerLabs/terraform-unused-vars is gone, do you have any replacements to suggest?
@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
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.
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.
I'm looking for this as well. Incorporating this into 'terraform validate' even if it was an extra argument would be super useful.