diff --git a/CHANGELOG.md b/CHANGELOG.md index b3901b9c..3e55d287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Added -- Write your awesome addition here (by @you) +- Added destroy-time flag (by @syst0m) ### Changed diff --git a/aws_auth.tf b/aws_auth.tf index c6b99a77..f9a381ce 100644 --- a/aws_auth.tf +++ b/aws_auth.tf @@ -1,11 +1,11 @@ resource "local_file" "config_map_aws_auth" { - count = var.write_aws_auth_config && local.enabled ? 1 : 0 + count = var.write_aws_auth_config && var.enabled ? 1 : 0 content = data.template_file.config_map_aws_auth.rendered filename = "${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml" } resource "null_resource" "update_config_map_aws_auth" { - count = var.manage_aws_auth && local.enabled ? 1 : 0 + count = var.manage_aws_auth && var.enabled ? 1 : 0 depends_on = [aws_eks_cluster.this] provisioner "local-exec" { diff --git a/cluster.tf b/cluster.tf index 10d569a7..3b353dc8 100644 --- a/cluster.tf +++ b/cluster.tf @@ -1,5 +1,5 @@ resource "aws_cloudwatch_log_group" "this" { - count = length(var.cluster_enabled_log_types) > 0 && local.enabled ? 1 : 0 + count = length(var.cluster_enabled_log_types) > 0 && var.enabled ? 1 : 0 name = "/aws/eks/${var.cluster_name}/cluster" retention_in_days = var.cluster_log_retention_in_days kms_key_id = var.cluster_log_kms_key_id @@ -7,7 +7,7 @@ resource "aws_cloudwatch_log_group" "this" { } resource "aws_eks_cluster" "this" { - count = local.enabled + count = var.enabled ? 1 : 0 name = var.cluster_name enabled_cluster_log_types = var.cluster_enabled_log_types role_arn = local.cluster_iam_role_arn @@ -34,7 +34,7 @@ resource "aws_eks_cluster" "this" { } resource "aws_security_group" "cluster" { - count = var.cluster_create_security_group && local.enabled ? 1 : 0 + count = var.cluster_create_security_group && var.enabled ? 1 : 0 name_prefix = var.cluster_name description = "EKS cluster security group." vpc_id = var.vpc_id @@ -47,7 +47,7 @@ resource "aws_security_group" "cluster" { } resource "aws_security_group_rule" "cluster_egress_internet" { - count = var.cluster_create_security_group && local.enabled ? 1 : 0 + count = var.cluster_create_security_group && var.enabled ? 1 : 0 description = "Allow cluster egress access to the Internet." protocol = "-1" security_group_id = local.cluster_security_group_id @@ -58,7 +58,7 @@ resource "aws_security_group_rule" "cluster_egress_internet" { } resource "aws_security_group_rule" "cluster_https_worker_ingress" { - count = var.cluster_create_security_group && local.enabled ? 1 : 0 + count = var.cluster_create_security_group && var.enabled ? 1 : 0 description = "Allow pods to communicate with the EKS cluster API." protocol = "tcp" security_group_id = local.cluster_security_group_id @@ -69,7 +69,7 @@ resource "aws_security_group_rule" "cluster_https_worker_ingress" { } resource "aws_iam_role" "cluster" { - count = var.manage_cluster_iam_resources && local.enabled ? 1 : 0 + count = var.manage_cluster_iam_resources && var.enabled ? 1 : 0 name_prefix = var.cluster_name assume_role_policy = data.aws_iam_policy_document.cluster_assume_role_policy.json permissions_boundary = var.permissions_boundary @@ -79,13 +79,13 @@ resource "aws_iam_role" "cluster" { } resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSClusterPolicy" { - count = var.manage_cluster_iam_resources && local.enabled ? 1 : 0 + count = var.manage_cluster_iam_resources && var.enabled ? 1 : 0 policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" role = local.cluster_iam_role_name } resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSServicePolicy" { - count = var.manage_cluster_iam_resources && local.enabled ? 1 : 0 + count = var.manage_cluster_iam_resources && var.enabled ? 1 : 0 policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy" role = local.cluster_iam_role_name } diff --git a/kubectl.tf b/kubectl.tf index 30fc0ed1..41708ec4 100644 --- a/kubectl.tf +++ b/kubectl.tf @@ -1,5 +1,5 @@ resource "local_file" "kubeconfig" { - count = var.write_kubeconfig && local.enabled ? 1 : 0 + count = var.write_kubeconfig && var.enabled ? 1 : 0 content = data.template_file.kubeconfig.rendered filename = "${substr(var.config_output_path, -1, 1) == "/" ? "${var.config_output_path}kubeconfig_${var.cluster_name}" : var.config_output_path}" } diff --git a/variables.tf b/variables.tf index eb6ea983..b0ae3177 100644 --- a/variables.tf +++ b/variables.tf @@ -295,7 +295,7 @@ variable "attach_worker_cni_policy" { } variable "enabled" { - description = "Destroy-time flag. If set to "false", the count will be set to "0" on all resources." + description = "Destroy-time flag. If set to `false`, the count will be set to `0` on all resources." type = bool default = true } diff --git a/workers.tf b/workers.tf index 240ee3e5..53e12cad 100644 --- a/workers.tf +++ b/workers.tf @@ -1,7 +1,7 @@ # Worker Groups using Launch Configurations resource "aws_autoscaling_group" "workers" { - count = (local.worker_group_count * local.enabled) + count = var.enabled ? local.worker_group_count : 0 name_prefix = join( "-", compact( @@ -143,7 +143,7 @@ resource "aws_autoscaling_group" "workers" { } resource "aws_launch_configuration" "workers" { - count = (local.worker_group_count * local.enabled) + count = var.enabled ? local.worker_group_count : 0 name_prefix = "${aws_eks_cluster.this.name}-${lookup(var.worker_groups[count.index], "name", count.index)}" associate_public_ip_address = lookup( var.worker_groups[count.index], @@ -232,7 +232,7 @@ resource "aws_launch_configuration" "workers" { } resource "random_pet" "workers" { - count = (local.worker_group_count * local.enabled) + count = var.enabled ? local.worker_group_count : 0 separator = "-" length = 2 @@ -243,7 +243,7 @@ resource "random_pet" "workers" { } resource "aws_security_group" "workers" { - count = var.worker_create_security_group && local.enabled ? 1 : 0 + count = var.worker_create_security_group && var.enabled ? 1 : 0 name_prefix = aws_eks_cluster.this.name description = "Security group for all nodes in the cluster." vpc_id = var.vpc_id @@ -257,7 +257,7 @@ resource "aws_security_group" "workers" { } resource "aws_security_group_rule" "workers_egress_internet" { - count = var.worker_create_security_group && local.enabled ? 1 : 0 + count = var.worker_create_security_group && var.enabled ? 1 : 0 description = "Allow nodes all egress to the Internet." protocol = "-1" security_group_id = local.worker_security_group_id @@ -268,7 +268,7 @@ resource "aws_security_group_rule" "workers_egress_internet" { } resource "aws_security_group_rule" "workers_ingress_self" { - count = var.worker_create_security_group && local.enabled ? 1 : 0 + count = var.worker_create_security_group && var.enabled ? 1 : 0 description = "Allow node to communicate with each other." protocol = "-1" security_group_id = local.worker_security_group_id @@ -279,7 +279,7 @@ resource "aws_security_group_rule" "workers_ingress_self" { } resource "aws_security_group_rule" "workers_ingress_cluster" { - count = var.worker_create_security_group && local.enabled ? 1 : 0 + count = var.worker_create_security_group && var.enabled ? 1 : 0 description = "Allow workers pods to receive communication from the cluster control plane." protocol = "tcp" security_group_id = local.worker_security_group_id @@ -290,7 +290,7 @@ resource "aws_security_group_rule" "workers_ingress_cluster" { } resource "aws_security_group_rule" "workers_ingress_cluster_kubelet" { - count = var.worker_create_security_group && local.enabled ? var.worker_sg_ingress_from_port > 10250 ? 1 : 0 : 0 + count = var.worker_create_security_group && var.enabled ? var.worker_sg_ingress_from_port > 10250 ? 1 : 0 : 0 description = "Allow workers Kubelets to receive communication from the cluster control plane." protocol = "tcp" security_group_id = local.worker_security_group_id @@ -301,7 +301,7 @@ resource "aws_security_group_rule" "workers_ingress_cluster_kubelet" { } resource "aws_security_group_rule" "workers_ingress_cluster_https" { - count = var.worker_create_security_group && local.enabled ? 1 : 0 + count = var.worker_create_security_group && var.enabled ? 1 : 0 description = "Allow pods running extension API servers on port 443 to receive communication from cluster control plane." protocol = "tcp" security_group_id = local.worker_security_group_id @@ -312,7 +312,7 @@ resource "aws_security_group_rule" "workers_ingress_cluster_https" { } resource "aws_iam_role" "workers" { - count = var.manage_worker_iam_resources && local.enabled ? 1 : 0 + count = var.manage_worker_iam_resources && var.enabled ? 1 : 0 name_prefix = var.workers_role_name != "" ? null : aws_eks_cluster.this.name name = var.workers_role_name != "" ? var.workers_role_name : null assume_role_policy = data.aws_iam_policy_document.workers_assume_role_policy.json @@ -323,7 +323,7 @@ resource "aws_iam_role" "workers" { } resource "aws_iam_instance_profile" "workers" { - count = var.manage_worker_iam_resources && local.enabled ? local.worker_group_count : 0 + count = var.manage_worker_iam_resources && var.enabled ? local.worker_group_count : 0 name_prefix = aws_eks_cluster.this.name role = lookup( var.worker_groups[count.index], @@ -335,37 +335,37 @@ resource "aws_iam_instance_profile" "workers" { } resource "aws_iam_role_policy_attachment" "workers_AmazonEKSWorkerNodePolicy" { - count = var.manage_worker_iam_resources && local.enabled ? 1 : 0 + count = var.manage_worker_iam_resources && var.enabled ? 1 : 0 policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy" role = aws_iam_role.workers[0].name } resource "aws_iam_role_policy_attachment" "workers_AmazonEKS_CNI_Policy" { - count = var.manage_worker_iam_resources && var.attach_worker_cni_policy && local.enabled ? 1 : 0 + count = var.manage_worker_iam_resources && var.attach_worker_cni_policy && var.enabled ? 1 : 0 policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" role = aws_iam_role.workers[0].name } resource "aws_iam_role_policy_attachment" "workers_AmazonEC2ContainerRegistryReadOnly" { - count = var.manage_worker_iam_resources && local.enabled ? 1 : 0 + count = var.manage_worker_iam_resources && var.enabled ? 1 : 0 policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" role = aws_iam_role.workers[0].name } resource "aws_iam_role_policy_attachment" "workers_additional_policies" { - count = var.manage_worker_iam_resources && local.enabled ? length(var.workers_additional_policies) : 0 + count = var.manage_worker_iam_resources && var.enabled ? length(var.workers_additional_policies) : 0 role = aws_iam_role.workers[0].name policy_arn = var.workers_additional_policies[count.index] } resource "aws_iam_role_policy_attachment" "workers_autoscaling" { - count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.attach_worker_autoscaling_policy && local.enabled ? 1 : 0 + count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.attach_worker_autoscaling_policy && var.enabled ? 1 : 0 policy_arn = aws_iam_policy.worker_autoscaling[0].arn role = aws_iam_role.workers[0].name } resource "aws_iam_policy" "worker_autoscaling" { - count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && local.enabled ? 1 : 0 + count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.enabled ? 1 : 0 name_prefix = "eks-worker-autoscaling-${aws_eks_cluster.this.name}" description = "EKS worker node autoscaling policy for cluster ${aws_eks_cluster.this.name}" policy = data.aws_iam_policy_document.worker_autoscaling.json diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 2bd83bfb..f2d84ad7 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -1,7 +1,7 @@ # Worker Groups using Launch Templates resource "aws_autoscaling_group" "workers_launch_template" { - count = (local.worker_group_launch_template_count * local.enabled) + count = (local.worker_group_launch_template_count * var.enabled) name_prefix = join( "-", compact( @@ -218,7 +218,7 @@ resource "aws_autoscaling_group" "workers_launch_template" { } resource "aws_launch_template" "workers_launch_template" { - count = (local.worker_group_launch_template_count * local.enabled) + count = (local.worker_group_launch_template_count * var.enabled) name_prefix = "${aws_eks_cluster.this.name}-${lookup( var.worker_groups_launch_template[count.index], "name", @@ -382,7 +382,7 @@ resource "aws_launch_template" "workers_launch_template" { } resource "random_pet" "workers_launch_template" { - count = (local.worker_group_launch_template_count * && local.enabled) + count = (local.worker_group_launch_template_count * var.enabled) separator = "-" length = 2 @@ -401,7 +401,7 @@ resource "random_pet" "workers_launch_template" { } resource "aws_iam_instance_profile" "workers_launch_template" { - count = var.manage_worker_iam_resources ? (local.worker_group_launch_template_count * local.enabled) : 0 + count = var.manage_worker_iam_resources ? (local.worker_group_launch_template_count * var.enabled) : 0 name_prefix = aws_eks_cluster.this.name role = lookup( var.worker_groups_launch_template[count.index],