Variable Definitions Flashcards

1
Q

If there is no values in the terraform.tfvars file for a variable and there is a value in a separate variables file , what will be the value of the variable?

A

The value in the separate file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If there are values in both terraform.tfvars file for a variable and a separate variables file , what will be the value of the variable?

A

The value in the TFVARS file takes precedence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If the file, “terraform.tfvars” is missing from the working directory how do you specify in the CLI which variable file to use?

A

terraform plan -var-file=
“filename.tfvar”

Ex:
terraform plan -var-file=”prod.tfvars”

terraform plan -var-file=”dev.tfvars”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens if you declare a variable but don’t give it a value?

A

Terraform will ask to input the value in the CLI prompt when you run terraform plan / apply.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you declare a value for a variable directly at the CLI when running terraform apply / plan

A

terraform plan -var=”variable name=value”

Ex:
terraform plan -var=”instance_type=m5.large”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you add an environment variable in Linux?

A

export TF_VAR_variablename=value

Ex: export TF_VAR_instance_type=m5.large

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you check the value of an Environment variable?

A

echo $TF_VAR_variablename

Ex:
echo $TF_VAR_instance_type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What will terraform choose if there is a variable value stored in a terraform.tfvars file, a value stored in an environment variable, or a default value stored in a separate .tf file?

A

Terraform always takes precedence from the environment variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the order that Terraform loads variables?

A

Terraform loads variables in the following order, with later sources taking precedence over earlier ones

  1. Environment first
  2. Terraform.tfvars, if present
  3. Terraform.tfvars.json, if present

4.Any *.auto.tfvars or *.auto.tfvars.json files, processed in lexican order of their filename

  1. Any -var and -var-file options on the command line.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly