Here are the complete step-by-step instructions that you can copy and paste into a Word document or PDF for your project:
- AWS Account: Ensure you have an active AWS account.
- SSH Key Pair: Create an SSH key pair in your AWS account and download the
.pem
file. - Amazon Linux Instance: Ensure you have an Amazon Linux instance running with access to install and run Terraform.
-
Update Package Repository:
sudo yum update -y
-
Download and Unzip Terraform:
wget https://releases.hashicorp.com/terraform/1.0.11/terraform_1.0.11_linux_amd64.zip unzip terraform_1.0.11_linux_amd64.zip -d /usr/local/bin
-
Verify Terraform Installation:
terraform -version
-
Install AWS CLI (if not already installed):
sudo yum install aws-cli -y
-
Configure AWS CLI:
aws configure
- Enter your AWS Access Key ID, Secret Access Key, Default region name (
us-east-2
), and Default output format (e.g.,json
).
- Enter your AWS Access Key ID, Secret Access Key, Default region name (
-
Create a Project Directory:
mkdir aws-multi-server cd aws-multi-server
-
Create and Edit
main.tf
:nano main.tf
-
Add the Following Configuration to
main.tf
:provider "aws" { region = "us-east-2" } resource "aws_security_group" "allow_ssh" { vpc_id = "vpc-07c013bc2e179830d" # Your VPC ID ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } } resource "aws_instance" "web" { count = 3 ami = "ami-0942ecd5d85baa812" # Your AMI ID instance_type = "t2.micro" subnet_id = "subnet-0b313bf9dfbc70934" # Your Subnet ID vpc_security_group_ids = [aws_security_group.allow_ssh.id] tags = { Name = "WebServer-${count.index + 1}" } }
-
Save and Exit:
- In Nano, press
Ctrl + O
,Enter
, thenCtrl + X
to save and exit the editor.
- In Nano, press
-
Initialize Terraform:
terraform init
-
Plan the Deployment:
terraform plan
-
Apply the Configuration:
terraform apply
- When prompted to confirm, type
yes
and pressEnter
.
- When prompted to confirm, type
-
Check AWS Management Console:
- Go to the EC2 Dashboard in the AWS Management Console.
- Verify that three EC2 instances have been created, each tagged as
WebServer-1
,WebServer-2
, andWebServer-3
.
-
SSH into Instances:
- Use the public IP addresses of the instances to SSH into them from your PuTTY session. For example:
ssh -i "C:\Users\nomii\Downloads\Syed1.pem" ec2-user@<public-ip-of-instance>
- Replace
<public-ip-of-instance>
with the actual public IP address of each instance.
- Use the public IP addresses of the instances to SSH into them from your PuTTY session. For example:
By following these steps, you'll be able to deploy multiple EC2 instances using Terraform on your Amazon Linux instance. This guide provides a complete, step-by-step process to set up and deploy your infrastructure!!