====== Providing Values for Variables ======
Values for variables can be provided in several ways:
===== Command-line Flags =====
Use the -var option with terraform apply or terraform plan.
terraform apply -var="instance_type=t2.large"
===== Variable Definition Files =====
Define variables in a .tfvars file or .tfvars.json file.
// variables.tfvars
instance_type = "t2.large"
availability_zones = ["us-west-2a", "us-west-2b"]
// variables.tfvars.json
{
"instance_type": "t2.large",
"availability_zones": ["us-west-2a", "us-west-2b"]
}
Apply these with the -var-file flag:
terraform apply -var-file="variables.tfvars"
===== Environment Variables =====
Prefix the variable name with TF_VAR_ and set it as an environment variable.
export TF_VAR_instance_type="t2.large"
terraform apply