Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Terraform Tutorials: Variables Complete Reference

In Terraform, there are several types of variables that you can define, including:

  1. String: A sequence of characters. Example: “hello”.
  2. Number: A numeric value. Example: 42.
  3. Boolean: A logical value that is either true or false.
  4. List: A sequence of values of the same type. Example: [ “apples”, “oranges”, “bananas” ].
  5. Map: A collection of key-value pairs, where the keys and values can be of any type. Example: { “name” = “John”, “age” = 30 }.
  6. Object: A complex data type that can contain multiple attributes. Example: { name = “John”, age = 30, address = { street = “123 Main St”, city = “Anytown”, state = “CA” } }.
  7. Tuple: A sequence of values of different types. Example: [ “John”, 30, true ].

Quick Tutorials on Terraform Variable

Terraform Variables and Configuration explained – 5 mins reading!

Terraform Variable Naming convention

Types of Terraform variable

Location of Declaring Terraform Variable


One Example Code


variable "instance_count" {
  type = number
  default = 1
}

variable "instance_name" {
  type = string
  default = "Rajesh"
}

resource "aws_instance" "example-number" {
  count = var.instance_count
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  
  tags = {
    Name = var.instance_name
  }
}


variable "security_groups" {
  type = list(string)
  default = ["sg-0541801a7a059ba17"]
}


resource "aws_instance" "example-list" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  vpc_security_group_ids = var.security_groups
}

variable "instance_tags" {
  type = map(string)
  default = {
    Name = "my-instance4mMap-Rajesh"
  }
}

resource "aws_instance" "example-map" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  tags = var.instance_tags
}

variable "create_vm" {
  description = "If set to true, it will create vm"
   type   = bool
}

resource "aws_instance" "example-bool" {
  count   = var.create_vm ? 1 : 0
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  tags = var.instance_tags
}Code language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Terraform workspace explained!!!

What is Terraform workspace? Have you worked with terraform workflow? such as terraform init/plan/apply/destroy with terraform configuration file? If Yes, you already have worked with Terraform workspace….

Read More

Terraform Tutorials: Templating in Terraform

Top 10 Templating Engines Across Major Programming Languages # Templating Engine Programming Language Common Framework / Ecosystem Typical Real Use 1 Jinja2 Python Flask, Ansible HTML generation,…

Read More

Terraform provisioners Tutorials and Complete Guide

Terraform provisioners are used to execute scripts or shell commands on a local or remote machine as part of resource creation/deletion. They are similar to “EC2 instance…

Read More

Terraform Tutorials: Local Values using Local Block

What is local value in terraform? In Terraform, a locals block is used to define local variables within a module, allowing you to create reusable expressions and…

Read More

Terraform Tutorials: Module Complete Guide

A Terraform module is a collection of configuration files that encapsulate resources used together to achieve a specific outcome. Modules promote reusability, organization, and maintainability in infrastructure…

Read More

What is Terrafile?

Terrafile is a tool used to manage Terraform modules as dependencies. It simplifies the process of downloading and managing Terraform modules by automating the fetching of modules…

Read More