forked from kube-hetzner/terraform-hcloud-kube-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kustomization_user.tf
61 lines (51 loc) · 1.83 KB
/
kustomization_user.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
locals {
user_kustomization_templates = try(fileset("extra-manifests", "*.yaml.tpl"), toset([]))
}
resource "null_resource" "kustomization_user" {
for_each = local.user_kustomization_templates
connection {
user = "root"
private_key = var.ssh_private_key
agent_identity = local.ssh_agent_identity
host = module.control_planes[keys(module.control_planes)[0]].ipv4_address
port = var.ssh_port
}
provisioner "file" {
content = templatefile("extra-manifests/${each.key}", var.extra_kustomize_parameters)
destination = replace("/var/user_kustomize/${each.key}", ".yaml.tpl", ".yaml")
}
triggers = {
manifest_sha1 = "${sha1(templatefile("extra-manifests/${each.key}", var.extra_kustomize_parameters))}"
}
depends_on = [
null_resource.kustomization
]
}
resource "null_resource" "kustomization_user_deploy" {
count = length(local.user_kustomization_templates) > 0 ? 1 : 0
connection {
user = "root"
private_key = var.ssh_private_key
agent_identity = local.ssh_agent_identity
host = module.control_planes[keys(module.control_planes)[0]].ipv4_address
port = var.ssh_port
}
# Remove templates after rendering, and apply changes.
provisioner "remote-exec" {
# Debugging: "sh -c 'for file in $(find /var/user_kustomize -type f -name \"*.yaml\" | sort -n); do echo \"\n### Template $${file}.tpl after rendering:\" && cat $${file}; done'",
inline = compact([
"rm -f /var/user_kustomize/*.yaml.tpl",
"echo 'Applying user kustomization...'",
"kubectl apply -k /var/user_kustomize/ --wait=true",
var.extra_kustomize_deployment_commands
])
}
lifecycle {
replace_triggered_by = [
null_resource.kustomization_user
]
}
depends_on = [
null_resource.kustomization_user
]
}