In this video, we're diving into the world of Terraform data types. If you're new to Terraform or want to understand how data types work, you’re in the right place. We’ll break down each data type with simple examples so you can confidently use them in your projects.
CHAPTERS
***********
00:00 INTRO
00:29 Data Type | String
00:56 Data Tytpe | Number
01:21 Data Type | Bool
01:47 Data Type | List
02:19 Data Type | Set
02:39 Data Type | Map
03:20 Data Type | Object
04:02 Data Type | Tuple
04:32 Testing the Output | String
04:55 Testing the Output | Number
05:02 Testing the Output | Bool
05:09 Testing the Output | List
05:25 Testing the Output | Set
05:35 Testing the Output | Map
05:47 Testing the Output | Object
06:00 Testing the Output | Tuple
06:19 OUTRO
1. String
Strings are text values and one of the most basic data types in Terraform. They're often used for names, IDs, or labels.
Example:
*********
variable "location" {
type = string
default = "eastus"
}
Here, the location variable is defined as a string with a default value of "eastus."
2. Number
The number type represents numeric values and can be an integer or a float. Use it to specify values like the number of VM instances.
Example:
*********
variable "vm_count" {
type = number
default = 2
}
In this example, vm_count is set to 2, meaning two instances will be deployed.
3. Bool
Bool stands for boolean values (true or false) and is great for toggling features.
Example:
*********
variable "enable_monitoring" {
type = bool
default = true
}
Here, monitoring is enabled because the value is set to true.
4. List
Lists are ordered collections of values of the same type. They’re handy for repeating configurations, such as multiple regions.
Example:
*********
variable "supported_locations" {
type = list(string)
default = ["eastus", "westus", "centralus"]
}
The supported_locations list contains different Azure regions, making the configuration scalable.
5. Set
Sets are similar to lists but only contain unique values, with no guaranteed order.
Example:
*********
variable "resource_tags" {
type = set(string)
default = ["web-server", "production"]
}
Using a set ensures that all tags are unique.
6. Map
Maps store key-value pairs, which is perfect for related data like tags or settings.
Example:
*********
variable "vm_skus" {
type = map(string)
default = {
dev = "Standard_DS1_v2"
staging = "Standard_DS2_v2"
prod = "Standard_DS3_v2"
}
}
Here, different VM SKUs are mapped to environment names for easy reference.
7. Object
Objects group various attributes together, similar to a configuration file.
Example:
*********
variable "vm_config" {
type = object({
vm_size = string
os_type = string
disk_size_gb = number
})
default = {
vm_size = "Standard_B2s"
os_type = "Linux"
disk_size_gb = 30
}
}
The vm_config object includes settings for a virtual machine, such as size and OS type.
8. Tuple
Tuples are ordered collections with different data types, useful for grouping related values.
Example:
*********
variable "database_settings" {
type = tuple([string, number, bool])
default = ["SQL Database", 50, true]
}
This tuple holds three different pieces of information: the database type, storage size, and a boolean for availability.
And that’s a wrap! We covered the essential Terraform data types to help you define your infrastructure as code. Understanding these types will make your configurations more flexible and powerful.
If you found this video helpful, hit the like button, and subscribe for more Terraform tutorials. Drop a comment below if you have questions or want us to dive deeper into specific topics. Thanks for watching, and happy coding!
Watch video Understanding Terraform Datatypes online without registration, duration hours minute second in high quality. This video was added by user vCloudBitsBytes 12 October 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 65 once and liked it 0 people.