Data Types in Terraform
Each variable in Terraform will have a value and that value will be of specific type. That type specifies exactly the kind of data a variable can store and these types are as listed below and are categorized into
- Primitive types - number, string, bool
- Complex/Structural/Collection types - list, tuple, set, map, object
- There is one special value that has no type - null, which represents an absence or omission
Below are the list of types
- number - a numeric value which can represent both
- whole numbers - 1, -1, 3
- fractional value - 3.14
- string - a sequence of Unicode characters representing some text, like "hello".
- bool - a Boolean value, either "true" or "false".
- list -
- to store multiple values/elements within a pair of square brackets separated by comma.
- All values must be of same type(either string or numbers). and duplicates are allowed.
- E.g. animals = ["dog", "tiger", "cat", "dog"]
- A good example would be AWS Instance types.
- Values/elements of list are accessed using indexes. E.g. listname[0], listname[1]
- set - same as list type. A collection of unordered unique (no duplicates) values.
- tuple - to store multiple values within a pair of square brackets separated by comma. All values can be of different types. However, here the values must be ordered. A good example would be list of IP addresses
- map - a group of key-value pairs within a pair of curly/flower brackets {}. The key-value pairs can be separated by either a comma or a line break. The keys in key-value pair in the map must be strings and unique.
- object - a structural type that can contain different/all types of variable values e.g.
- details of student
{
name = <value>
email = <value>
age = <value>
}
- null - represented by unquoted symbol null
Elements in a list can be identified with consecutive whole numbers, starting with zero.
No comments:
Post a Comment