Interpolation-only expressions are deprecated in Terraform v0.12.14

We have been doing,

node_selector = var.node_group != null ? { “${var.node_group}” = true } : null

and in tfvars we will have,

node_selector = “NODEGROUP2”
And it works correctly.

Tflint is now throwing a warning on it as below,
Warning: Interpolation-only expressions are deprecated in Terraform v0.12.14 (terraform_deprecated_interpolation)

Trying to understand what exactly its throwing warning and possible fixes?
Is it complaining on “${}” and I have to set to set it as var.node_group ?

setting the line as,

node_selector = var.node_selector != null ? { “var.node_selector” = true } : null

clear the tflint warning, however value is not being replaced for var.node_selector

If I can make question much simpler, How do I make below work?

resource “random_pet” “this” {
keepers = {
“var.key” = “test”
}
}

variable “key” {
type = string
description = “test”
default = “ami_id”
}

Any thoughts?

Thanks.

Solved as below,

resource "random_pet" "this" {
  keepers = {
    (var.key) = "test"
  }
}

Had to put var inside parenthesis.

Um, those aren’t parentheses…

Parentheses are not needed.

You simply write var.key with no additional punctuation at all.

Sorry edited the post.
var.key within {} will throw terraform plan error
“var.key” within {} wont error, but value for var.key wont get replaced.
(var.key) within {} worked well.

Oh, I see.

It is not normal to have to use parentheses when dealing with an ‘interpolation-only expressions’ warning - however this is a special case because it is specifically in the context of an object key.

1 Like

Indeed… this is a special exception in the language grammar because the most common situation is to write literal object attribute names, whereas a dynamic attribute name based on a reference to something else is less common.

For that reason, in this situation Terraform will treat an identifier there as a literal attribute name be default, but allows using other expression types as long as it isn’t ambiguous whether a literal name or reference was intended. Adding parentheses is one way to remove the ambiguity without changing the meaning of the expression, and so IIRC the error message for this situation recommends using parenthesis as shown above.