nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • A
    7% (3)
  • B
    2% (1)
  • C
    89% (41)
  • D
    2% (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.

Avariable.instance_id

`variable.instance_id` is not valid Terraform syntax; the correct namespace prefix for input variables is `var`, not `variable`.

Bvar.instance_ids

`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`.

Cvar.instance_idCorrect

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.

DNone of the above

`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

#Terraform 0.12#HCL Syntax#Variables#Interpolation

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice