-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc.tf
81 lines (63 loc) · 1.76 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
## VPCs
resource "aws_default_vpc" "default" {
tags = {
Name = "Default VPC"
}
}
## Subnets
resource "aws_default_subnet" "public" {
count = local.az_count
availability_zone = local.available_azs[count.index]
tags = {
Name = "Default subnet for ${local.available_azs[count.index]}"
}
}
resource "aws_subnet" "private" {
count = local.az_count
availability_zone = local.available_azs[count.index]
vpc_id = aws_default_vpc.default.id
cidr_block = cidrsubnet(aws_default_vpc.default.cidr_block, 4, 8 + count.index)
tags = {
Name = "Private subnet for ${local.available_azs[count.index]}"
}
}
## Route tables
resource "aws_route_table" "private" {
vpc_id = aws_default_vpc.default.id
tags = {
Name = "Private route table"
}
}
resource "aws_route_table_association" "private" {
count = local.az_count
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private.id
}
## Security groups
resource "aws_security_group" "alb" {
name = "alb"
description = "SG for ALB"
vpc_id = aws_default_vpc.default.id
}
resource "aws_vpc_security_group_ingress_rule" "alb_https" {
security_group_id = aws_security_group.alb.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "tcp"
from_port = 443
to_port = 443
}
resource "aws_vpc_security_group_ingress_rule" "alb_icmp" {
security_group_id = aws_security_group.alb.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "icmp"
from_port = "-1"
to_port = "-1"
}
# for OIDC authentication
resource "aws_vpc_security_group_egress_rule" "alb_https" {
security_group_id = aws_security_group.alb.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "tcp"
from_port = 443
to_port = 443
}