TERRAFORM-ASSOCIATE-003 practice question 2 of 30

[Navigate Terraform State and Backends] Terraform variable names are saved in the state file.

Full set: 226 questions
Answer options
A: True
B: False
Correct Answer:
FALSE
Explanation

The Terraform state file does not store the names of the input variables defined in your configuration (.tf files). Instead, it stores the values that are assigned to resource attributes, which may have originated from variables. The state file's primary purpose is to map the configured resources to real-world objects and to cache the attribute values of those resources. The configuration logic, including variable names, resides solely in the .tf configuration files.

Why Incorrect

The statement is False. The state file is a record of the state of your infrastructure, not a copy of the code used to create it. For example, if you have a variable var.instancesize with a value of "t2.micro" and use it to set an EC2 instance's instancetype, the state file will record "instancetype": "t2.micro", but it will not contain any reference to the variable name instancesize.

References

1. HashiCorp Developer Documentation

"Purpose of Terraform State": This document explains that the state file is used for "Mapping to Real World"

"Metadata"

and "Performance". It emphasizes that the state stores "attribute values for all resources

" which are the resolved values

not the variable names from the configuration. The document makes no mention of storing variable names.

Source: HashiCorp

"Purpose of Terraform State"

https://developer.hashicorp.com/terraform/language/state/purpose

2. HashiCorp Developer Documentation

"State File Format": This technical reference details the JSON structure of the state file. The schema includes objects for resources and their instances

which contain an attributes map. This map holds the key-value pairs of the resource's arguments and their final

computed values. The schema does not include any fields for storing the names of the input variables used to derive these values.

Source: HashiCorp

"State File Format"

https://developer.hashicorp.com/terraform/language/state/format

Scroll to Top