-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added opentofu project for creating a custom VPC on AWS
- Loading branch information
Showing
11 changed files
with
756 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
./webapp/node_modules/* | ||
./webapp/package-lock.json | ||
webapp/node_modules/ | ||
webapp/package-lock.json | ||
webapp/package-lock.json | ||
iac/aws/terraform/creating-custom-vpc/.terraform/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable aws_region { | ||
default = "us-east-1" | ||
description = "AWS region where the resources will be provisioned" | ||
} | ||
|
||
# Configure the AWS Provider | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
# helm = { | ||
# source = "hashicorp/aws" | ||
# version = "~> 2.6" | ||
# } | ||
} | ||
} | ||
|
||
# Configure region and profile | ||
provider "aws" { | ||
region = var.aws_region | ||
profile = "myaws" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "aws_vpc" "mycustomvpc" { | ||
cidr_block = "10.0.0.0/16" | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
|
||
tags = { | ||
"owner" = "vinod" | ||
"Name" = "my custom VPC" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
iac/aws/terraform/creating-custom-vpc/002.internet.gateway.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
resource "aws_internet_gateway" "igw" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
tags = { | ||
"owner" = "vinod" | ||
"Name" = "IGW" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
resource "aws_subnet" "private-us-east-1a" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
cidr_block = "10.0.1.0/24" | ||
availability_zone = "us-east-1a" | ||
|
||
tags = { | ||
"subnet" = "private-us-east-1a" | ||
"Name" = "Private Subnet" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "private-us-east-1b" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
cidr_block = "10.0.2.0/24" | ||
availability_zone = "us-east-1b" | ||
|
||
tags = { | ||
"subnet" = "private-us-east-1b" | ||
"Name" = "Private Subnet" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "public-us-east-1a" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
cidr_block = "10.0.3.0/24" | ||
availability_zone = "us-east-1a" | ||
map_public_ip_on_launch = true | ||
|
||
tags = { | ||
"subnet" = "public-us-east-1a" | ||
"Name" = "Public Subnet" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "public-us-east-1b" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
cidr_block = "10.0.4.0/24" | ||
availability_zone = "us-east-1b" | ||
map_public_ip_on_launch = true | ||
|
||
tags = { | ||
"subnet" = "public-us-east-1b" | ||
"Name" = "Public Subnet" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
resource "aws_eip" "nat" { | ||
vpc = true | ||
|
||
tags = { | ||
"Name" = "EIP" | ||
"Owner" = "Vinod" | ||
} | ||
|
||
} | ||
|
||
resource "aws_nat_gateway" "nat" { | ||
allocation_id = aws_eip.nat.id | ||
subnet_id = aws_subnet.public-us-east-1a.id | ||
|
||
tags = { | ||
"Name" = "NAT Gateway" | ||
"Owner" = "Vinod" | ||
} | ||
|
||
# To ensure proper ordering, it is recommended to add an explicit dependency | ||
# on the Internet Gateway for the VPC. | ||
depends_on = [aws_internet_gateway.igw] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
resource "aws_route_table" "privateroute" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
nat_gateway_id = aws_nat_gateway.nat.id | ||
} | ||
|
||
tags = { | ||
Name = "private" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "publicroute" { | ||
vpc_id = aws_vpc.mycustomvpc.id | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = aws_internet_gateway.igw.id | ||
} | ||
|
||
tags = { | ||
Name = "public" | ||
} | ||
} | ||
|
||
resource "aws_route_table_association" "privateassociation_a" { | ||
subnet_id = aws_subnet.private-us-east-1a.id | ||
route_table_id = aws_route_table.privateroute.id | ||
} | ||
resource "aws_route_table_association" "privateassociation_b" { | ||
subnet_id = aws_subnet.private-us-east-1b.id | ||
route_table_id = aws_route_table.privateroute.id | ||
} | ||
resource "aws_route_table_association" "publicassociation_a" { | ||
subnet_id = aws_subnet.public-us-east-1a.id | ||
route_table_id = aws_route_table.publicroute.id | ||
} | ||
resource "aws_route_table_association" "publicassociation_b" { | ||
subnet_id = aws_subnet.public-us-east-1b.id | ||
route_table_id = aws_route_table.publicroute.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Description | ||
Creating a custom VPC using OpenTofu. | ||
|
||
## Architecture | ||
![Alt text](image https://drive.google.com/file/d/1-1enJhmxFLkUp2jaqOkKGFqueP6cF68W/view?usp=sharing) | ||
|
Oops, something went wrong.