-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
61 lines (51 loc) · 1.61 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
locals {
# Helm command configuration
helm_command = <<-EOT
helm upgrade --install ${var.release_name} ${var.repo_name}/${var.chart_name} \
--version ${var.chart_version} \
--namespace ${var.namespace} \
${var.create_namespace ? "--create-namespace" : ""} \
-f $VALUES_FILE \
--debug
EOT
}
# Main resource for Helm installation
resource "null_resource" "helm_install" {
triggers = {
chart_name = var.chart_name
chart_version = var.chart_version
release_name = var.release_name
namespace = var.namespace
always_update = var.always_update != false ? timestamp() : "initial"
}
provisioner "local-exec" {
command = <<-EOT
echo "Starting Helm install process..."
# Create temporary files
export KUBECONFIG=$(mktemp)
VALUES_FILE=$(mktemp)
echo "Created temporary files: KUBECONFIG=$KUBECONFIG, VALUES_FILE=$VALUES_FILE"
# Generate kubeconfig
cat <<EOF > $KUBECONFIG
${var.kubeconfig_json}
EOF
echo "Generated kubeconfig file"
# Generate values file
cat <<EOF > $VALUES_FILE
${jsonencode(var.set_values)}
EOF
echo "Generated values file"
# Execute Helm commands
echo "Executing Helm commands..."
helm repo add ${var.repo_name} ${var.repo_url}
helm repo update
${local.helm_command}
HELM_EXIT_CODE=$?
echo "Helm command completed with exit code: $HELM_EXIT_CODE"
# Cleanup
rm $KUBECONFIG $VALUES_FILE
echo "Cleaned up temporary files"
exit $HELM_EXIT_CODE
EOT
}
}