NoobProg
NoobProg

Reputation: 91

how to concatenate a variable and a string in terraform?

I'm new to terraform and trying to add a variable to a string, Suppose, id = "abcde", host =~ ${id} + "id", should return abcdeid what's the best way to achieve this in terraform?

Upvotes: 1

Views: 12244

Answers (2)

Scott Heath
Scott Heath

Reputation: 890

Assuming a var called name and a suffix of -123

Host = “${var.name}-123”

Upvotes: 5

Marcin
Marcin

Reputation: 238877

You can concatenate them directly or using join. For example:

variable "id" {
  default = "abcde"
}

output "output1" {
  value = "${var.id}id"
}

output "output2" {
  value = join("", [var.id, "id"])
}

which will give:

output1 = abcdeid
output2 = abcdeid

Upvotes: 5

Related Questions