unused-declarations
What it does
Section titled “What it does”Reports a variable, local value, data source or provider alias that no file of the module (the .tf files of the directory) refers to. Override files declare nothing of their own. A module with .tf.json files, a file that does not parse or one that cannot be read is not judged.
Why it matters
Section titled “Why it matters”An unused declaration is left over from a change. A variable that nothing reads misleads the user of the module, who sets it and sees no effect, and an unused data source still makes a request on each plan.
To fix, delete it.
Example
Section titled “Example”variable "used" {}variable "unused" {}locals { used_local = var.used unused_local = 1}data "aws_ami" "used" {}data "aws_ami" "unused" {}output "x" { value = "${local.used_local}-${data.aws_ami.used.id}"}provider "aws" { alias = "west"}provider "aws" {...Configuration
Section titled “Configuration”hcl: lint: rules: unused-declarations: warn # off (default), warn, errorEnabled by the presets: hcl/tflint-recommended.
Suppress one line with sudsy-disable-next-line unused-declarations in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| tflint | terraform_unused_declarations |
partial | Reads one file: a declaration used only by another file of the module is reported. |