-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
125 lines (94 loc) · 2.75 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
#tfsec:ignore:aws-ec2-require-vpc-flow-logs-for-all-vpcs
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "SOAT Tech Challenge VPC"
}
}
resource "aws_subnet" "public_subnets" {
count = length(var.private_subnet_cidrs)
vpc_id = aws_vpc.main.id
cidr_block = element(var.public_subnet_cidrs, count.index)
availability_zone = element(local.azs, count.index)
tags = {
Name = "SOAT-TC VPC Public Subnet ${count.index + 1}"
}
}
resource "aws_subnet" "private_subnets" {
count = length(var.private_subnet_cidrs)
vpc_id = aws_vpc.main.id
cidr_block = element(var.private_subnet_cidrs, count.index)
availability_zone = element(local.azs, count.index)
tags = {
Name = "SOAT-TC VPC Private Subnet ${count.index + 1}"
}
}
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
tags = {
Name = "SOAT-TC VPC Internet Gateway"
}
}
resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
tags = {
Name = "SOAT-TC VPC Public Route Table"
}
}
resource "aws_route_table" "private_rt" {
vpc_id = aws_vpc.main.id
tags = {
Name = "SOAT-TC VPC Private Route Table"
}
}
resource "aws_route_table_association" "public_rt_association" {
count = length(var.public_subnet_cidrs)
subnet_id = element(aws_subnet.public_subnets[*].id, count.index)
route_table_id = aws_route_table.public_rt.id
}
resource "aws_route_table_association" "private_rt_association" {
count = length(var.private_subnet_cidrs)
subnet_id = element(aws_subnet.private_subnets[*].id, count.index)
route_table_id = aws_route_table.private_rt.id
}
resource "aws_vpc_endpoint" "dynamodb" {
service_name = "com.amazonaws.${var.aws_region}.dynamodb"
vpc_id = aws_vpc.main.id
vpc_endpoint_type = "Gateway"
route_table_ids = [aws_route_table.public_rt.id]
tags = {
Name = "SOAT-TC DynamoDB VPC Gateway Endpoint"
}
}
resource "aws_vpc_endpoint" "sqs" {
service_name = "com.amazonaws.${var.aws_region}.sqs"
vpc_id = aws_vpc.main.id
vpc_endpoint_type = "Interface"
subnet_ids = aws_subnet.public_subnets[*].id
security_group_ids = [aws_default_security_group.default.id]
private_dns_enabled = true
tags = {
Name = "SOAT-TC SQS VPC Interface Endpoint"
}
}
resource "aws_default_security_group" "default" {
vpc_id = aws_vpc.main.id
ingress {
protocol = -1
self = true
from_port = 0
to_port = 0
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}