-
-
Notifications
You must be signed in to change notification settings - Fork 538
Expand file tree
/
Copy pathkustomization_user.tf
More file actions
87 lines (72 loc) · 2.59 KB
/
kustomization_user.tf
File metadata and controls
87 lines (72 loc) · 2.59 KB
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
locals {
user_kustomization_templates = try(fileset(var.extra_kustomize_folder, "**/*.yaml.tpl"), toset([]))
}
resource "terraform_data" "kustomization_user" {
for_each = local.user_kustomization_templates
connection {
user = "root"
private_key = var.ssh_private_key
agent_identity = local.ssh_agent_identity
host = local.first_control_plane_ip
port = var.ssh_port
bastion_host = local.ssh_bastion.bastion_host
bastion_port = local.ssh_bastion.bastion_port
bastion_user = local.ssh_bastion.bastion_user
bastion_private_key = local.ssh_bastion.bastion_private_key
}
provisioner "remote-exec" {
inline = [
"mkdir -p $(dirname /var/user_kustomize/${each.key})"
]
}
provisioner "file" {
content = templatefile("${var.extra_kustomize_folder}/${each.key}", var.extra_kustomize_parameters)
destination = replace("/var/user_kustomize/${each.key}", ".yaml.tpl", ".yaml")
}
triggers_replace = {
manifest_sha1 = "${sha1(templatefile("${var.extra_kustomize_folder}/${each.key}", var.extra_kustomize_parameters))}"
}
depends_on = [
terraform_data.kustomization
]
}
moved {
from = null_resource.kustomization_user
to = terraform_data.kustomization_user
}
resource "terraform_data" "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 = local.first_control_plane_ip
port = var.ssh_port
bastion_host = local.ssh_bastion.bastion_host
bastion_port = local.ssh_bastion.bastion_port
bastion_user = local.ssh_bastion.bastion_user
bastion_private_key = local.ssh_bastion.bastion_private_key
}
# 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 = [
terraform_data.kustomization_user
]
}
depends_on = [
terraform_data.kustomization_user
]
}
moved {
from = null_resource.kustomization_user_deploy
to = terraform_data.kustomization_user_deploy
}