-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
144 lines (132 loc) · 4.15 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
locals {
block_devices = var.image_source.volume_id != "" ? [{
uuid = var.image_source.volume_id
source_type = "volume"
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}] : []
cloudinit_templates = concat([
{
filename = "base.cfg"
content_type = "text/cloud-config"
content = templatefile(
"${path.module}/files/user_data.yaml.tpl",
{
hostname = var.name
install_dependencies = var.install_dependencies
}
)
},
{
filename = "vault.cfg"
content_type = "text/cloud-config"
content = module.vault_configs.configuration
},
{
filename = "node_exporter.cfg"
content_type = "text/cloud-config"
content = module.prometheus_node_exporter_configs.configuration
}
],
var.fluentbit.enabled ? [{
filename = "fluent_bit.cfg"
content_type = "text/cloud-config"
content = module.fluentbit_configs.configuration
}] : [],
var.chrony.enabled ? [{
filename = "chrony.cfg"
content_type = "text/cloud-config"
content = module.chrony_configs.configuration
}] : [],
)
}
module "vault_configs" {
source = "git::https://github.com/Ferlab-Ste-Justine/terraform-cloudinit-templates.git//vault?ref=v0.27.4"
install_dependencies = var.install_dependencies
hostname = var.hostname
release_version = var.release_version
tls = var.tls
etcd_backend = var.etcd_backend
}
module "prometheus_node_exporter_configs" {
source = "git::https://github.com/Ferlab-Ste-Justine/terraform-cloudinit-templates.git//prometheus-node-exporter?ref=v0.15.0"
install_dependencies = var.install_dependencies
}
module "chrony_configs" {
source = "git::https://github.com/Ferlab-Ste-Justine/terraform-cloudinit-templates.git//chrony?ref=v0.15.0"
install_dependencies = var.install_dependencies
chrony = {
servers = var.chrony.servers
pools = var.chrony.pools
makestep = var.chrony.makestep
}
}
module "fluentbit_configs" {
source = "git::https://github.com/Ferlab-Ste-Justine/terraform-cloudinit-templates.git//fluent-bit?ref=v0.15.0"
install_dependencies = true
fluentbit = {
metrics = var.fluentbit.metrics
systemd_services = concat(
var.fluentbit.etcd_tag != "" ? [{
tag = var.fluentbit.etcd_tag
service = "etcd.service"
}] : [],
[
{
tag = var.fluentbit.containerd_tag
service = "containerd.service"
},
{
tag = var.fluentbit.kubelet_tag
service = "kubelet.service"
},
{
tag = var.fluentbit.node_exporter_tag
service = "node-exporter.service"
}
]
)
forward = var.fluentbit.forward
}
}
data "template_cloudinit_config" "user_data" {
gzip = true
base64_encode = true
dynamic "part" {
for_each = local.cloudinit_templates
content {
filename = part.value["filename"]
content_type = part.value["content_type"]
content = part.value["content"]
}
}
}
resource "openstack_compute_instance_v2" "vault_node" {
name = var.name
image_id = var.image_source.image_id != "" ? var.image_source.image_id : null
flavor_id = var.flavor_id
key_pair = var.keypair_name
user_data = data.template_cloudinit_config.user_data.rendered
network {
port = var.network_port.id
}
scheduler_hints {
group = var.server_group.id
}
dynamic "block_device" {
for_each = local.block_devices
content {
uuid = block_device.value["uuid"]
source_type = block_device.value["source_type"]
boot_index = block_device.value["boot_index"]
destination_type = block_device.value["destination_type"]
delete_on_termination = block_device.value["delete_on_termination"]
}
}
lifecycle {
ignore_changes = [
user_data,
]
}
}