diff --git a/modules/extensions/autoscaler.tf b/modules/extensions/autoscaler.tf index d46a21ab..bd424e85 100644 --- a/modules/extensions/autoscaler.tf +++ b/modules/extensions/autoscaler.tf @@ -9,12 +9,21 @@ locals { worker_pools_autoscaling = { for k, v in var.worker_pools : k => v if tobool(lookup(v, "autoscale", false)) } # Whether to enable cluster autoscaler deployment based on configuration, active nodes, and autoscaling pools - cluster_autoscaler_enabled = alltrue([ + remote_cluster_autoscaler_enabled = alltrue([ var.cluster_autoscaler_install, var.expected_node_count > 0, var.expected_autoscale_worker_pools > 0, + var.cluster_autoscaler_remote_exec ]) + local_cluster_autoscaler_enabled = alltrue([ + var.cluster_autoscaler_install, + var.expected_node_count > 0, + var.expected_autoscale_worker_pools > 0, + var.cluster_autoscaler_remote_exec == false + ]) + + # Templated Helm manifest values cluster_autoscaler_manifest = sensitive(one(data.helm_template.cluster_autoscaler[*].manifest)) cluster_autoscaler_manifest_path = join("/", [local.yaml_manifest_path, "cluster_autoscaler.yaml"]) @@ -118,7 +127,7 @@ data "helm_template" "cluster_autoscaler" { } resource "null_resource" "cluster_autoscaler" { - count = local.cluster_autoscaler_enabled ? 1 : 0 + count = local.remote_cluster_autoscaler_enabled ? 1 : 0 triggers = { manifest_md5 = try(md5(local.cluster_autoscaler_manifest), null) @@ -148,3 +157,15 @@ resource "null_resource" "cluster_autoscaler" { inline = ["kubectl apply -f ${local.cluster_autoscaler_manifest_path}"] } } + +resource "null_resource" "local_cluster_autoscaler" { + count = local.local_cluster_autoscaler_enabled ? 1 : 0 + + triggers = { + manifest_md5 = try(md5(local.cluster_autoscaler_manifest), null) + } + + provisioner "local-exec" { + inline = ["cat ${local.cluster_autoscaler_manifest} | kubectl apply --dry-run='client' -f -"] + } +} diff --git a/modules/extensions/variables.tf b/modules/extensions/variables.tf index be1a57fa..f608f13b 100644 --- a/modules/extensions/variables.tf +++ b/modules/extensions/variables.tf @@ -72,6 +72,7 @@ variable "cluster_autoscaler_helm_version" { type = string } variable "cluster_autoscaler_helm_values" { type = map(string) } variable "cluster_autoscaler_helm_values_files" { type = list(string) } variable "expected_autoscale_worker_pools" { type = number } +variable "cluster_autoscaler_remote_exec" { type = bool } # Prometheus variable "prometheus_install" { type = bool } diff --git a/variables-extensions.tf b/variables-extensions.tf index b5488885..b2ceba94 100644 --- a/variables-extensions.tf +++ b/variables-extensions.tf @@ -207,6 +207,12 @@ variable "cluster_autoscaler_helm_values_files" { type = list(string) } +variable "cluster_autoscaler_remote_exec" { + default = true + description = "Whether to execute deploy the cluster autoscaler remotely via the operator server. If false, the cluster autoscaler helm chart will be installed on the same machine you are running Terraform from." + type = bool +} + # Prometheus variable "prometheus_install" {