interpolation
What is interpolation?
interpolation: Embedding an expression inside a string with ${...}. In HCL2 you rarely need it for whole values — bare references work. Interpolation embeds an expression in a string, using ${...} in Terraform. name = "web-${var.env}" produces web-production when the environment is production. In older Terraform versions you needed interpolation syntax for every reference. Since Terraform 0.12, you can use references directly, so instance_type = var.size is the clean form and "${var.size}" is unnecessary.
Frequently asked questions about interpolation
What should you keep in mind with interpolation?
Keep interpolation for building strings from several parts, such as resource names and tags. Use a consistent naming pattern across all resources, such as project, environment and role, so you can recognise them in the cloud console and on invoices. For more complex string building, format() and join() are often clearer than long interpolated strings.
What does an example of interpolation look like?
name = "web-${var.env}-${count.index}" At a glance
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |