# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. provider "helm" { kubernetes { host = var.cluster_endpoint cluster_ca_certificate = base64decode(var.cluster_certificate_authority_data) exec { api_version = "client.authentication.k8s.io/v1beta1" command = "aws" args = ["eks", "get-token", "--cluster-name", var.cluster_name] } } } resource "kubernetes_namespace" "cluster_autoscaler" { count = (var.enabled && var.create_namespace && var.namespace != "kube-system") ? 1 : 0 metadata { name = var.namespace } } resource "helm_release" "cluster_autoscaler" { count = var.enabled ? 1 : 0 name = "cluster-autoscaler" chart = "cluster-autoscaler" repository = "https://kubernetes.github.io/autoscaler" version = "9.25.0" namespace = var.namespace set { name = "fullnameOverride" value = "aws-cluster-autoscaler" } set { name = "autoDiscovery.clusterName" value = var.cluster_name } set { name = "awsRegion" value = var.aws_region } set { name = "rbac.serviceAccount.name" value = "cluster-autoscaler" } set { name = "rbac.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn" value = aws_iam_role.kubernetes_cluster_autoscaler[0].arn } values = [ yamlencode(var.settings) ] }