Skip to content

empty-list-equality

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

Reports a comparison with an empty list, x == [] or x != []. It is false for an empty set or a tuple of another type.

[] is a tuple, and Terraform compares values of different types as not equal, so the comparison is false for an empty set or an empty list of another type, and the condition silently does the wrong thing.

To fix, compare the length: length(x) == 0.

Reported
a = var.l == []
b = var.l != []
c = [] == var.l
d = length(var.l) == 0
e = var.l == [] && var.m
f = var.l == [1]
hcl:
lint:
rules:
empty-list-equality: warn # off, warn (default), error

Enabled by the presets: hcl/tflint-recommended.

Suppress one line with sudsy-disable-next-line empty-list-equality in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
tflint terraform_empty_list_equality full