nerdexam
HashiCorp

TA-002-P · Question #89

Which of the following is allowed as a Terraform variable name?

The correct answer is B. name. Terraform reserves certain identifiers like 'count', 'source', and 'version' for special use; only 'name' is a valid user-defined variable name.

Understand Terraform basics

Question

Which of the following is allowed as a Terraform variable name?

Options

  • Acount
  • Bname
  • Csource
  • Dversion

How the community answered

(29 responses)
  • B
    93% (27)
  • C
    3% (1)
  • D
    3% (1)

Why each option

Terraform reserves certain identifiers like 'count', 'source', and 'version' for special use; only 'name' is a valid user-defined variable name.

Acount

'count' is a reserved meta-argument used to create multiple resource instances and cannot be used as a user-defined variable name.

BnameCorrect

The identifier 'name' is not on Terraform's reserved list and can be freely used as an input variable name. Terraform explicitly prohibits 'count', 'source', and 'version' as variable names because they serve as meta-arguments or module configuration keywords. Any identifier not reserved by the language specification is a valid choice for a variable name.

Csource

'source' is a reserved argument in module blocks that specifies the module's source location and is not allowed as a variable name.

Dversion

'version' is a reserved argument in module and provider blocks for version constraints and cannot be used as a variable name.

Concept tested: Terraform reserved variable name restrictions

Source: https://developer.hashicorp.com/terraform/language/values/variables#declaring-an-input-variable

Topics

#Terraform variables#Naming conventions#Reserved keywords

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice