variable
What is variable?
variable: A typed input to a configuration or module. Set via -var, *.tfvars files, env vars (TF_VAR_*), or defaults. A variable in Terraform is a typed input to a configuration or module, such as the number of servers or the environment name. You declare it with a type, a description and optionally a default.
Frequently asked questions about variable
How is variable used in practice?
Values come from .tfvars files, -var options on the command line, environment variables named TF_VAR_name, or the default. This lets the same code create different environments with different settings.
What should you keep in mind with variable?
Add descriptions and types to every variable, so the module documents itself. Use validation blocks to reject impossible values early, such as an unknown region. Mark secrets with sensitive = true, so Terraform hides them in output, and pass them through environment variables or a secret manager rather than committing them in a .tfvars file.
What does an example of variable look like?
variable "instance_count" { type = number default = 2 } At a glance
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |