nerdexam
HashiCorp

TA-002-P · Question #148

What is the command you can use to set an environment variable named "var1"of type String?

The correct answer is D. export TF_VAR_var1. To set a Terraform variable named 'var1' via an environment variable, you must prefix the variable name with TF_VAR_ and use the export command.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

What is the command you can use to set an environment variable named "var1"of type String?

Options

  • Aexport TF_VAR_VAR1
  • Bset TF_VAR_var1
  • Cvariable "var1" { type = "string"}
  • Dexport TF_VAR_var1

How the community answered

(25 responses)
  • A
    4% (1)
  • B
    8% (2)
  • D
    88% (22)

Why each option

To set a Terraform variable named 'var1' via an environment variable, you must prefix the variable name with `TF_VAR_` and use the `export` command.

Aexport TF_VAR_VAR1

Using `TF_VAR_VAR1` (uppercase `VAR1`) would set a Terraform variable named `VAR1`, not `var1`, as Terraform environment variable names are case-sensitive to the declared variable.

Bset TF_VAR_var1

`set` is used in some shells but `export` is the standard for making environment variables available to child processes in a Unix-like environment; also, no value is specified.

Cvariable "var1" { type = "string"}

`variable "var1" { type = "string"}` is Terraform HCL syntax for *declaring* a variable within a `.tf` file, not a shell command to *set* an environment variable.

Dexport TF_VAR_var1Correct

To set a Terraform variable named `var1` using an environment variable in a Unix-like shell, the environment variable must be named `TF_VAR_var1`. The `export` command makes this variable available to child processes like Terraform.

Concept tested: Setting Terraform variables via environment variables

Source: https://developer.hashicorp.com/terraform/language/values/variables#environment-variables

Topics

#Environment variables#Terraform variables#CLI usage

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice