TA-002-P · Question #210
Which of the below options is the equivalent Terraform 0.12 version of the snippet which is written in Terraform 0.11? "${var.instance_id}"
The correct answer is C. var.instance_id. Terraform 0.12 introduced first-class expressions, allowing direct variable references like var.instance_id without the string interpolation syntax required in 0.11.
Question
Which of the below options is the equivalent Terraform 0.12 version of the snippet which is written in Terraform 0.11? "${var.instance_id}"
Options
- Avariable.instance_id
- Bvar.instance_ids
- Cvar.instance_id
- DNone of the above
How the community answered
(46 responses)- A7% (3)
- B2% (1)
- C89% (41)
- D2% (1)
Why each option
Terraform 0.12 introduced first-class expressions, allowing direct variable references like `var.instance_id` without the string interpolation syntax required in 0.11.
`variable.instance_id` is not valid Terraform syntax; the correct namespace prefix for input variables is `var`, not `variable`.
`var.instance_ids` references a different variable name (`instance_ids` with an `s`), which would cause a reference error if the variable is named `instance_id`.
In Terraform 0.11, variables in string contexts required the `"${var.instance_id}"` interpolation syntax. Terraform 0.12 added native expression support, so `var.instance_id` can be used directly as a value without wrapping it in a quoted template string, which is cleaner and less error-prone.
`var.instance_id` is valid Terraform 0.12 syntax, so 'None of the above' is incorrect.
Concept tested: Terraform 0.12 native expression syntax for variables
Source: https://developer.hashicorp.com/terraform/language/expressions/references#input-variables
Topics
Community Discussion
No community discussion yet for this question.