Inspectopedia 2025.2 Help

Unused elements

Reports unused variables, locals, and data sources in a Terraform module and provides a quick-fix to remove them.

Example of a problem:

data "aws_ami" "latest_amazon_linux" { most_recent = true filter { name = "name" values = ["amzn2-ami-hvm-*-x86_64-gp2"] } owners = ["amazon"] } data "aws_vpc" "unused_data_source" { default = true } resource "aws_instance" "example" { ami = data.aws_ami.latest_amazon_linux.id instance_type = "t2.micro" tags = { Name = "ExampleInstance" } } variable "used_variable" { description = "This variable is used in resource configuration" type = string default = "ami-01456a894f71116f2" } locals { instance_name = "used-instance" } resource "aws_instance" "example1" { ami = var.used_variable instance_type = "t2.micro" tags = { Name = local.instance_name } } variable "unused_variable1" { description = "This variable is not used anywhere in the configuration" type = string default = "default_value1" } locals { unused_local1 = "This is an unused local value" }

In this example, unused_data_source, unused_variable1, and unused_local1 are declared in the file, but are not used anywhere.

After the quick-fix is applied:

data "aws_ami" "latest_amazon_linux" { most_recent = true filter { name = "name" values = ["amzn2-ami-hvm-*-x86_64-gp2"] } owners = ["amazon"] } resource "aws_instance" "example" { ami = data.aws_ami.latest_amazon_linux.id instance_type = "t2.micro" tags = { Name = "ExampleInstance" } } variable "used_variable" { description = "This variable is used in resource configuration" type = string default = "ami-01456a894f71116f2" } locals { instance_name = "used-instance" } resource "aws_instance" "example1" { ami = var.used_variable instance_type = "t2.micro" tags = { Name = local.instance_name } } locals { }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

TfUnusedElements
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Terraform/OpenTofu

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection TfUnusedElements

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025