TA-002-P · Question #392
Suppose terraformcode is taking up some values which are not defined inside the code files. In which of the following options issue might have occurred?
The correct answer is D. Issue in Environment Variables. When Terraform consumes values not defined in any configuration file, those values are being supplied through environment variables prefixed with TF_VAR_, which Terraform reads automatically from the shell environment.
Question
Suppose terraformcode is taking up some values which are not defined inside the code files. In which of the following options issue might have occurred?
Options
- AIssue in main.tf file
- BIssue in vars.tf file
- CIssue in terraform.tfvars
- DIssue in Environment Variables
How the community answered
(41 responses)- A5% (2)
- B2% (1)
- C7% (3)
- D85% (35)
Why each option
When Terraform consumes values not defined in any configuration file, those values are being supplied through environment variables prefixed with TF_VAR_, which Terraform reads automatically from the shell environment.
The main.tf file contains resource definitions and provider configuration; any value originating there is visible in the code and would not cause unexplained external values.
The vars.tf file declares variable blocks with optional defaults; any value originating there is explicitly defined in the code files.
The terraform.tfvars file is a standard variable definitions file that Terraform automatically loads, so values from it are fully traceable within the project directory.
Terraform supports reading variable values from environment variables named TF_VAR_ followed by the variable name, meaning a value can influence the configuration without appearing in any .tf or .tfvars file. If unexpected values are being consumed, the issue is likely an unintended or incorrect TF_VAR_* environment variable set in the shell or CI/CD environment.
Concept tested: Terraform TF_VAR environment variable input mechanism
Source: https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_var_name
Topics
Community Discussion
No community discussion yet for this question.