-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.tf
90 lines (70 loc) · 2.06 KB
/
data.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
data "aws_ami" "ami" {
filter {
name = "architecture"
values = ["arm64"]
}
filter {
name = "name"
values = ["debian-11*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
most_recent = true
owners = [136693071363]
}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_route_table" "private" {
for_each = toset(var.private_subnet_ids)
subnet_id = each.value
depends_on = [
data.aws_subnet.subnets,
]
}
data "aws_subnet" "eni_subnet" {
for_each = aws_network_interface.eni
id = each.value.subnet_id
}
data "aws_subnet" "first" {
id = var.public_subnet_ids[0]
}
data "aws_subnet" "subnets" {
for_each = toset(concat(var.private_subnet_ids, var.public_subnet_ids))
id = each.value
}
data "aws_vpc" "vpc" {
id = data.aws_subnet.first.vpc_id
}
data "template_cloudinit_config" "cloudinit" {
for_each = toset(var.private_subnet_ids)
base64_encode = true
gzip = true
part {
content = data.template_file.cloudinit_base.rendered
content_type = "text/cloud-config"
merge_type = "dict(recurse_array)+list(append)"
}
}
data "template_file" "cloudinit_base" {
template = file("${path.module}/templates/cloudinit_base.tpl")
vars = {
nat_script_file = base64gzip(data.template_file.nat_failover_trigger_script.rendered)
nat_add_route_file = base64gzip(data.template_file.nat_add_route_script.rendered)
nat_systemd_file = base64gzip(data.template_file.nat_failover_systemd.rendered)
vpc_cidr = data.aws_vpc.vpc.cidr_block
}
}
data "template_file" "nat_add_route_script" {
template = file("${path.module}/templates/usr/local/bin/add_default_route.py.tpl")
}
data "template_file" "nat_failover_systemd" {
template = file("${path.module}/templates/etc/systemd/system/nat-failover.service.tpl")
}
data "template_file" "nat_failover_trigger_script" {
template = file("${path.module}/templates/usr/local/bin/nat-failover-trigger.py.tpl")
vars = {
sns_arn = aws_sns_topic.nat_failover_topic.arn
}
}