TA-002-P · Question #396
Terraform is currently being used by your organisation to create resources on AWS for the development of a web application. One of your coworkers wants to change the instance type to "t2.large" while
The correct answer is D. Modify the terraform.tfvars with the instance type and issue terraform plan and then terraform. To override a specific variable such as instance type without altering other default values, the teammate should update terraform.tfvars with the new value and then run terraform plan followed by terraform apply.
Question
Terraform is currently being used by your organisation to create resources on AWS for the development of a web application. One of your coworkers wants to change the instance type to "t2.large" while keeping the default set values. What adjustments does the teammate make in order to meet his goal?
Options
- AIssue Terraform plan instance.type".t2.large" and it deploys the instance
- BModify the tf.variableswith the instance type and issue terraform apply
- CCreate a new file my.tfvars and add the type of the instance and issue terraform plan and apply
- DModify the terraform.tfvars with the instance type and issue terraform plan and then terraform
How the community answered
(24 responses)- A4% (1)
- B8% (2)
- D88% (21)
Why each option
To override a specific variable such as instance type without altering other default values, the teammate should update terraform.tfvars with the new value and then run terraform plan followed by terraform apply.
'terraform plan instance.type="t2.large"' is not valid Terraform CLI syntax and would not successfully pass a variable value to the configuration.
Modifying the variable declaration files changes the default values in the source code itself rather than overriding them externally, which is not the correct pattern for environment-specific or user-specific overrides.
Creating a custom my.tfvars file would only work if explicitly passed with the -var-file flag; without it, Terraform does not auto-load non-standard .tfvars filenames - only terraform.tfvars and *.auto.tfvars are loaded automatically.
The terraform.tfvars file is automatically loaded by Terraform and is the standard place to supply variable values that override declared defaults without modifying the variable declaration files themselves. By adding or updating only the instance_type entry in terraform.tfvars, the teammate changes that one value while all other variables retain their defaults, then runs plan and apply to execute the change safely.
Concept tested: Overriding Terraform variable defaults with terraform.tfvars
Source: https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files
Topics
Community Discussion
No community discussion yet for this question.