nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • A
    5% (2)
  • B
    2% (1)
  • C
    7% (3)
  • D
    85% (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.

AIssue in main.tf file

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.

BIssue in vars.tf file

The vars.tf file declares variable blocks with optional defaults; any value originating there is explicitly defined in the code files.

CIssue in terraform.tfvars

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.

DIssue in Environment VariablesCorrect

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

#Terraform variables#Variable precedence#Environment variables#Configuration input

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice