input variable
A named, typed value a configuration or module takes from outside, declared in a variable block and read as var.<name>.
In more detail
A good declaration has a description, a type, a validation rule where useful and, if safe, a default. Values can come from defaults, TF_VAR_ environment variables, .tfvars files and the -var and -var-file options, with a fixed order of precedence. If no value and no default exist, Terraform prompts, or fails when input is turned off.
Examples
variable "environment" {
description = "Name of the environment this configuration builds."
type = string
}filename = "${var.environment}.json"Related terms
- type constraint — The type argument of a variable, such as string, number, bool, list(string), map(string) or object({...}), which rejects values of the wrong shape.
- validation block — A block inside a variable that states a condition the value must meet and the error message to show when it does not.
- variable definitions file — A .tfvars file of name = value lines that supplies values for input variables.
- Terraform variable precedence — The fixed order Terraform uses to decide which value wins when a variable is set in more than one place.
- local value — A name for an expression inside a configuration, declared in a locals block and read as local.<name>, which nobody outside can set.
Taught in
- Writing Your First Configuration In HCL — Infrastructure as Code with Terraform
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Functions And Expressions In HCL — Infrastructure as Code with Terraform
- Writing A Custom Network Module — Infrastructure as Code with Terraform
- Calling Your Module And Passing Variables — Infrastructure as Code with Terraform
- Scaling Resources With Count — Infrastructure as Code with Terraform
- The Problem With Local State — Infrastructure as Code with Terraform
- One Hour, No Weights Published — HashiCorp Terraform Associate (004) Exam Prep
- Providers: How Terraform Reaches Every API — HashiCorp Terraform Associate (004) Exam Prep
- 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
- Validate, Format, Destroy, And The Flags That Bend A Plan — HashiCorp Terraform Associate (004) Exam Prep
- Resources, Data Sources And The References Between Them — 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