diff --git a/CHANGELOG.md b/CHANGELOG.md index fb88268..a248bba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/). - Fix doc about spot instances, cluster-autoscaler should be scheduled on normal instances instead of spot (by @simowaer) - Adding `encrypted` option to worker's root_block_device as read from the worker configurations (by @craig-rueda) +- Use correct policy arns for CN regions (cn-north-1, cn-northwest-1) (by @cofyc) # History diff --git a/cluster.tf b/cluster.tf index c5439ad..a327e92 100644 --- a/cluster.tf +++ b/cluster.tf @@ -96,12 +96,12 @@ resource "aws_iam_role" "cluster" { resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSClusterPolicy" { count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 - policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" + policy_arn = "${local.policy_arn_prefix}/AmazonEKSClusterPolicy" role = local.cluster_iam_role_name } resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSServicePolicy" { count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 - policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy" + policy_arn = "${local.policy_arn_prefix}/AmazonEKSServicePolicy" role = local.cluster_iam_role_name } diff --git a/data.tf b/data.tf index f43ac9e..d945c52 100644 --- a/data.tf +++ b/data.tf @@ -221,3 +221,5 @@ data "aws_iam_instance_profile" "custom_worker_group_launch_template_iam_instanc local.workers_group_defaults["iam_instance_profile_name"], ) } + +data "aws_region" "current" {} diff --git a/local.tf b/local.tf index 8ed32f8..a959cc3 100644 --- a/local.tf +++ b/local.tf @@ -22,6 +22,7 @@ locals { default_ami_id_linux = data.aws_ami.eks_worker.id default_ami_id_windows = data.aws_ami.eks_worker_windows.id + policy_arn_prefix = contains(["cn-northwest-1", "cn-north-1"], data.aws_region.current.name) ? "arn:aws-cn:iam::aws:policy" : "arn:aws:iam::aws:policy" workers_group_defaults_defaults = { name = "count.index" # Name of the worker group. Literal count.index will never be used but if name is not set, the count.index interpolation will be used. tags = [] # A list of map defining extra tags to be applied to the worker group autoscaling group. diff --git a/workers.tf b/workers.tf index 4c1a6a0..c198c5b 100644 --- a/workers.tf +++ b/workers.tf @@ -318,19 +318,19 @@ resource "aws_iam_instance_profile" "workers" { resource "aws_iam_role_policy_attachment" "workers_AmazonEKSWorkerNodePolicy" { count = var.manage_worker_iam_resources && var.create_eks ? 1 : 0 - policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy" + policy_arn = "${local.policy_arn_prefix}/AmazonEKSWorkerNodePolicy" role = aws_iam_role.workers[0].name } resource "aws_iam_role_policy_attachment" "workers_AmazonEKS_CNI_Policy" { count = var.manage_worker_iam_resources && var.attach_worker_cni_policy && var.create_eks ? 1 : 0 - policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" + policy_arn = "${local.policy_arn_prefix}/AmazonEKS_CNI_Policy" role = aws_iam_role.workers[0].name } resource "aws_iam_role_policy_attachment" "workers_AmazonEC2ContainerRegistryReadOnly" { count = var.manage_worker_iam_resources && var.create_eks ? 1 : 0 - policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" + policy_arn = "${local.policy_arn_prefix}/AmazonEC2ContainerRegistryReadOnly" role = aws_iam_role.workers[0].name }