format()
The function that builds a string from a template with placeholders such as %s for text and %02d for a zero-padded number.
In more detail
It is the tidy way to produce stable, predictable names from a prefix and a counter. The template decides the layout, so every name comes out the same shape.
Example
format("%s-%02d", "orders", 1) # "orders-01"Related terms
- built-in function — One of Terraform's fixed set of functions, such as lower(), join() or jsonencode(), that transform values inside expressions.
- string interpolation — Building a string from a template whose placeholders hold expressions, which are evaluated and inserted as text.
Taught in
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Functions And Expressions In HCL — Infrastructure as Code with Terraform