MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Terraform Tutorials: Variables – Data Type – Map

In this example, the instance_tags variable is defined with a type of map(string), and it is given a default value of { Name = "my-instance" }. The AWS provider is then configured to use the us-west-2 region.

The aws_instance resource is used to launch Amazon EC2 instances. The tags argument is used to assign tags to the instance, and it is set to the value of the instance_tags variable.

You can change the value of instance_tags by modifying the default value in the variable definition, or you can specify a different value when you run Terraform by using the -var flag. For example, if you want to launch an instance with tags { Name = "my-instance", Environment = "prod" }, you can run the following command:

$ terraform apply -var ‘instance_tags={ Name = “my-instance”, Environment = “prod” }’


Maps are a collection of string keys and string values. These can be useful for selecting values based on predefined parameters such as the server configuration by the monthly price.

We’ve replaced our sensitive strings with variables, but we still are hard-coding AMIs. Unfortunately, AMIs are specific to the region that is in use. One option is to just ask the user to input the proper AMI for the region, but Terraform can do better than that with maps.

dynamic lookup – The square-bracket index notation used here is an example of how the map type expression is accessed as a variable, with [var.region] referencing the var.amis declaration for dynamic lookup.

static value lookup – the map type expression can also use a static value lookup directly with var.amis[“us-east-1”].

Maps are a way to create variables that are lookup tables. An example will show this best. Let’s extract our AMIs into a map and add support for the us-west-2 region as well:

Find Trusted Cardiac Hospitals

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

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Terraform Error Handing with Try Catch

The code could be improved by adding some error handling. For example, you could check to make sure that the PEM file exists and that the password…

Read More

Terraform Project – Assignment – Exercise – Lab#1: Variables

How to submit Assignment? Please submit assignment @https://www.debug.school/ and POST url share in the comments of this post. Assignment – 1 Write a terraform script using aws…

Read More

Quick Tutorials of Hashicorp Packer

Packer AWS – Builders & Provisionars – aws-ubuntu.pkr.hcl Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge,…

Read More

Terraform Tutorials: Variables – Data Type – String

In this example, the instance_name variable is defined with a type of string, and it is given a default value of “my-instance”. The AWS provider is then…

Read More

Terraform Tutorials: Variables – Data Type – List

In this example, the security_groups variable is defined with a type of list(string), and it is given a default value of [“default”]. The AWS provider is then…

Read More

Terraform Tutorials: Variables – Data Type – Number

In this example, the instance_count variable is defined with a type of number, and it is given a default value of 1. The AWS provider is then…

Read More