https://github.com/tks-devops/terraform-project
Terraform Project for AWS Infrastructure..1 VPC ○ 3 public subnets ○ 3 private subnets ○ 3 Private routing tables ○ 1 public routing table ○ 1 internet gateway ○ 3 Elastic IP's for NAT Gateways ○ 3 NAT GateWays
https://github.com/tks-devops/terraform-project
aws-ec2 awscli elastic elastic-ip-for-nat-gateways git github internet-gateway linux nat-gateways private-routing-table private-subnets public-routing-table public-subnet shell-script teraform vpc yaml yaml-configuration
Last synced: 4 months ago
JSON representation
Terraform Project for AWS Infrastructure..1 VPC ○ 3 public subnets ○ 3 private subnets ○ 3 Private routing tables ○ 1 public routing table ○ 1 internet gateway ○ 3 Elastic IP's for NAT Gateways ○ 3 NAT GateWays
- Host: GitHub
- URL: https://github.com/tks-devops/terraform-project
- Owner: Tks-Devops
- Created: 2024-12-23T23:52:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-25T12:23:42.000Z (about 1 year ago)
- Last Synced: 2025-09-02T06:33:04.907Z (4 months ago)
- Topics: aws-ec2, awscli, elastic, elastic-ip-for-nat-gateways, git, github, internet-gateway, linux, nat-gateways, private-routing-table, private-subnets, public-routing-table, public-subnet, shell-script, teraform, vpc, yaml, yaml-configuration
- Language: HCL
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Terraform Project for AWS Infrastructure
## Step 1: Install Terraform
Download and install Terraform from [terraform.io](https://www.terraform.io/downloads.html).
Verify installation:
```bash
terraform --version
Step 2: Create Terraform Files
Create a new directory for Terraform:
mkdir terraform_project && cd terraform_project
Create main.tf:
nano main.tf
Paste the following configuration:
HCL
provider "aws" {
region = "us-east-1"
}
# Fetch Availability Zones
data "aws_availability_zones" "available" {}
# Create VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "main-vpc"
}
}
# Create Public Subnets
resource "aws_subnet" "public" {
count = 3
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, count.index)
availability_zone = element(data.aws_availability_zones.available.names, count.index)
map_public_ip_on_launch = true
tags = {
Name = "public-subnet-${count.index + 1}"
}
}
# Create Private Subnets
resource "aws_subnet" "private" {
count = 3
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, count.index + 3)
availability_zone = element(data.aws_availability_zones.available.names, count.index)
tags = {
Name = "private-subnet-${count.index + 1}"
}
}
# Create Internet Gateway
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
tags = {
Name = "main-internet-gateway"
}
}
# Create Public Route Table
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
tags = {
Name = "public-route-table"
}
}
# Add Route to Internet Gateway in Public Route Table
resource "aws_route" "public_internet_access" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
# Associate Public Subnets with Public Route Table
resource "aws_route_table_association" "public" {
count = 3
subnet_id = aws_subnet.public[count.index].id
route_table_id = aws_route_table.public.id
}
# Create Elastic IPs for NAT Gateways
resource "aws_eip" "nat" {
count = 3
vpc = true
tags = {
Name = "nat-eip-${count.index + 1}"
}
}
# Create NAT Gateways
resource "aws_nat_gateway" "nat" {
count = 3
allocation_id = aws_eip.nat[count.index].id
subnet_id = aws_subnet.public[count.index].id
tags = {
Name = "nat-gateway-${count.index + 1}"
}
}
# Create Private Route Tables
resource "aws_route_table" "private" {
count = 3
vpc_id = aws_vpc.main.id
tags = {
Name = "private-route-table-${count.index + 1}"
}
}
# Add Routes to NAT Gateways in Private Route Tables
resource "aws_route" "private_nat_access" {
count = 3
route_table_id = aws_route_table.private[count.index].id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat[count.index].id
}
# Associate Private Subnets with Private Route Tables
resource "aws_route_table_association" "private" {
count = 3
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private[count.index].id
}
Initialize and apply:
bash
terraform init
terraform apply