mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-01-19 01:57:35 +01:00
fix: Use splat syntax to avoid errors during destroy with an empty state (#1041)
This commit is contained in:
committed by
GitHub
parent
c75fbb0164
commit
d97edde9cd
@@ -1,5 +1,4 @@
|
||||
data "aws_caller_identity" "current" {
|
||||
}
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
locals {
|
||||
auth_launch_template_worker_roles = [
|
||||
|
||||
@@ -64,7 +64,7 @@ resource "null_resource" "wait_for_cluster" {
|
||||
count = var.create_eks && var.manage_aws_auth ? 1 : 0
|
||||
|
||||
depends_on = [
|
||||
aws_eks_cluster.this[0],
|
||||
aws_eks_cluster.this,
|
||||
aws_security_group_rule.cluster_private_access,
|
||||
]
|
||||
|
||||
|
||||
6
local.tf
6
local.tf
@@ -146,10 +146,10 @@ locals {
|
||||
|
||||
kubeconfig = var.create_eks ? templatefile("${path.module}/templates/kubeconfig.tpl", {
|
||||
kubeconfig_name = local.kubeconfig_name
|
||||
endpoint = aws_eks_cluster.this[0].endpoint
|
||||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data
|
||||
endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0]
|
||||
cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0]
|
||||
aws_authenticator_command = var.kubeconfig_aws_authenticator_command
|
||||
aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? var.kubeconfig_aws_authenticator_command_args : ["token", "-i", aws_eks_cluster.this[0].name]
|
||||
aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? var.kubeconfig_aws_authenticator_command_args : ["token", "-i", coalescelist(aws_eks_cluster.this[*].name, [""])[0]]
|
||||
aws_authenticator_additional_args = var.kubeconfig_aws_authenticator_additional_args
|
||||
aws_authenticator_env_variables = var.kubeconfig_aws_authenticator_env_variables
|
||||
}) : ""
|
||||
|
||||
15
workers.tf
15
workers.tf
@@ -6,7 +6,7 @@ resource "aws_autoscaling_group" "workers" {
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_eks_cluster.this[0].name,
|
||||
coalescelist(aws_eks_cluster.this[*].name, [""])[0],
|
||||
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 : ""
|
||||
]
|
||||
@@ -112,16 +112,16 @@ resource "aws_autoscaling_group" "workers" {
|
||||
[
|
||||
{
|
||||
"key" = "Name"
|
||||
"value" = "${aws_eks_cluster.this[0].name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg"
|
||||
"value" = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg"
|
||||
"propagate_at_launch" = true
|
||||
},
|
||||
{
|
||||
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
|
||||
"key" = "kubernetes.io/cluster/${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}"
|
||||
"value" = "owned"
|
||||
"propagate_at_launch" = true
|
||||
},
|
||||
{
|
||||
"key" = "k8s.io/cluster/${aws_eks_cluster.this[0].name}"
|
||||
"key" = "k8s.io/cluster/${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}"
|
||||
"value" = "owned"
|
||||
"propagate_at_launch" = true
|
||||
},
|
||||
@@ -148,7 +148,7 @@ resource "aws_autoscaling_group" "workers" {
|
||||
|
||||
resource "aws_launch_configuration" "workers" {
|
||||
count = var.create_eks ? local.worker_group_count : 0
|
||||
name_prefix = "${aws_eks_cluster.this[0].name}-${lookup(var.worker_groups[count.index], "name", count.index)}"
|
||||
name_prefix = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup(var.worker_groups[count.index], "name", count.index)}"
|
||||
associate_public_ip_address = lookup(
|
||||
var.worker_groups[count.index],
|
||||
"public_ip",
|
||||
@@ -262,7 +262,6 @@ resource "aws_launch_configuration" "workers" {
|
||||
)
|
||||
delete_on_termination = lookup(ebs_block_device.value, "delete_on_termination", true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
@@ -394,7 +393,7 @@ resource "aws_security_group_rule" "cluster_primary_ingress_workers" {
|
||||
|
||||
resource "aws_iam_role" "workers" {
|
||||
count = var.manage_worker_iam_resources && var.create_eks ? 1 : 0
|
||||
name_prefix = var.workers_role_name != "" ? null : aws_eks_cluster.this[0].name
|
||||
name_prefix = var.workers_role_name != "" ? null : coalescelist(aws_eks_cluster.this[*].name, [""])[0]
|
||||
name = var.workers_role_name != "" ? var.workers_role_name : null
|
||||
assume_role_policy = data.aws_iam_policy_document.workers_assume_role_policy.json
|
||||
permissions_boundary = var.permissions_boundary
|
||||
@@ -405,7 +404,7 @@ resource "aws_iam_role" "workers" {
|
||||
|
||||
resource "aws_iam_instance_profile" "workers" {
|
||||
count = var.manage_worker_iam_resources && var.create_eks ? local.worker_group_count : 0
|
||||
name_prefix = aws_eks_cluster.this[0].name
|
||||
name_prefix = coalescelist(aws_eks_cluster.this[*].name, [""])[0]
|
||||
role = lookup(
|
||||
var.worker_groups[count.index],
|
||||
"iam_role_id",
|
||||
|
||||
@@ -6,7 +6,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_eks_cluster.this[0].name,
|
||||
coalescelist(aws_eks_cluster.this[*].name, [""])[0],
|
||||
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 : ""
|
||||
]
|
||||
@@ -189,7 +189,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
|
||||
[
|
||||
{
|
||||
"key" = "Name"
|
||||
"value" = "${aws_eks_cluster.this[0].name}-${lookup(
|
||||
"value" = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"name",
|
||||
count.index,
|
||||
@@ -197,7 +197,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
|
||||
"propagate_at_launch" = true
|
||||
},
|
||||
{
|
||||
"key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}"
|
||||
"key" = "kubernetes.io/cluster/${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}"
|
||||
"value" = "owned"
|
||||
"propagate_at_launch" = true
|
||||
},
|
||||
@@ -224,7 +224,7 @@ resource "aws_autoscaling_group" "workers_launch_template" {
|
||||
|
||||
resource "aws_launch_template" "workers_launch_template" {
|
||||
count = var.create_eks ? (local.worker_group_launch_template_count) : 0
|
||||
name_prefix = "${aws_eks_cluster.this[0].name}-${lookup(
|
||||
name_prefix = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"name",
|
||||
count.index,
|
||||
@@ -427,7 +427,7 @@ resource "aws_launch_template" "workers_launch_template" {
|
||||
|
||||
tags = merge(
|
||||
{
|
||||
"Name" = "${aws_eks_cluster.this[0].name}-${lookup(
|
||||
"Name" = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"name",
|
||||
count.index,
|
||||
@@ -442,7 +442,7 @@ resource "aws_launch_template" "workers_launch_template" {
|
||||
|
||||
tags = merge(
|
||||
{
|
||||
"Name" = "${aws_eks_cluster.this[0].name}-${lookup(
|
||||
"Name" = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"name",
|
||||
count.index,
|
||||
@@ -500,7 +500,7 @@ resource "random_pet" "workers_launch_template" {
|
||||
|
||||
resource "aws_iam_instance_profile" "workers_launch_template" {
|
||||
count = var.manage_worker_iam_resources && var.create_eks ? local.worker_group_launch_template_count : 0
|
||||
name_prefix = aws_eks_cluster.this[0].name
|
||||
name_prefix = coalescelist(aws_eks_cluster.this[*].name, [""])[0]
|
||||
role = lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"iam_role_id",
|
||||
|
||||
Reference in New Issue
Block a user