-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc.tf
89 lines (72 loc) · 1.67 KB
/
vpc.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
resource "aws_vpc" "ws-VPC" {
cidr_block = var.vpc_cidr
tags = {
Name = "ws-VPC"
}
}
resource "aws_internet_gateway" "ws-igw" {
vpc_id = aws_vpc.ws-VPC.id
tags = {
Name = "Web Server VPC"
}
}
resource "aws_subnet" "public" {
count = 2
vpc_id = aws_vpc.ws-VPC.id
cidr_block = element(var.subnets_cidr, count.index)
availability_zone = element(var.azs, count.index)
map_public_ip_on_launch = true
tags = {
Name = "Public Subnet-${count.index + 1}"
}
}
resource "aws_route_table" "ws-public_rt" {
vpc_id = aws_vpc.ws-VPC.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.ws-igw.id
}
tags = {
Name = "Public Route Table"
}
}
resource "aws_route_table_association" "public" {
count = 2
subnet_id = element(aws_subnet.public.*.id, count.index)
route_table_id = aws_route_table.ws-public_rt.id
}
resource "aws_subnet" "private" {
vpc_id = aws_vpc.ws-VPC.id
cidr_block = "10.0.3.0/24"
tags = {
Name = "Private Subnet"
}
}
resource "aws_route_table" "ws-private_rt" {
vpc_id = aws_vpc.ws-VPC.id
}
resource "aws_route_table_association" "private" {
subnet_id = aws_subnet.private.id
route_table_id = aws_route_table.ws-private_rt.id
}
resource "aws_eip" "ws-eIP" {
vpc = true
}
resource "aws_security_group" "ws-sg" {
vpc_id = aws_vpc.ws-VPC.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "Allow HTTP access"
}
}