Variables: what the file leaves open
The first configuration had the subscription and the region written into it. Some values are not the configuration's to fix: your subscription, your region, your password, your SSH key, your home address for the bastion rule. And one name: the database server's, which on Azure becomes a hostname on the internet and must be unique worldwide. A variable is a value the file leaves open:
variable "location" { type = string } # no default: must be given
variable "vm_size" { type = string, default = "Standard_B2ats_v2" }
variable "db_password" { type = string, sensitive = true }
Used as var.location, anywhere a value can stand: location = var.location.
- Types are checked before anything runs: a bool where a string is expected stops the plan
- Default makes a variable optional; no default makes Terraform ask, or fail in a script
- sensitive hides the value from plan output and the terminal. It is still in the state, in plain text
The same files build every student's setup. What differs is in the variables, never in the files.