From 880fd427a4046c30d349ee127a6904be438d39a7 Mon Sep 17 00:00:00 2001 From: syst0m Date: Thu, 7 Nov 2019 17:52:25 +0000 Subject: [PATCH] Fix errors manifesting when used on an existing-cluster --- aws_auth.tf | 7 ++++--- data.tf | 1 + kubectl.tf | 2 +- outputs.tf | 4 ++-- workers.tf | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/aws_auth.tf b/aws_auth.tf index dab6030e..077416c5 100644 --- a/aws_auth.tf +++ b/aws_auth.tf @@ -1,6 +1,6 @@ resource "local_file" "config_map_aws_auth" { count = var.write_aws_auth_config && var.enabled ? 1 : 0 - content = data.template_file.config_map_aws_auth.rendered + content = data.template_file.config_map_aws_auth[0].rendered filename = "${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml" } @@ -26,8 +26,8 @@ EOS } triggers = { - kube_config_map_rendered = data.template_file.kubeconfig.rendered - config_map_rendered = data.template_file.config_map_aws_auth.rendered + kube_config_map_rendered = data.template_file.kubeconfig[0].rendered + config_map_rendered = data.template_file.config_map_aws_auth[0].rendered endpoint = aws_eks_cluster.this[count.index].endpoint } } @@ -77,6 +77,7 @@ data "template_file" "worker_role_arns" { } data "template_file" "config_map_aws_auth" { + count = var.enabled ? 1 : 0 template = file("${path.module}/templates/config-map-aws-auth.yaml.tpl") vars = { diff --git a/data.tf b/data.tf index b1e9cd9d..53972fde 100644 --- a/data.tf +++ b/data.tf @@ -63,6 +63,7 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" { } data "template_file" "kubeconfig" { + count = var.enabled ? 1 : 0 template = file("${path.module}/templates/kubeconfig.tpl") vars = { diff --git a/kubectl.tf b/kubectl.tf index 41708ec4..4f8b20bb 100644 --- a/kubectl.tf +++ b/kubectl.tf @@ -1,5 +1,5 @@ resource "local_file" "kubeconfig" { count = var.write_kubeconfig && var.enabled ? 1 : 0 - content = data.template_file.kubeconfig.rendered + 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/outputs.tf b/outputs.tf index e6f5e8ed..9f6efa11 100644 --- a/outputs.tf +++ b/outputs.tf @@ -30,7 +30,7 @@ output "cluster_security_group_id" { output "config_map_aws_auth" { description = "A kubernetes configuration to authenticate to this EKS cluster." - value = data.template_file.config_map_aws_auth.rendered + value = concat(data.template_file.config_map_aws_auth[*].rendered, [""])[0] } output "cluster_iam_role_name" { @@ -55,7 +55,7 @@ output "cloudwatch_log_group_name" { output "kubeconfig" { description = "kubectl config file contents for this EKS cluster." - value = data.template_file.kubeconfig.rendered + value = concat(data.template_file.kubeconfig[*].rendered, [""])[0] } output "kubeconfig_filename" { diff --git a/workers.tf b/workers.tf index a0eb1a61..aff4cdca 100644 --- a/workers.tf +++ b/workers.tf @@ -368,11 +368,12 @@ resource "aws_iam_policy" "worker_autoscaling" { count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.enabled ? 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.json + policy = data.aws_iam_policy_document.worker_autoscaling[0].json path = var.iam_path } data "aws_iam_policy_document" "worker_autoscaling" { + count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.enabled ? 1 : 0 statement { sid = "eksWorkerAutoscalingAll" effect = "Allow"