Skip to content

Commit

Permalink
Allow disabling cluster-autoscaler role
Browse files Browse the repository at this point in the history
  • Loading branch information
antonincms committed Jul 1, 2024
1 parent 6fd0985 commit 16dd6a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions iam_cluster_autoscaler.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
locals {
handle_iam_cluster_autoscaler = var.handle_iam_resources && var.handle_iam_cluster_autoscaler
}

resource "aws_iam_role" "quortex_role_autoscaler" {
count = var.handle_iam_resources ? 1 : 0
count = local.handle_iam_cluster_autoscaler ? 1 : 0
name = var.autoscaler_role_name
description = "IAM Role to allow the autoscaler service account to manage AWS Autoscaling."
tags = var.tags
Expand Down Expand Up @@ -29,7 +33,7 @@ resource "aws_iam_role" "quortex_role_autoscaler" {
# Inspired by https://github.com/terraform-aws-modules/terraform-aws-iam/blob/263426fbb6cb8b0d59fb6b2a86168047ff1e58ac/modules/iam-role-for-service-accounts-eks/policies.tf#L48

data "aws_iam_policy_document" "cluster_autoscaler" {
count = var.handle_iam_resources ? 1 : 0
count = local.handle_iam_cluster_autoscaler ? 1 : 0

statement {
actions = [
Expand Down Expand Up @@ -67,7 +71,7 @@ data "aws_iam_policy_document" "cluster_autoscaler" {
}

resource "aws_iam_policy" "quortex_autoscaler_policy" {
count = var.handle_iam_resources ? 1 : 0
count = local.handle_iam_cluster_autoscaler ? 1 : 0

description = "Allow the autoscaler to make calls to the AWS APIs."
policy = data.aws_iam_policy_document.cluster_autoscaler[0].json
Expand All @@ -76,7 +80,7 @@ resource "aws_iam_policy" "quortex_autoscaler_policy" {
}

resource "aws_iam_role_policy_attachment" "quortex_autoscaler_policy_attach" {
count = var.handle_iam_resources ? 1 : 0
count = local.handle_iam_cluster_autoscaler ? 1 : 0
role = aws_iam_role.quortex_role_autoscaler[0].name
policy_arn = aws_iam_policy.quortex_autoscaler_policy[0].arn
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ variable "handle_iam_aws_load_balancer_controller" {
default = false
}

variable "handle_iam_cluster_autoscaler" {
type = bool
description = "Wether to handle IAM resources lifecycle for cluster-autoscaler"
default = true
}

variable "handle_iam_external_dns" {
type = bool
description = "Whether to handle IAM resources lifecycle for external-dns addon"
Expand Down

0 comments on commit 16dd6a8

Please sign in to comment.