This guide will walk you through the steps to configure two EC2 instances in two different AWS regions using Terraform and running it on LocalStack.
- LocalStack setup and running on your machine.
- Terraform installed on your machine.
- AWS CLI installed and configured on your machine
Now, go to the terminal and navigate to the directory where you have saved the main.tf file. Run the following commands:
terraform init
terraform plan
terraform apply --auto-approve
Now , Run the command to check if 2 instances are created in 2 different AWS regions
aws --endpoint-url=http://localhost:4566 ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress,Tags[?Key==`Name`]| [0].Value]' --output table --region us-east-1
aws --endpoint-url=http://localhost:4566 ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress,Tags[?Key==`Name`]| [0].Value]' --output table --region us-east-2