Terraform: Unused variables in Terraform Files

Created on 25 Jan 2017  路  6Comments  路  Source: hashicorp/terraform

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.

config enhancement

Most helpful comment

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.

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amaczuga picture amaczuga  路  124Comments

radeksimko picture radeksimko  路  80Comments

nevir picture nevir  路  82Comments

FlorinAndrei picture FlorinAndrei  路  61Comments

lukehoersten picture lukehoersten  路  151Comments