-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
90 lines (78 loc) · 2.09 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.8.0"
}
}
}
provider "aws" {
region = "us-east-1"
#Using credentials file
shared_credentials_files = ["credentials"]
profile = "default"
}
### Networking
resource "aws_vpc" "main-vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "igw-1" {
vpc_id = aws_vpc.main-vpc.id
tags = {
Name = "Internet Gateway 1"
}
}
resource "aws_subnet" "publicsubnet1" { # Creating Public Subnets
vpc_id = aws_vpc.main-vpc.id
cidr_block = "10.0.0.0/24" # CIDR block of public subnets
availability_zone = "us-east-1a"
tags = {
Name = "public-subnet-1"
}
}
resource "aws_subnet" "privatesubnet1" { # Creating Private Subnets
vpc_id = aws_vpc.main-vpc.id
cidr_block = "10.0.1.0/24" # CIDR block of private subnets
availability_zone = "us-east-1a"
tags = {
Name = "private-subnet-1"
}
}
resource "aws_eip" "nateIP" {
vpc = true
}
resource "aws_nat_gateway" "NATgw" {
allocation_id = aws_eip.nateIP.id
subnet_id = aws_subnet.publicsubnet1.id
tags = {
Name = "nat-gw-1"
}
}
resource "aws_route_table" "PublicRT" { # Creating RT for Public Subnet
vpc_id = aws_vpc.main-vpc.id
route {
cidr_block = "0.0.0.0/0" # Traffic from Public Subnet reaches Internet via Internet Gateway
gateway_id = aws_internet_gateway.igw-1.id
}
tags = {
Name = "public-route-table"
}
}
resource "aws_route_table" "PrivateRT" { # Creating RT for Private Subnet
vpc_id = aws_vpc.main-vpc.id
route {
cidr_block = "0.0.0.0/0" # Traffic from Private Subnet reaches Internet via NAT Gateway
nat_gateway_id = aws_nat_gateway.NATgw.id
}
tags = {
Name = "private-route-table-1"
}
}
resource "aws_route_table_association" "PublicRTassociation1" {
subnet_id = aws_subnet.publicsubnet1.id
route_table_id = aws_route_table.PublicRT.id
}
resource "aws_route_table_association" "PrivateRTassociation1" {
subnet_id = aws_subnet.privatesubnet1.id
route_table_id = aws_route_table.PrivateRT.id
}