Understanding variables
If you've ever used any programming language, then you might be familiar with variables already. In most common case, they allow you to assign a value (a number or string or something else) to some hand-picked name and reference this value by this name inside your code. If you need to modify the value, then you just need to do it once, in a place where variable is defined.
Unlike in programming languages, variables in Terraform are more like input data for your templates: you define them before using the template. During the Terraform run, you have zero control over variables. The values of variables never change; you can't modify them inside the template.
In the previous chapter, we already tried variables in order to configure modules. We also learned that our template.tf
is a module: root module. Let's define some variables for the root module.
It is a common pattern to split variables, template, and outputs into three different files. As you...