user6248151
user6248151

Reputation:

Terraform 12 var and string concatenation best practice

I'm updating from terraform 0.11 to 0.12 and I was wondering what was the "best practice" to concatenate string and vars in my .tf files.

The new syntax is pretty straightforward reguarding the variables :

# V0.11
foo = "${var.bar}"

# V0.12
foo = var.bar

but how should-I handle this situation ?

foo = "${var.bar}-a-string"

Shall-I keep this syntax or turn it in something like :

foo = join("-", [${var.bar}, "a", "string"])

This guy seems to think we should keep interpolation syntax for string concatenation even if it's deprecated in the new terraform version.

Upvotes: 1

Views: 3705

Answers (1)

Vaibhav Khalane
Vaibhav Khalane

Reputation: 121

To concatenate variable with the string, use this syntax instead of join() :

foo = "string-${var.bar}-a-string"

But if you don't want to use a variable for string concatenation, you can use such syntax:

foo = var.bar

Upvotes: 1

Related Questions