From 8e1526b8681a7aaf823c29d2a0951dc6b9e1b84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Toma=C5=A1i=C4=87?= Date: Wed, 20 Nov 2019 12:59:39 +0000 Subject: [PATCH] Update flag name to `create_eks` --- aws_auth.tf | 6 +++--- cluster.tf | 16 ++++++++-------- data.tf | 2 +- kubectl.tf | 2 +- workers.tf | 36 ++++++++++++++++++------------------ workers_launch_template.tf | 8 ++++---- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/aws_auth.tf b/aws_auth.tf index 9f9e4510..358a7814 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 && var.create_cluster ? 1 : 0 + count = var.write_aws_auth_config && var.create_eks ? 1 : 0 content = data.template_file.config_map_aws_auth[0].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 && var.create_cluster ? 1 : 0 + count = var.manage_aws_auth && var.create_eks ? 1 : 0 depends_on = [aws_eks_cluster.this] provisioner "local-exec" { @@ -77,7 +77,7 @@ data "template_file" "worker_role_arns" { } data "template_file" "config_map_aws_auth" { - count = var.create_cluster ? 1 : 0 + count = var.create_eks ? 1 : 0 template = file("${path.module}/templates/config-map-aws-auth.yaml.tpl") vars = { diff --git a/cluster.tf b/cluster.tf index 2f4c87c8..b7ced5c1 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 && var.create_cluster ? 1 : 0 + count = length(var.cluster_enabled_log_types) > 0 && var.create_eks ? 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 = var.create_cluster ? 1 : 0 + count = var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.cluster_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.cluster_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.cluster_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_cluster_iam_resources && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_cluster_iam_resources && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy" role = local.cluster_iam_role_name } diff --git a/data.tf b/data.tf index 4333c65e..2a598fbf 100644 --- a/data.tf +++ b/data.tf @@ -63,7 +63,7 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" { } data "template_file" "kubeconfig" { - count = var.create_cluster ? 1 : 0 + count = var.create_eks ? 1 : 0 template = file("${path.module}/templates/kubeconfig.tpl") vars = { diff --git a/kubectl.tf b/kubectl.tf index 6bbd0764..cf140ebb 100644 --- a/kubectl.tf +++ b/kubectl.tf @@ -1,5 +1,5 @@ resource "local_file" "kubeconfig" { - count = var.write_kubeconfig && var.create_cluster ? 1 : 0 + count = var.write_kubeconfig && var.create_eks ? 1 : 0 content = data.template_file.kubeconfig[0].rendered filename = "${substr(var.config_output_path, -1, 1) == "/" ? "${var.config_output_path}kubeconfig_${var.cluster_name}" : var.config_output_path}" } diff --git a/workers.tf b/workers.tf index f618c707..fe67ba65 100644 --- a/workers.tf +++ b/workers.tf @@ -1,7 +1,7 @@ # Worker Groups using Launch Configurations resource "aws_autoscaling_group" "workers" { - count = var.create_cluster ? local.worker_group_count : 0 + count = var.create_eks ? local.worker_group_count : 0 name_prefix = join( "-", compact( @@ -143,7 +143,7 @@ resource "aws_autoscaling_group" "workers" { } resource "aws_launch_configuration" "workers" { - count = var.create_cluster ? local.worker_group_count : 0 + count = var.create_eks ? local.worker_group_count : 0 name_prefix = "${aws_eks_cluster.this[count.index].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 = var.create_cluster ? local.worker_group_count : 0 + count = var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.worker_create_security_group && var.create_eks ? 1 : 0 name_prefix = aws_eks_cluster.this[count.index].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 && var.create_cluster ? 1 : 0 + count = var.worker_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.worker_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.worker_create_security_group && var.create_eks ? 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 && var.create_cluster ? var.worker_sg_ingress_from_port > 10250 ? 1 : 0 : 0 + count = var.worker_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.worker_create_security_group && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.create_eks ? 1 : 0 name_prefix = var.workers_role_name != "" ? null : aws_eks_cluster.this[count.index].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 && var.create_cluster ? local.worker_group_count : 0 + count = var.manage_worker_iam_resources && var.create_eks ? local.worker_group_count : 0 name_prefix = aws_eks_cluster.this[count.index].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 && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.attach_worker_cni_policy && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.create_eks ? 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 && var.create_cluster ? length(var.workers_additional_policies) : 0 + count = var.manage_worker_iam_resources && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.attach_worker_autoscaling_policy && var.create_eks ? 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 && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.create_eks ? 1 : 0 name_prefix = "eks-worker-autoscaling-${aws_eks_cluster.this[count.index].name}" description = "EKS worker node autoscaling policy for cluster ${aws_eks_cluster.this[count.index].name}" policy = data.aws_iam_policy_document.worker_autoscaling[0].json @@ -373,7 +373,7 @@ resource "aws_iam_policy" "worker_autoscaling" { } data "aws_iam_policy_document" "worker_autoscaling" { - count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.create_cluster ? 1 : 0 + count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.create_eks ? 1 : 0 statement { sid = "eksWorkerAutoscalingAll" effect = "Allow" diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 66851a1d..8cf3d673 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 = var.create_cluster ? local.worker_group_launch_template_count : 0 + count = var.create_eks ? local.worker_group_launch_template_count : 0 name_prefix = join( "-", compact( @@ -218,7 +218,7 @@ resource "aws_autoscaling_group" "workers_launch_template" { } resource "aws_launch_template" "workers_launch_template" { - count = var.create_cluster ? (local.worker_group_launch_template_count) : 0 + count = var.create_eks ? (local.worker_group_launch_template_count) : 0 name_prefix = "${aws_eks_cluster.this[count.index].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 = var.create_cluster ? local.worker_group_launch_template_count : 0 + count = var.create_eks ? local.worker_group_launch_template_count : 0 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 && var.create_cluster ? local.worker_group_launch_template_count : 0 + count = var.manage_worker_iam_resources && var.create_eks ? local.worker_group_launch_template_count : 0 name_prefix = aws_eks_cluster.this[count.index].name role = lookup( var.worker_groups_launch_template[count.index],