Lab11: Terraform Interpolation - OT-TRAINING/TerraformAWS GitHub Wiki
In this lab, we will try to understand and implement the different terraform loops and interpolation. - Create a resource to create 2 Instances using the count loop - Once the Instances are created and you have validated it, please delete it - Create a resource which will take a list as input and create Virtual Machines with those names. Hint:- for_each can be used in this - Create a mapping between the EC2 instance ID and it's IP using the for loop in terraform. - Destroy the infrastructure again. - Create a condition in which you can check for the Instance name and if it is not provided, provide your team_name as Instance name. - Create two variables with type map, one is common_labels and other is specific_labels and after merging those two variables, pass it to the VM instance resource's label attribute. - Create two different variables for network tags and after concat pass it to the Instance instance resource's tags attribute
Create a resource to create 2 Instances using the count loop -
provider "aws" {
  region = "us-east-2"
}
data "aws_ami" "ubuntu" {
  most_recent = true 
  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  }
  owners = ["099720109477"] 
}
resource "aws_instance" "ec2" {
  count         = 2
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"
  tags = {
    Name = "team_name-instance-${count.index}"
  }
}