How do we define a name with Concat taken from multiple variable

Hi All,

Anybody can help me out to define a name on any.tf file with concat from multiple variable, for example we would like to use name, environment, domain which is already define on the variables.tf file

Thank you for your help.

Regards,

RH

What you’re looking for is called string interpolation:

bent@DESKTOP-KEO4V17:/tmp/concatvars$ cat variables.tf main.tf
variable "name" {
  default = "server"
}
variable "environment" {
  default = "test"
}
variable "domain" {
  default = "acme.com"
}

output "fqdn" {
  value = "${var.environment}-${var.name}.${var.domain}"
}

bent@DESKTOP-KEO4V17:/tmp/concatvars$ terraform apply

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

fqdn = test-server.acme.com
bent@DESKTOP-KEO4V17:/tmp/concatvars$
1 Like

Hi Bent, thank a lot for your help, is it working well, great job and many thanks

1 Like