TA-002-P · Question #173
Which of the following value will be accepted for var1? variable "var1" { type = string }
The correct answer is B. Both A and B. Both "5" (a string literal) and 5 (a number literal) will be accepted for a variable declared with type = string. Terraform performs automatic type conversion (type coercion) when assigning values to variables. A number like 5 will be automatically converted to the string "5"…
Question
Which of the following value will be accepted for var1? variable "var1" { type = string }
Options
- ANone of the above
- BBoth A and B
- C"5"
- D5
How the community answered
(41 responses)- A2% (1)
- B90% (37)
- C5% (2)
- D2% (1)
Explanation
Both "5" (a string literal) and 5 (a number literal) will be accepted for a variable declared with type = string. Terraform performs automatic type conversion (type coercion) when assigning values to variables. A number like 5 will be automatically converted to the string "5" to satisfy the string type constraint. This means both choices C and D are valid, making the correct answer B ('Both A and B', referring to both "5" and 5 in the original choice labeling).
Topics
Community Discussion
No community discussion yet for this question.