nerdexam
HashiCorp

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"…

Read, generate, and modify configuration

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)
  • A
    2% (1)
  • B
    90% (37)
  • C
    5% (2)
  • D
    2% (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

#Terraform variables#Type coercion#String type#HCL data types

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice