Skip to content

Commit

Permalink
added rest vpc scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
easyawslearn committed Sep 23, 2019
1 parent ebd4f82 commit e1b5f76
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
7 changes: 7 additions & 0 deletions terraform-aws-vpc/internet-gateway.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.vpc_demo.id}"

tags = {
Name = "internet-gateway-demo"
}
}
35 changes: 35 additions & 0 deletions terraform-aws-vpc/nat.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
resource "aws_eip" "nat" {
vpc = true
}

resource "aws_nat_gateway" "nat_gw" {
allocation_id = "${aws_eip.nat.id}"
subnet_id = "${aws_subnet.public_1.id}"
depends_on = ["aws_internet_gateway.gw"]
}

resource "aws_route_table" "route_private" {
vpc_id = "${aws_vpc.vpc_demo.id}"

route {
cidr_block = "10.0.0.0/0"
gateway_id = "${aws_nat_gateway.nat_gw.id}"
}

tags = {
Name = "private-route-table-demo"
}
}

resource "aws_route_table_association" "private_1" {
subnet_id = "${aws_subnet.private_1.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
resource "aws_route_table_association" "private_2" {
subnet_id = "${aws_subnet.private_2.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
resource "aws_route_table_association" "private_3" {
subnet_id = "${aws_subnet.private_3.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
6 changes: 3 additions & 3 deletions terraform-aws-vpc/private_subnets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "aws_subnet" "private_1" {
cidr_block = "10.0.4.0/24"

tags = {
Name = "private_1"
Name = "private_1-demo"
}
}
resource "aws_subnet" "private_2" {
Expand All @@ -13,7 +13,7 @@ resource "aws_subnet" "private_2" {
cidr_block = "10.0.5.0/24"

tags = {
Name = "private_1"
Name = "private_2-demo"
}
}
resource "aws_subnet" "private_3" {
Expand All @@ -22,6 +22,6 @@ resource "aws_subnet" "private_3" {
cidr_block = "10.0.6.0/24"

tags = {
Name = "private_1"
Name = "private_3-demo"
}
}
6 changes: 3 additions & 3 deletions terraform-aws-vpc/public_subnets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "aws_subnet" "public_1" {
cidr_block = "10.0.1.0/24"

tags = {
Name = "public_1"
Name = "public_1-demo"
}
}
resource "aws_subnet" "public_2" {
Expand All @@ -13,7 +13,7 @@ resource "aws_subnet" "public_2" {
cidr_block = "10.0.2.0/24"

tags = {
Name = "public_1"
Name = "public_2-demo"
}
}
resource "aws_subnet" "public_3" {
Expand All @@ -22,6 +22,6 @@ resource "aws_subnet" "public_3" {
cidr_block = "10.0.3.0/24"

tags = {
Name = "public_1"
Name = "public_3-demo"
}
}
27 changes: 27 additions & 0 deletions terraform-aws-vpc/route_table.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "aws_route_table" "route-public" {
vpc_id = "${aws_vpc.vpc_demo.id}"

route {
cidr_block = "10.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}

tags = {
Name = "public-route-table-demo"
}
}

resource "aws_route_table_association" "public_1" {
subnet_id = "${aws_subnet.public_1.id}"
route_table_id = "${aws_route_table.route-public.id}"
}

resource "aws_route_table_association" "public_2" {
subnet_id = "${aws_subnet.public_2.id}"
route_table_id = "${aws_route_table.route-public.id}"
}

resource "aws_route_table_association" "public_3" {
subnet_id = "${aws_subnet.public_3.id}"
route_table_id = "${aws_route_table.route-public.id}"
}

0 comments on commit e1b5f76

Please sign in to comment.