-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
80 lines (69 loc) · 2.29 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
locals {
# These files all get executable permissions.
script_files = [for key, value in var.script_files : {
"path" : key,
"content" : value,
"permissions" : "0755"
}]
# These files are just text/data.
config_files = concat(
[for file_path, contents in var.config_files :
{
"path" : file_path,
"content" : contents
}
],
)
# Create run commands from base config, service starts, and module input
runcmd = concat(
["systemctl daemon-reload"],
var.runcmd,
flatten([for service in var.services : [
"systemctl enable ${service}",
"systemctl start --no-block ${service}",
]]),
flatten([for service in var.user_services : [
"su - ${service.user} -c 'systemctl --user enable ${service.name}'",
"su - ${service.user} -c 'systemctl --user start --no-block ${service.name}'",
]]),
var.endcmd
)
cloud_config = yamlencode(
# Build custom config from input and local variables
{
"write_files" : concat(local.script_files, local.config_files, var.write_files),
"runcmd" : local.runcmd,
"bootcmd" : var.bootcmd,
"mounts" : var.mounts,
"packages" : var.packages,
"package_update": var.package_update,
"package_upgrade": var.package_upgrade,
"package_reboot_if_required": var.package_reboot_if_required,
"growpart" : {
"mode" : "auto",
"devices" : concat(["/"], var.grow_partition_devices)
},
}
)
}
data "cloudinit_config" "main" {
base64_encode = true
# Automatically GZIP if things get too big (with reasonable margin for error).
# Cloud Init Length + Initial MIME Headers + Estimated "Parts" Length + Estimated "parts" headers > 85% of the total space
gzip = length(local.cloud_config) + 180 + length(yamlencode(var.parts)) + (length(var.parts) * 100) > (16384 * 0.85)
## Module Generated Configs using "cloud-config" format.
part {
content = local.cloud_config
content_type = "text/cloud-config"
}
# Caller Specific Configs
dynamic "part" {
for_each = var.parts
content {
content = part.value["content"]
filename = try(part.value["filename"], null)
content_type = try(part.value["content_type"], null)
merge_type = try(part.value["merge_type"], null)
}
}
}