HashiCorpHashiCorp
TA-002-P · Question #132
TA-002-P Question #132: Real Exam Question with Answer & Explanation
The correct answer is C: terraform apply -var-file="testing.tfvars". To apply variable values from a custom .tfvars file, you must specify the file using the -var-file flag with the terraform apply command.
Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)
Question
You have created a custom variable definition file testing.tfvars. How will you use it for provisioning infrastructure?
Options
- Aterraform apply -var-state-file ="testing.tfvars"
- Bterraform plan -var-file="testing.tfvar"
- Cterraform apply -var-file="testing.tfvars"
- Dterraform apply var-file="testing.tfvars"
Explanation
To apply variable values from a custom .tfvars file, you must specify the file using the -var-file flag with the terraform apply command.
Common mistakes.
- A.
-var-state-fileis not a valid Terraform CLI option for specifying a variable definition file. - B. The command
terraform planis for creating an execution plan, not applying infrastructure, and the file extensiontfvaris a typo; it should betfvars. - D. This command is syntactically incorrect as it's missing the hyphen before
var-file, which is required for CLI flags.
Concept tested. Passing variables using .tfvars files
Reference. https://developer.hashicorp.com/terraform/cli/commands/apply#var-file-path
Topics
#Terraform CLI#Variables#terraform apply#tfvars files
Community Discussion
No community discussion yet for this question.