Input Variables (Variables)
Explore how to define and manage input variables in Terraform configurations for Azure. Understand different ways to assign variable values, including blocks, shorthand syntax, runtime arguments, and variable definition files, to create flexible and maintainable infrastructure code.
Variables in Terraform are like in any other programming or scripting language; they hold values. Variables can hold many different types of information to call on later in a configuration file.
Variable definition syntax
Variables are handy HCL constructs that can be defined in a few different ways and in a few different places.
Blocks
Variables can be defined in a block with various arguments in the form:
variable "<variable name>" {
type = <type> ## string, number or bool
<default = <value>>
<description = "">
}
You can find more information about each type of argument assigned to a variable in the Input Variables Terraform documentation.
Let’s say you’re creating a configuration to provision an Azure VM from scratch. Inside of that configuration, you are referencing the VM name in various places. To ensure you only have a single place to change, if that VM name should change, you’ve decided to ...