Skip to content

unused-declarations

Terraform (HCL)suspiciousno fixdefault: offhcl/tflint-recommended

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.

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.

Reported
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" {
...
hcl:
lint:
rules:
unused-declarations: warn # off (default), warn, error

Enabled by the presets: hcl/tflint-recommended.

Suppress one line with sudsy-disable-next-line unused-declarations in a comment of the file’s language.

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.