Skip to content

This repository includes a Terraform configuration designed to create a basic AWS Virtual Private Cloud (VPC) infrastructure. The setup features an Internet Gateway, Route Table, Subnet, Security Group, and an EC2 instance with an Elastic IP, along with the necessary networking components.

Notifications You must be signed in to change notification settings

kingshadie/TerraformAWSVpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Configuration for AWS VPC with EC2 Instance This repository contains a Terraform configuration to set up a basic AWS Virtual Private Cloud (VPC) infrastructure. This setup includes an Internet Gateway, Route Table, Subnet, Security Group, EC2 instance with an Elastic IP, and associated networking components. The EC2 instance is provisioned with Apache web server installed and serves a simple webpage.

Prerequisites

Before applying this configuration, ensure you have the following:

  1. Terraform installed on your machine. You can install Terraform from here.
  2. AWS CLI configured with the appropriate credentials. You can configure it using aws configure.
  3. An SSH key pair in your AWS account. The key pair name should match the value of key_name in the configuration (terraformkeypair in this case). You can create one from the AWS Console under EC2 > Key Pairs.

Resources

This Terraform configuration sets up the following resources:

  1. VPC: A Virtual Private Cloud (VPC) with a CIDR block of 10.0.0.0/16.
  2. Internet Gateway: Allows the VPC to communicate with the internet.
  3. Route Table: Configures routes to allow outbound internet traffic via the Internet Gateway.
  4. Subnet: A subnet with a CIDR block of 10.0.1.0/24, located in us-east-1a.
  5. Security Group: A security group with the following inbound rules: Allow HTTP (port 80) from anywhere.

Allow HTTPS (port 443) from anywhere.

Allow SSH (port 22) from anywhere.

Allow IPv6 HTTPS (port 443) from anywhere.

Additionally, outbound traffic is allowed for both IPv4 and IPv6.

  1. Elastic IP (EIP): An elastic IP address that is associated with the EC2 instance.
  2. Network Interface: A network interface attached to the EC2 instance.
  3. EC2 Instance: A t2.micro EC2 instance using an Amazon Linux AMI, with Apache installed and configured to serve a simple web page.

Configuration

1. Virtual Private Cloud (VPC)**

The VPC resource creates a VPC with a CIDR block of 10.0.0.0/16.

image

2. Internet Gateway

The Internet Gateway allows the VPC to connect to the internet.

image

3. Route Table

The Route Table includes routes for both IPv4 and IPv6 traffic, directing outbound traffic through the Internet Gateway.

image

4. Subnet

This configuration creates a subnet in the us-east-1a availability zone.

image

5. Security Group

The security group allows inbound web traffic (HTTP, HTTPS) and SSH, while allowing all outbound traffic.

image

Set Inbound Rules

• Allow HTTP (port 80) from anywhere (IPv4). • Allow HTTPS (port 443) from anywhere (IPv4 and IPv6). • Allow SSH (port 22) from anywhere

image

Set Outbound Rules

Allow all outbound traffic for both IPv4 and IPv6.

image

6. Network Interface

This network interface is associated with the subnet and security group.

image

7. Elastic IP

An Elastic IP is created and associated with the network interface.

image

9. EC2 Instance An EC2 instance is created with the network interface attached. Apache is installed and configured to serve a simple web page.

image

Usage

  1. Clone this repository to your local machine.
  2. Initialize Terraform:

image

  1. Validate the configuration:

image

  1. Apply the configuration:

image

  1. Confirm the changes, and Terraform will begin provisioning your infrastructure.

Cleanup To destroy the infrastructure created by this configuration, run: image

This Terraform configuration sets up a basic VPC infrastructure with an EC2 instance and associated networking components. When deploying this configuration, make sure to:

1. Replace placeholders: Customize the CIDR blocks, region, AMI ID, and key pair name based on your environment.

2. Harden security: Restrict access where possible, use private subnets for internal resources, and apply the principle of least privilege to security groups and IAM roles.

About

This repository includes a Terraform configuration designed to create a basic AWS Virtual Private Cloud (VPC) infrastructure. The setup features an Internet Gateway, Route Table, Subnet, Security Group, and an EC2 instance with an Elastic IP, along with the necessary networking components.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages