-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathvpc_spoke.tf
87 lines (77 loc) · 2.62 KB
/
vpc_spoke.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
resource "aws_vpc" "spoke_vpc" {
cidr_block = var.spoke_cidr_block
enable_dns_hostnames = true
enable_dns_support = true
tags = merge(var.tags, {
Name = "${local.prefix}-spoke-vpc"
})
}
resource "aws_subnet" "spoke_db_private_subnet" {
vpc_id = aws_vpc.spoke_vpc.id
count = length(local.spoke_db_private_subnets_cidr)
cidr_block = element(local.spoke_db_private_subnets_cidr, count.index)
availability_zone = element(local.availability_zones, count.index)
map_public_ip_on_launch = false
tags = merge(var.tags, {
Name = "${local.prefix}-spoke-db-private-${element(local.availability_zones, count.index)}"
})
}
resource "aws_subnet" "spoke_tgw_private_subnet" {
vpc_id = aws_vpc.spoke_vpc.id
count = length(local.spoke_tgw_private_subnets_cidr)
cidr_block = element(local.spoke_tgw_private_subnets_cidr, count.index)
availability_zone = element(local.availability_zones, count.index)
map_public_ip_on_launch = false
tags = merge(var.tags, {
Name = "${local.prefix}-spoke-tgw-private-${element(local.availability_zones, count.index)}"
})
}
resource "aws_route_table" "spoke_db_private_rt" {
vpc_id = aws_vpc.spoke_vpc.id
tags = merge(var.tags, {
Name = "${local.prefix}-spoke-db-private-rt"
})
}
resource "aws_main_route_table_association" "spoke-set-worker-default-rt-assoc" {
vpc_id = aws_vpc.spoke_vpc.id
route_table_id = aws_route_table.spoke_db_private_rt.id
}
resource "aws_route_table_association" "spoke_db_private_rta" {
count = length(local.spoke_db_private_subnets_cidr)
subnet_id = element(aws_subnet.spoke_db_private_subnet.*.id, count.index)
route_table_id = aws_route_table.spoke_db_private_rt.id
}
resource "aws_security_group" "default_spoke_sg" {
name = "${local.prefix}-default_spoke_sg"
description = "Default security group to allow inbound/outbound from the VPC"
vpc_id = aws_vpc.spoke_vpc.id
depends_on = [aws_vpc.spoke_vpc]
dynamic "ingress" {
for_each = local.sg_ingress_protocol
content {
from_port = 0
to_port = 65535
protocol = ingress.value
self = true
}
}
dynamic "egress" {
for_each = local.sg_egress_protocol
content {
from_port = 0
to_port = 65535
protocol = egress.value
self = true
}
}
dynamic "egress" {
for_each = local.sg_ports
content {
from_port = egress.value
to_port = egress.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
tags = var.tags
}