Variables
Variable types
string
number
bool (true/false)
list(datatype)
map(datatype)
set(datatype)
Input Variables
Terraform variables allow you to write configuration that is flexible and easier to re-use.
Example to declare a variable in variables file say
variables.tf
:
Note: Terraform loads all files in the current directory ending in .tf, so you can name your configuration files however you choose.
To override the default value of a variable use
-var
flag.
Setting variables via the command-line will not save their values. Terraform supports many ways to use and set variables so you can avoid having to enter them repeatedly as you execute commands.
If you do not set a default value for a variable, you must assign a value before Terraform can apply the configuration. Terraform does not support unassigned variables.
You can also store variable values in a file
terraform.tfvars
which is the default file that terrafom looks for when applying configuration, or explicit file location can also be passed using-var-file file_name.tfvars
.To learn more, follow here.
Output Variables
Create a file called
outputs.tf
in your terraform directory (i.e in the directory in which your terraform file resides).
Last updated