TA-002-P · Question #132
You have created a custom variable definition file testing.tfvars. How will you use it for provisioning infrastructure?
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.
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"
How the community answered
(13 responses)- B8% (1)
- C92% (12)
Why each option
To apply variable values from a custom `.tfvars` file, you must specify the file using the `-var-file` flag with the `terraform apply` command.
`-var-state-file` is not a valid Terraform CLI option for specifying a variable definition file.
The command `terraform plan` is for creating an execution plan, not applying infrastructure, and the file extension `tfvar` is a typo; it should be `tfvars`.
The correct command to use a custom variable definition file like `testing.tfvars` for provisioning infrastructure is `terraform apply -var-file="testing.tfvars"`. The `-var-file` flag instructs Terraform to load variable values from the specified file.
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
Source: https://developer.hashicorp.com/terraform/cli/commands/apply#var-file-path
Topics
Community Discussion
No community discussion yet for this question.