简体   繁体   中英

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?

You can concatenate them directly or usingjoin . 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

Assuming a var called name and a suffix of -123

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM