string interpolation
Building a string from a template whose placeholders hold expressions, which are evaluated and inserted as text.
In more detail
It is clearer than joining pieces with plus signs. The syntax varies: C# writes $"sku is {code}", while Terraform and JavaScript template literals use ${expression}. In Terraform, an interpolation that refers to a resource also creates a dependency on it.
Examples
Console.WriteLine($"Target framework: {target}");greet = "hello ${var.name}"Related terms
- string — The type for text values, such as a name or an email address.
- raw string literal — A C# string opened and closed by three or more double quotes, in which inner quotes and backslashes need no escaping.
- Terraform expression — Anything that produces a value on the right of an equals sign: a literal, a reference, a function call, a for expression or a conditional.
- resource reference — An expression such as aws_vpc.main.id that reads a value from another block by its address.
- here document — A way to write several lines of text straight into a script or file, opened with << and a marker word such as EOF and closed by that word on its own line.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Writing Your First Configuration In HCL — Infrastructure as Code with Terraform
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Expressions And Functions: Making Configuration Compute — HashiCorp Terraform Associate (004) Exam Prep