Table of contents
No headings in the article.
Variables in Terraform are fundamental for holding values such as instance names, configurations, and more. By creating a variables.tf
file, we can conveniently manage all our variables in one place.
Creating Variables:
hclCopy codevariable "filename" {
default = "/home/ubuntu/terrform-tutorials/terraform-variables/demo-var.txt"
}
variable "content" {
default = "This is coming from a variable which was updated"
}
Accessing Variables: These variables can be accessed using the var
object in the main.tf
file.
Task-01: Creating a Local File
hclCopy coderesource "local_file" "devops" {
filename = var.filename
content = var.content
}
Data Types in Terraform: Terraform supports various data types, including maps, lists, sets, and objects.
Map:
hclCopy codevariable "file_contents" {
type = map
default = {
"statement1" = "this is cool"
"statement2" = "this is cooler"
}
}
Task-02: Demonstrating Usage of List, Set, and Object Datatypes For this task, we'll utilize Terraform to showcase the usage of list, set, and object data types. In our variables.tf
file:
Refreshing State: To refresh the state by your configuration file, use terraform refresh
.
By mastering Terraform variables and understanding their various data types, we gain more control and flexibility in managing our infrastructure. Let's dive into the practical implementation and explore the power of variables in Terraform! ๐ #Terraform #InfrastructureAsCode #DevOps #Automation
Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.
You can connect with me at: https://www.linkedin.com/in/davendersingh/