PENDING CLEANUP
Module 8: Terraform Assignment - 3
Tasks To Be Performed:
- Destroy the previous deployment
- Create 2 EC2 instances in Ohio and N.Virginia respectively
- Rename Ohio’s instance to ‘hello-ohio’ and Virginia’s instance to ‘hello-virginia’
Step1:
Destroyed deployment Assignment 2 – Terraform
terraform destroy
Step 2-3:
provider "aws" {
region = "us-east-2" # Ohio region
alias = "ohio"
}
provider "aws" {
region = "us-east-1" # N. Virginia region
alias = "virginia"
}
resource "aws_instance" "hello_ohio" {
provider = aws.ohio
ami = "ami-06d4b7182ac3480fa"
instance_type = "t2.micro"
subnet_id = "subnet-01384a93bc22b2937"
tags = {
Name = "hello-ohio"
}
}
resource "aws_instance" "hello_virginia" {
provider = aws.virginia
ami = "ami-0230bd60aa48260c6"
instance_type = "t2.micro"
subnet_id = "subnet-05419866677eb6366"
tags = {
Name = "hello-virginia"
}
}
In this configuration:
- Two
provider
blocks are defined, each with a differentalias
(ohio
andvirginia
), targeting theus-east-2
(Ohio) andus-east-1
(N. Virginia) regions, respectively. - Two
aws_instance
resources are created:hello_ohio
for the Ohio region andhello_virginia
for the N. Virginia region. Each instance uses its respective provider by specifyingprovider = aws.<alias>
. - The
ami
andsubnet_id
for each instance should be appropriate for their respective regions. You need to replace the placeholders with the actual AMI IDs and subnet IDs for each region. - The
tags
for each instance are set tohello-ohio
andhello-virginia
, respectively.