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.
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)- A4% (1)
- B8% (2)
- D88% (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.
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.
`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.
`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.
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
Community Discussion
No community discussion yet for this question.