1
0
mirror of https://github.com/terraform-aws-modules/terraform-aws-eks.git synced 2025-09-09 19:32:58 +08:00

Fix cluster count

This commit is contained in:
syst0m
2019-10-31 17:49:36 +00:00
committed by Tomislav Tomasic
parent 75248e97df
commit 83eadaadf7
5 changed files with 42 additions and 42 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ EOS
triggers = { triggers = {
kube_config_map_rendered = data.template_file.kubeconfig.rendered kube_config_map_rendered = data.template_file.kubeconfig.rendered
config_map_rendered = data.template_file.config_map_aws_auth.rendered config_map_rendered = data.template_file.config_map_aws_auth.rendered
endpoint = aws_eks_cluster.this.endpoint endpoint = aws_eks_cluster.this[count.index].endpoint
} }
} }
+9 -9
View File
@@ -67,15 +67,15 @@ data "template_file" "kubeconfig" {
vars = { vars = {
kubeconfig_name = local.kubeconfig_name kubeconfig_name = local.kubeconfig_name
endpoint = aws_eks_cluster.this.endpoint endpoint = aws_eks_cluster.this[0].endpoint
cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data
aws_authenticator_command = var.kubeconfig_aws_authenticator_command aws_authenticator_command = var.kubeconfig_aws_authenticator_command
aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? " - ${join( aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? " - ${join(
"\n - ", "\n - ",
var.kubeconfig_aws_authenticator_command_args, var.kubeconfig_aws_authenticator_command_args,
)}" : " - ${join( )}" : " - ${join(
"\n - ", "\n - ",
formatlist("\"%s\"", ["token", "-i", aws_eks_cluster.this.name]), formatlist("\"%s\"", ["token", "-i", aws_eks_cluster.this[0].name]),
)}" )}"
aws_authenticator_additional_args = length(var.kubeconfig_aws_authenticator_additional_args) > 0 ? " - ${join( aws_authenticator_additional_args = length(var.kubeconfig_aws_authenticator_additional_args) > 0 ? " - ${join(
"\n - ", "\n - ",
@@ -117,9 +117,9 @@ data "template_file" "userdata" {
vars = merge({ vars = merge({
platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"])
cluster_name = aws_eks_cluster.this.name cluster_name = aws_eks_cluster.this[count.index].name
endpoint = aws_eks_cluster.this.endpoint endpoint = aws_eks_cluster.this[count.index].endpoint
cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data cluster_auth_base64 = aws_eks_cluster.this[count.index].certificate_authority[0].data
pre_userdata = lookup( pre_userdata = lookup(
var.worker_groups[count.index], var.worker_groups[count.index],
"pre_userdata", "pre_userdata",
@@ -163,9 +163,9 @@ data "template_file" "launch_template_userdata" {
vars = merge({ vars = merge({
platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"])
cluster_name = aws_eks_cluster.this.name cluster_name = aws_eks_cluster.this[count.index].name
endpoint = aws_eks_cluster.this.endpoint endpoint = aws_eks_cluster.this[count.index].endpoint
cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data cluster_auth_base64 = aws_eks_cluster.this[count.index].certificate_authority[0].data
pre_userdata = lookup( pre_userdata = lookup(
var.worker_groups_launch_template[count.index], var.worker_groups_launch_template[count.index],
"pre_userdata", "pre_userdata",
+6 -6
View File
@@ -1,26 +1,26 @@
output "cluster_id" { output "cluster_id" {
description = "The name/id of the EKS cluster." description = "The name/id of the EKS cluster."
value = aws_eks_cluster.this.id value = element(concat(aws_eks_cluster.this.*.id, list("")), 0)
} }
output "cluster_arn" { output "cluster_arn" {
description = "The Amazon Resource Name (ARN) of the cluster." description = "The Amazon Resource Name (ARN) of the cluster."
value = aws_eks_cluster.this.arn value = element(concat(aws_eks_cluster.this.*.arn, list("")), 0)
} }
output "cluster_certificate_authority_data" { output "cluster_certificate_authority_data" {
description = "Nested attribute containing certificate-authority-data for your cluster. This is the base64 encoded certificate data required to communicate with your cluster." description = "Nested attribute containing certificate-authority-data for your cluster. This is the base64 encoded certificate data required to communicate with your cluster."
value = aws_eks_cluster.this.certificate_authority[0].data value = element(concat(aws_eks_cluster.this.*.certificate_authority[0].data, list("")), 0)
} }
output "cluster_endpoint" { output "cluster_endpoint" {
description = "The endpoint for your EKS Kubernetes API." description = "The endpoint for your EKS Kubernetes API."
value = aws_eks_cluster.this.endpoint value = element(concat(aws_eks_cluster.this.*.endpoint, list("")), 0)
} }
output "cluster_version" { output "cluster_version" {
description = "The Kubernetes server version for the EKS cluster." description = "The Kubernetes server version for the EKS cluster."
value = aws_eks_cluster.this.version value = element(concat(aws_eks_cluster.this.*.version, list("")), 0)
} }
output "cluster_security_group_id" { output "cluster_security_group_id" {
@@ -45,7 +45,7 @@ output "cluster_iam_role_arn" {
output "cluster_oidc_issuer_url" { output "cluster_oidc_issuer_url" {
description = "The URL on the EKS cluster OIDC Issuer" description = "The URL on the EKS cluster OIDC Issuer"
value = concat(aws_eks_cluster.this.identity.*.oidc.0.issuer, [""])[0] value = concat(aws_eks_cluster.this.0.identity.*.oidc.0.issuer, [""])[0]
} }
output "cloudwatch_log_group_name" { output "cloudwatch_log_group_name" {
+15 -15
View File
@@ -6,7 +6,7 @@ resource "aws_autoscaling_group" "workers" {
"-", "-",
compact( compact(
[ [
aws_eks_cluster.this.name, aws_eks_cluster.this[count.index].name,
lookup(var.worker_groups[count.index], "name", count.index), lookup(var.worker_groups[count.index], "name", count.index),
lookup(var.worker_groups[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers[count.index].id : "" lookup(var.worker_groups[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers[count.index].id : ""
] ]
@@ -91,16 +91,16 @@ resource "aws_autoscaling_group" "workers" {
[ [
{ {
"key" = "Name" "key" = "Name"
"value" = "${aws_eks_cluster.this.name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg" "value" = "${aws_eks_cluster.this[count.index].name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg"
"propagate_at_launch" = true "propagate_at_launch" = true
}, },
{ {
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this.name}" "key" = "kubernetes.io/cluster/${aws_eks_cluster.this[count.index].name}"
"value" = "owned" "value" = "owned"
"propagate_at_launch" = true "propagate_at_launch" = true
}, },
{ {
"key" = "k8s.io/cluster/${aws_eks_cluster.this.name}" "key" = "k8s.io/cluster/${aws_eks_cluster.this[count.index].name}"
"value" = "owned" "value" = "owned"
"propagate_at_launch" = true "propagate_at_launch" = true
}, },
@@ -114,8 +114,8 @@ resource "aws_autoscaling_group" "workers" {
"propagate_at_launch" = false "propagate_at_launch" = false
}, },
{ {
"key" = "k8s.io/cluster-autoscaler/${aws_eks_cluster.this.name}" "key" = "k8s.io/cluster-autoscaler/${aws_eks_cluster.this[count.index].name}"
"value" = aws_eks_cluster.this.name "value" = aws_eks_cluster.this[count.index].name
"propagate_at_launch" = false "propagate_at_launch" = false
}, },
{ {
@@ -144,7 +144,7 @@ resource "aws_autoscaling_group" "workers" {
resource "aws_launch_configuration" "workers" { resource "aws_launch_configuration" "workers" {
count = var.enabled ? local.worker_group_count : 0 count = var.enabled ? local.worker_group_count : 0
name_prefix = "${aws_eks_cluster.this.name}-${lookup(var.worker_groups[count.index], "name", count.index)}" name_prefix = "${aws_eks_cluster.this[count.index].name}-${lookup(var.worker_groups[count.index], "name", count.index)}"
associate_public_ip_address = lookup( associate_public_ip_address = lookup(
var.worker_groups[count.index], var.worker_groups[count.index],
"public_ip", "public_ip",
@@ -244,14 +244,14 @@ resource "random_pet" "workers" {
resource "aws_security_group" "workers" { resource "aws_security_group" "workers" {
count = var.worker_create_security_group && var.enabled ? 1 : 0 count = var.worker_create_security_group && var.enabled ? 1 : 0
name_prefix = aws_eks_cluster.this.name name_prefix = aws_eks_cluster.this[count.index].name
description = "Security group for all nodes in the cluster." description = "Security group for all nodes in the cluster."
vpc_id = var.vpc_id vpc_id = var.vpc_id
tags = merge( tags = merge(
var.tags, var.tags,
{ {
"Name" = "${aws_eks_cluster.this.name}-eks_worker_sg" "Name" = "${aws_eks_cluster.this[count.index].name}-eks_worker_sg"
"kubernetes.io/cluster/${aws_eks_cluster.this.name}" = "owned" "kubernetes.io/cluster/${aws_eks_cluster.this[count.index].name}" = "owned"
}, },
) )
} }
@@ -313,7 +313,7 @@ resource "aws_security_group_rule" "workers_ingress_cluster_https" {
resource "aws_iam_role" "workers" { resource "aws_iam_role" "workers" {
count = var.manage_worker_iam_resources && var.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_prefix = var.workers_role_name != "" ? null : aws_eks_cluster.this[count.index].name
name = var.workers_role_name != "" ? var.workers_role_name : null name = var.workers_role_name != "" ? var.workers_role_name : null
assume_role_policy = data.aws_iam_policy_document.workers_assume_role_policy.json assume_role_policy = data.aws_iam_policy_document.workers_assume_role_policy.json
permissions_boundary = var.permissions_boundary permissions_boundary = var.permissions_boundary
@@ -324,7 +324,7 @@ resource "aws_iam_role" "workers" {
resource "aws_iam_instance_profile" "workers" { resource "aws_iam_instance_profile" "workers" {
count = var.manage_worker_iam_resources && var.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 name_prefix = aws_eks_cluster.this[count.index].name
role = lookup( role = lookup(
var.worker_groups[count.index], var.worker_groups[count.index],
"iam_role_id", "iam_role_id",
@@ -366,8 +366,8 @@ resource "aws_iam_role_policy_attachment" "workers_autoscaling" {
resource "aws_iam_policy" "worker_autoscaling" { resource "aws_iam_policy" "worker_autoscaling" {
count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.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}" name_prefix = "eks-worker-autoscaling-${aws_eks_cluster.this[count.index].name}"
description = "EKS worker node autoscaling policy for cluster ${aws_eks_cluster.this.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.json
path = var.iam_path path = var.iam_path
} }
@@ -402,7 +402,7 @@ data "aws_iam_policy_document" "worker_autoscaling" {
condition { condition {
test = "StringEquals" test = "StringEquals"
variable = "autoscaling:ResourceTag/kubernetes.io/cluster/${aws_eks_cluster.this.name}" variable = "autoscaling:ResourceTag/kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
values = ["owned"] values = ["owned"]
} }
+11 -11
View File
@@ -1,12 +1,12 @@
# Worker Groups using Launch Templates # Worker Groups using Launch Templates
resource "aws_autoscaling_group" "workers_launch_template" { resource "aws_autoscaling_group" "workers_launch_template" {
count = (local.worker_group_launch_template_count * var.enabled) count = var.enabled ? local.worker_group_launch_template_count : 0
name_prefix = join( name_prefix = join(
"-", "-",
compact( compact(
[ [
aws_eks_cluster.this.name, aws_eks_cluster.this[count.index].name,
lookup(var.worker_groups_launch_template[count.index], "name", count.index), lookup(var.worker_groups_launch_template[count.index], "name", count.index),
lookup(var.worker_groups_launch_template[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers_launch_template[count.index].id : "" lookup(var.worker_groups_launch_template[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers_launch_template[count.index].id : ""
] ]
@@ -167,7 +167,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
[ [
{ {
"key" = "Name" "key" = "Name"
"value" = "${aws_eks_cluster.this.name}-${lookup( "value" = "${aws_eks_cluster.this[count.index].name}-${lookup(
var.worker_groups_launch_template[count.index], var.worker_groups_launch_template[count.index],
"name", "name",
count.index, count.index,
@@ -175,7 +175,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
"propagate_at_launch" = true "propagate_at_launch" = true
}, },
{ {
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this.name}" "key" = "kubernetes.io/cluster/${aws_eks_cluster.this[count.index].name}"
"value" = "owned" "value" = "owned"
"propagate_at_launch" = true "propagate_at_launch" = true
}, },
@@ -189,8 +189,8 @@ resource "aws_autoscaling_group" "workers_launch_template" {
"propagate_at_launch" = false "propagate_at_launch" = false
}, },
{ {
"key" = "k8s.io/cluster-autoscaler/${aws_eks_cluster.this.name}" "key" = "k8s.io/cluster-autoscaler/${aws_eks_cluster.this[count.index].name}"
"value" = aws_eks_cluster.this.name "value" = aws_eks_cluster.this[count.index].name
"propagate_at_launch" = false "propagate_at_launch" = false
}, },
{ {
@@ -218,8 +218,8 @@ resource "aws_autoscaling_group" "workers_launch_template" {
} }
resource "aws_launch_template" "workers_launch_template" { resource "aws_launch_template" "workers_launch_template" {
count = (local.worker_group_launch_template_count * var.enabled) count = var.enabled ? (local.worker_group_launch_template_count) : 0
name_prefix = "${aws_eks_cluster.this.name}-${lookup( name_prefix = "${aws_eks_cluster.this[count.index].name}-${lookup(
var.worker_groups_launch_template[count.index], var.worker_groups_launch_template[count.index],
"name", "name",
count.index, count.index,
@@ -364,7 +364,7 @@ resource "aws_launch_template" "workers_launch_template" {
tags = merge( tags = merge(
{ {
"Name" = "${aws_eks_cluster.this.name}-${lookup( "Name" = "${aws_eks_cluster.this[count.index].name}-${lookup(
var.worker_groups_launch_template[count.index], var.worker_groups_launch_template[count.index],
"name", "name",
count.index, count.index,
@@ -382,7 +382,7 @@ resource "aws_launch_template" "workers_launch_template" {
} }
resource "random_pet" "workers_launch_template" { resource "random_pet" "workers_launch_template" {
count = (local.worker_group_launch_template_count * var.enabled) count = var.enabled ? local.worker_group_launch_template_count : 0
separator = "-" separator = "-"
length = 2 length = 2
@@ -402,7 +402,7 @@ resource "random_pet" "workers_launch_template" {
resource "aws_iam_instance_profile" "workers_launch_template" { resource "aws_iam_instance_profile" "workers_launch_template" {
count = var.manage_worker_iam_resources ? (local.worker_group_launch_template_count * var.enabled) : 0 count = var.manage_worker_iam_resources ? (local.worker_group_launch_template_count * var.enabled) : 0
name_prefix = aws_eks_cluster.this.name name_prefix = aws_eks_cluster.this[count.index].name
role = lookup( role = lookup(
var.worker_groups_launch_template[count.index], var.worker_groups_launch_template[count.index],
"iam_role_id", "iam_role_id",