Day 63 - Terraform Variables

1 min read

Cover Image for Day 63 - Terraform Variables

variables in Terraform are quite important, as you need to hold values of names of instances, configs, etc.

We can create a variable.tf file which will hold all the variables.

variable "filename" {
default = "/home/ubuntu/terrform-tutorials/terraform-variables/demo-var.txt"
}
variable "content" {
default = "This is coming from a variable which was updated"
}

These variables can be accessed by the var object in main.tf

Task-01

  • Create a local file using Terraform Hint:
resource "local_file" "devops" {
filename = var.filename
content = var.content
}

Data Types in Terraform

Map

variable "file_contents" {
type = map
default = {
"statement1" = "this is cool"
"statement2" = "this is cooler"
}
}

In conclusion, variables are used to modify the configuration of terraforn without chaging the main.tf file.

Thank you for you patient reading!!๐Ÿ’•