Hashicorp Certified Terraform Associate 003 · Free Practice Question Easy
Question 2
Which of the following is a valid variable name in Terraform?
-
A
count -
B
lifecycle -
C
version -
D
invalid
Reveal correct answer
Correct answer: D
Explanation
In Terraform, variable names must follow a set of naming conventions to be considered valid. Here are some examples of invalid variable names:
Names that start with a number:
1_invalid_variable_nameNames that contain spaces or special characters (other than underscores):
invalid variable nameNames that contain only numbers:
12345Names that are the same as Terraform reserved words, such as
source,version,providers,count,for_each,lifecycle,depends_on,locals.
It is recommended to use only lowercase letters, numbers, and underscores in variable names and to start variable names with a lowercase letter to ensure they are valid. Additionally, variable names should be descriptive and meaningful to help make your Terraform code more readable and maintainable.
https://developer.hashicorp.com/terraform/tutorials/configuration-language/count
https://developer.hashicorp.com/terraform/language/values/variables#declaring-an-input-variable
A. "count" is not a valid variable name in Terraform as it is a reserved keyword used for resource iteration and cannot be used as a variable name.
B. "lifecycle" is not a valid variable name in Terraform as it is a reserved keyword used for defining resource lifecycle configuration and cannot be used as a variable name.
C.
"version" is not a valid variable name in Terraform as it is a reserved keyword
D. This is a valid variable name in Terraform as it follows the naming conventions for variables, which allow alphanumeric characters and underscores, and must start with a letter or underscore.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
