-var
The plan and apply option that sets one input variable on the command line, as in -var="environment=prod".
In more detail
Command-line values beat every other source. It is handy for a one-off experiment, but a long command line is not version-controlled, so real projects use .tfvars files.
Example
terraform plan -var="environment=prod"Related terms
- input variable — A named, typed value a configuration or module takes from outside, declared in a variable block and read as var.<name>.
- Terraform variable precedence — The fixed order Terraform uses to decide which value wins when a variable is set in more than one place.
- variable definitions file — A .tfvars file of name = value lines that supplies values for input variables.
Taught in
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Reading A Plan, Saving It, Applying It — HashiCorp Terraform Associate (004) Exam Prep
- Input Variables, Outputs, And Which Value Wins — HashiCorp Terraform Associate (004) Exam Prep
- Complex Types: Lists, Sets, Maps, Objects And Tuples — HashiCorp Terraform Associate (004) Exam Prep
- Expressions And Functions: Making Configuration Compute — HashiCorp Terraform Associate (004) Exam Prep
- Count, For Each And Dynamic Blocks — HashiCorp Terraform Associate (004) Exam Prep
- Dependencies, depends_on And Lifecycle Rules — HashiCorp Terraform Associate (004) Exam Prep
- Custom Conditions: Validation, Pre And Postconditions, Checks — HashiCorp Terraform Associate (004) Exam Prep