How to Use the Terraform Join Function

For Terraform 0.12 and later, you can use the join() function, to allow you to join or concatenate strings in your Terraform plans. The terraform join function has two inputs, the separator character and a list of strings we wish to join together.

join(separator, list)

Let’s take a look at an example of how to use the join function in a terraform plan.

# Define a List in a variable
variable "example-list" {
  default = ["one","two","three"]
}

# Returns "one-two-three"
output "join-example" {
  value = "${join("-",var.example-list)}"
}

Here we have defined a variable called example-list which contains a list of strings. In the next block we are creating an output resource which uses the join function to join the strings in the list together. The resultant value which is outputted is:

one-two-three

Now, another example, this time without using a variable:

# Returns www.buildvirtual.net
join(".",list("www","buildvirtual","net")

A short article, but hopefully one that demonstrates how you can use the join function in Terraform to concatenate multiple strings from a defined list.

Related posts

Mastering the Linux ifconfig Command

Docker Exec Command With Practical Examples

Debugging with Git Bisect

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More