String interpolation

String interpolation

String interpolation is the concept of baking other objects (e.g. local values and variables) into a string.

In the following example there is a variable representing a name, and a local value representing the current date. Both the variable and the local value are used to construct an output string using string interpolation:

main.tf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
variable "name" {
  description = "Name of a person"
  default     = "Jane Doe"
  type        = string
}

locals {
  now = formatdate("YYYY-MM-DD", timestamp())
}

output "string_interpolation" {
  value = "On ${local.now}, ${var.name} said 'Hello!'"
}