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.
Question
Which of the following is allowed as a Terraform variable name?
Options
- Acount
- Bname
- Csource
- Dversion
How the community answered
(29 responses)- B93% (27)
- C3% (1)
- D3% (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.
'count' is a reserved meta-argument used to create multiple resource instances and cannot be used as a user-defined variable name.
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.
'source' is a reserved argument in module blocks that specifies the module's source location and is not allowed as a variable name.
'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
Community Discussion
No community discussion yet for this question.