Use of Structural Types

Learn the use of structural types in Terraform.

The structural types allow us to create a more complex object, where the values can be of multiple types. This is distinctly different from collection types, where each value in the collection must be of the same type.

Types of structural types

There are two structural types.

The object type

Similar in nature to a map, the object is a set of key/value pairs, but each value can be of a different type.

The tuple type

Similar in nature to a list, the tuple is an indexed set of values, where each value can be of a different type.

When to use structural types

Maps can be converted into objects with little issue, but the reverse isn’t always true. The same goes for tuples and lists. When we’re deciding which one to use, we ask ourselves if we need multiple types defined within the variable. If we do, we go with structural types. Here are some examples of object and tuple.

Get hands-on with 1200+ tech skills courses.