Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate variables in terraform V0.12

Tags:

terraform

I'm trying to update my terraform files from V0.11 to V0.12 and I have some questions.

What's the best way to concatenate variables with strings?

In V0.11 I use this: ${var.name}-STRING-${var.name2}, in V0.12 can I use this: var.name"-STRING-"var.name2 or must I use another ways to concatenate variables and strings?

like image 956
Eduardo Gimenez Avatar asked Oct 25 '25 11:10

Eduardo Gimenez


2 Answers

In v0.12 for interpolations like this:

"${var.example}"

You should use now:

var.example

In your example, In v0.12 you should keep using the previous syntax from v0.11:

"${var.name}-STRING-${var.name2}"

There is a great section in Terraform documentation about migrating to v0.12

like image 170
pabloxio Avatar answered Oct 27 '25 02:10

pabloxio


To concatenate, check few example below:

If you want to add '@' to string:

value = "${var.username}@${aws_instance.my-instance.public_dns}"

Output: [email protected]

To create link:

value = "http://${aws_instance.my-instance.public_dns}:90"

Output: http://ec2-184-72-11-141.us-west-1.compute.amazonaws.com:90

like image 43
Ashish Avatar answered Oct 27 '25 02:10

Ashish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!