-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
135 lines (114 loc) · 3.66 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
resource "aws_vpc" "production-internal" {
cidr_block = "172.31.0.0/16"
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.production-internal.id
}
resource "aws_subnet" "production-internal-a" {
vpc_id = aws_vpc.production-internal.id
cidr_block = "172.31.0.0/20"
availability_zone = "${var.aws_region}a"
}
resource "aws_subnet" "production-internal-b" {
vpc_id = aws_vpc.production-internal.id
cidr_block = "172.31.16.0/20"
availability_zone = "${var.aws_region}b"
}
resource "aws_subnet" "production-internal-c" {
vpc_id = aws_vpc.production-internal.id
cidr_block = "172.31.32.0/20"
availability_zone = "${var.aws_region}c"
}
resource "aws_db_subnet_group" "production-subnet-group" {
name = "${var.project_environment}-${var.project_name}"
subnet_ids = [aws_subnet.production-internal-a.id, aws_subnet.production-internal-b.id, aws_subnet.production-internal-c.id]
tags = {
Name = "${var.project_environment}-${var.project_name}"
}
}
resource "aws_route_table" "production" {
vpc_id = aws_vpc.production-internal.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
}
resource "aws_main_route_table_association" "a" {
vpc_id = aws_vpc.production-internal.id
route_table_id = aws_route_table.production.id
}
data "aws_subnets" "subnets" {
filter {
name = "vpc-id"
values = [aws_vpc.production-internal.id]
}
}
resource "aws_security_group" "production-webservers" {
name = "${var.project_environment}-webservers"
description = "${var.project_environment}-webservers"
vpc_id = aws_vpc.production-internal.id
ingress {
description = "HTTP from lb"
from_port = 80
to_port = 80
protocol = "tcp"
security_groups = [aws_security_group.production-load-balancer.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
resource "aws_security_group" "production-workers" {
name = "${var.project_environment}-workers"
description = "${var.project_environment}-workers"
vpc_id = aws_vpc.production-internal.id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
resource "aws_security_group" "production-internal" {
name = "${var.project_environment}-internal"
description = "${var.project_environment}-internal"
vpc_id = aws_vpc.production-internal.id
ingress {
description = "All traffic from webservers and workers"
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [aws_security_group.production-webservers.id, aws_security_group.production-workers.id]
}
ingress {
description = "SSH Access"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = var.ssh_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
resource "aws_security_group" "production-rds" {
name = "${var.project_environment}-rds"
description = "${var.project_environment}-rds"
vpc_id = aws_vpc.production-internal.id
ingress {
description = "PSQL traffic from webservers and workers"
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.production-webservers.id, aws_security_group.production-workers.id]
}
}