Search⌘ K
AI Features

Data Types: Collection Types

Explore Terraform's collection data types such as lists, sets, and maps within the HashiCorp Configuration Language. Understand how each type handles values, ordering, and duplicates. This lesson helps you grasp type conversions and variable declarations to improve your Terraform configurations and debugging skills.

Underpinning Terraform is a configuration language called HCL, which stands for HashiCorp Configuration Language. As the name suggests, it’s a language designed for configuration created by HashiCorp, the same company that created Terraform itself.

Like other configuration languages, HCL is declarative. HCL also shares some characteristics with more robust programming languages, and in this lesson, we’ll look at Terraform’s data types.

This lesson is somewhat limited to only covering data types in HCL. Most of this you could probably figure out yourself as you continue to learn Terraform if you’re already proficient in other languages. However, you can return to this lesson whenever you feel like it as a place for revision.

It’s also helpful to have a proper grounding in data types if we start using Terraform’s looping capabilities, which we look at later in the course. Finally, understanding data types in HCL is also frequently useful when debugging Terraform scripts.

Simple data types

First, we create a folder named ltthw_data_types with a vars.tf file to store some examples of the basic data types available in Terraform. Then we create some output values to match in output.tf like so:

output a_number_output { 
value = var.a_number 
} 
output a_string_output { 
value = var.a_string 
} 
output a_boolean_output { 
value = var.a_boolean 
}
Simple data type

We’ll get a prompt for an input for each of the module’s ...