Skip to content

RajatSablok/terraform-aws-ec2-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform AWS EC2 Setup

Use this project to allocate an AWS EC2 instance programmatically.

Configurations

  1. AMI: Ubuntu Server 20.04 LTS (ami-0851b76e8b1bce90b) (free tier eligible)
  2. Instance Type: t2.micro (free tier eligible)
  3. Security Group inbound rules will allow access to port 22 (SSH), 443 (HTTPS), 80 (HTTP) from anywhere

These configurations can be edited from main.tf file.

Prerequisites:

  1. Terraform
  2. AWS CLI
  3. AWS Account and Security Credentials

Steps to run:

  1. Clone the repository
git clone https://github.com/RajatSablok/terraform-aws-ec2-setup.git
  1. Configure AWS CLI
aws configure
  1. Create new AWS Key Pair (PEM) file
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem
  1. Initialize Terraform project
terraform init
  1. Edit variables.tf file to enter name of the EC2 instance and PEM file that you created
  2. Apply the changes (this will allocate the EC2 instance)
terraform apply

Note

Use terraform destroy to terminate the EC2 instance and the related security group.