Type Constraints - Simple Types
Understand how to apply simple type constraints to Terraform variables, including string, number, and bool types. Learn how these constraints help ensure variable values are valid, improve code readability, and guide correct usage within your Terraform projects.
We'll cover the following...
So far, we have been setting variables and not specified the type. This means that whatever type you pass to a variable will be the type that the variable assumes. A type constraint allows you to be specific about the type of a variable. There are three simple types:
- string
- number
- bool
Project example
To specify a type constraint, use the type property when defining a variable. Let’s see an example of using the three simple types:
In this project, we are defining three variables a, b, and c. We are using the type parameter to define:
aas a string,bas a bool, andcas a number.
We are using defaults to set ...