Ad space (banner)
AD

Got the fundamentals? A structured Terraform course is a fast way to level up.

Find Terraform courses on Udemy

Affiliate link. Costs you nothing extra.

Lesson 16 / 37

What Are Variables?

Variables let one configuration serve several situations, instead of hard-coding values throughout.

You declare them with variable "name" {} and reference them as var.name. Values come from a .tfvars file, the command line, or environment variables.

Making the instance type a variable means development can use a small type and production a large one, from exactly the same configuration.

A common stumble is putting secrets in a .tfvars file and committing it. Mark sensitive variables as such, and keep their values out of the repository.

In real work, variables are what allow one module to be reused across environments, which is the main reason modules are worth writing.

Terraform
Try it (type this into the pseudo terminal)
terraform plan

🧑‍💻 You can type this command into the Terraform pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)