Terraform Variables: Input and Output

Learn about Terraform’s input and output variables as well as how to work with arguments.

Input variables

In programming, we can use variables to store values and customize our application. The same applies to Terraform as we can use input variables to hold values for our arguments. Using input variables allows us to use the same configuration file for different environments by simply tweaking the variables as we need. The different input variable types that Terraform provides include the following:

  • string: This is used for specifying text values, e.g., "name".
  • bool: This is used for specifying boolean values, e.g., true or false.
  • number: This is used for specifying number values, e.g., a port number of 8080.
  • list: This is used to list a range of values, e.g., ["t2.micro", "t2.nano", "t2.small"].
  • map: This is used to list a range of values in a key-pair format. An example of using a map variable to show a list of instances is shown below:

Get hands-on with 1200+ tech skills courses.