nerdexam
HashiCorp

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.

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"

How the community answered

(13 responses)
  • B
    8% (1)
  • C
    92% (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.

Aterraform apply -var-state-file ="testing.tfvars"

`-var-state-file` is not a valid Terraform CLI option for specifying a variable definition file.

Bterraform plan -var-file="testing.tfvar"

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`.

Cterraform apply -var-file="testing.tfvars"Correct

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.

Dterraform apply var-file="testing.tfvars"

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

#Terraform CLI#Variables#terraform apply#tfvars files

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice