-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
112 lines (93 loc) · 2.68 KB
/
main.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
resource "aws_autoscaling_group" "main" {
name = var.name
max_size = 1
min_size = 1
desired_capacity = 1
health_check_type = "EC2"
vpc_zone_identifier = [var.subnet_id]
launch_template {
id = aws_launch_template.main.id
version = aws_launch_template.main.latest_version
}
tag {
key = "Name"
value = var.name
propagate_at_launch = true
}
dynamic "tag" {
for_each = var.tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
instance_refresh {
strategy = "Rolling"
}
timeouts {
delete = "15m"
}
}
resource "aws_security_group" "main" {
name = var.name
description = "Used in ${var.name} instance of subnet-router in subnet ${var.subnet_id}"
vpc_id = var.vpc_id
dynamic "ingress" {
for_each = var.advertise_addresses
content {
description = "Allow local traffic from ${ingress.value} to the site to site instance"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [ingress.value]
}
}
ingress {
description = "Allow remote subnet traffic from the VPC to the site to site instance"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = var.remote_addresses
}
egress {
description = "Unrestricted egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
tags = merge(var.tags, {
Name = var.name
})
}
resource "aws_network_interface" "main" {
description = "${var.name} reusable ENI for routing traffic between sites"
subnet_id = var.subnet_id
security_groups = [aws_security_group.main.id]
source_dest_check = false
tags = merge(var.tags, {
Name = var.name
})
}
resource "aws_eip" "main" {
#checkov:skip=CKV2_AWS_19:Reusable EIP
domain = "vpc"
network_interface = aws_network_interface.main.id
tags = merge(var.tags, {
Name = var.name
})
}
resource "aws_route" "main" {
count = length(var.route_table_ids) * length(var.remote_addresses)
route_table_id = var.route_table_ids[floor(count.index / length(var.remote_addresses))]
destination_cidr_block = var.remote_addresses[count.index % length(var.remote_addresses)]
network_interface_id = aws_network_interface.main.id
}
resource "aws_route" "tailnet" {
count = length(var.route_table_ids)
route_table_id = var.route_table_ids[count.index]
destination_cidr_block = "100.64.0.0/10"
network_interface_id = aws_network_interface.main.id
}