locals { worker_ami_name_filter = var.worker_ami_name_filter != "" ? var.worker_ami_name_filter : "amazon-eks-node-${var.cluster_version}-v*" worker_ami_name_filter_windows = var.worker_ami_name_filter_windows != "" ? var.worker_ami_name_filter_windows : "Windows_Server-2019-English-Core-EKS_Optimized-${var.cluster_version}-*" } data "aws_iam_policy_document" "workers_assume_role_policy" { statement { sid = "EKSWorkerAssumeRole" actions = [ "sts:AssumeRole", ] principals { type = "Service" identifiers = ["ec2.amazonaws.com"] } } } data "aws_ami" "eks_worker" { filter { name = "name" values = [local.worker_ami_name_filter] } most_recent = true owners = [var.worker_ami_owner_id] } data "aws_ami" "eks_worker_windows" { filter { name = "name" values = [local.worker_ami_name_filter_windows] } filter { name = "platform" values = ["windows"] } most_recent = true # Owner ID of AWS EKS team (windows) owners = [var.worker_ami_owner_id_windows] } data "aws_iam_policy_document" "cluster_assume_role_policy" { statement { sid = "EKSClusterAssumeRole" actions = [ "sts:AssumeRole", ] principals { type = "Service" identifiers = ["eks.amazonaws.com"] } } } data "template_file" "kubeconfig" { template = file("${path.module}/templates/kubeconfig.tpl") vars = { kubeconfig_name = local.kubeconfig_name endpoint = aws_eks_cluster.this.endpoint cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data aws_authenticator_command = var.kubeconfig_aws_authenticator_command aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? " - ${join( "\n - ", var.kubeconfig_aws_authenticator_command_args, )}" : " - ${join( "\n - ", formatlist("\"%s\"", ["token", "-i", aws_eks_cluster.this.name]), )}" aws_authenticator_additional_args = length(var.kubeconfig_aws_authenticator_additional_args) > 0 ? " - ${join( "\n - ", var.kubeconfig_aws_authenticator_additional_args, )}" : "" aws_authenticator_env_variables = length(var.kubeconfig_aws_authenticator_env_variables) > 0 ? " env:\n${join( "\n", data.template_file.aws_authenticator_env_variables.*.rendered, )}" : "" } } data "template_file" "aws_authenticator_env_variables" { count = length(var.kubeconfig_aws_authenticator_env_variables) template = <