Skip to content

Commit 9af0c24

Browse files
authored
fix: Add support for overriding DNS suffix for cluster IAM role service principal endpoint (#1905)
1 parent 9a99689 commit 9af0c24

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ Full contributing [guidelines are covered here](https://github.com/terraform-aws
855855
| <a name="input_cluster_endpoint_private_access"></a> [cluster\_endpoint\_private\_access](#input\_cluster\_endpoint\_private\_access) | Indicates whether or not the Amazon EKS private API server endpoint is enabled | `bool` | `false` | no |
856856
| <a name="input_cluster_endpoint_public_access"></a> [cluster\_endpoint\_public\_access](#input\_cluster\_endpoint\_public\_access) | Indicates whether or not the Amazon EKS public API server endpoint is enabled | `bool` | `true` | no |
857857
| <a name="input_cluster_endpoint_public_access_cidrs"></a> [cluster\_endpoint\_public\_access\_cidrs](#input\_cluster\_endpoint\_public\_access\_cidrs) | List of CIDR blocks which can access the Amazon EKS public API server endpoint | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
858+
| <a name="input_cluster_iam_role_dns_suffix"></a> [cluster\_iam\_role\_dns\_suffix](#input\_cluster\_iam\_role\_dns\_suffix) | Base DNS domain name for the current partition (e.g., amazonaws.com in AWS Commercial, amazonaws.com.cn in AWS China) | `string` | `null` | no |
858859
| <a name="input_cluster_identity_providers"></a> [cluster\_identity\_providers](#input\_cluster\_identity\_providers) | Map of cluster identity provider configurations to enable for the cluster. Note - this is different/separate from IRSA | `any` | `{}` | no |
859860
| <a name="input_cluster_ip_family"></a> [cluster\_ip\_family](#input\_cluster\_ip\_family) | The IP family used to assign Kubernetes pod and service addresses. Valid values are `ipv4` (default) and `ipv6`. You can only specify an IP family when you create a cluster, changing this value will force a new cluster to be created | `string` | `null` | no |
860861
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the EKS cluster | `string` | `""` | no |

examples/eks_managed_node_group/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ module "eks" {
8989
instance_types = ["m6i.large", "m5.large", "m5n.large", "m5zn.large"]
9090

9191
# We are using the IRSA created below for permissions
92-
iam_role_attach_cni_policy = false
92+
# However, we have to deploy with the policy attached FIRST (when creating a fresh cluster)
93+
# and then turn this off after the cluster/node group is created. Without this initial policy,
94+
# the VPC CNI fails to assign IPs and nodes cannot join the cluster
95+
# See https://github.com/aws/containers-roadmap/issues/1666 for more context
96+
iam_role_attach_cni_policy = true
9397
}
9498

9599
eks_managed_node_groups = {

main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ resource "aws_iam_openid_connect_provider" "oidc_provider" {
172172
locals {
173173
iam_role_name = coalesce(var.iam_role_name, "${var.cluster_name}-cluster")
174174
policy_arn_prefix = "arn:${data.aws_partition.current.partition}:iam::aws:policy"
175+
176+
# TODO - hopefully this can be removed once the AWS endpoint is named properly in China
177+
# https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1904
178+
dns_suffix = coalesce(var.cluster_iam_role_dns_suffix, data.aws_partition.current.dns_suffix)
175179
}
176180

177181
data "aws_iam_policy_document" "assume_role_policy" {
@@ -183,7 +187,7 @@ data "aws_iam_policy_document" "assume_role_policy" {
183187

184188
principals {
185189
type = "Service"
186-
identifiers = ["eks.${data.aws_partition.current.dns_suffix}"]
190+
identifiers = ["eks.${local.dns_suffix}"]
187191
}
188192
}
189193
}

variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ variable "iam_role_additional_policies" {
305305
default = []
306306
}
307307

308+
# TODO - hopefully this can be removed once the AWS endpoint is named properly in China
309+
# https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1904
310+
variable "cluster_iam_role_dns_suffix" {
311+
description = "Base DNS domain name for the current partition (e.g., amazonaws.com in AWS Commercial, amazonaws.com.cn in AWS China)"
312+
type = string
313+
default = null
314+
}
315+
308316
variable "iam_role_tags" {
309317
description = "A map of additional tags to add to the IAM role created"
310318
type = map(string)

0 commit comments

Comments
 (0)