Skip to content

Commit 2df1572

Browse files
authored
feat: Add variables to allow users to control attributes on cluster_encryption IAM policy (terraform-aws-modules#1928)
1 parent 27f99f0 commit 2df1572

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,11 @@ Full contributing [guidelines are covered here](https://github.com/terraform-aws
855855
| <a name="input_cluster_addons"></a> [cluster\_addons](#input\_cluster\_addons) | Map of cluster addon configurations to enable for the cluster. Addon name can be the map keys or set with `name` | `any` | `{}` | no |
856856
| <a name="input_cluster_enabled_log_types"></a> [cluster\_enabled\_log\_types](#input\_cluster\_enabled\_log\_types) | A list of the desired control plane logs to enable. For more information, see Amazon EKS Control Plane Logging documentation (https://docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html) | `list(string)` | <pre>[<br> "audit",<br> "api",<br> "authenticator"<br>]</pre> | no |
857857
| <a name="input_cluster_encryption_config"></a> [cluster\_encryption\_config](#input\_cluster\_encryption\_config) | Configuration block with encryption configuration for the cluster | <pre>list(object({<br> provider_key_arn = string<br> resources = list(string)<br> }))</pre> | `[]` | no |
858+
| <a name="input_cluster_encryption_policy_description"></a> [cluster\_encryption\_policy\_description](#input\_cluster\_encryption\_policy\_description) | Description of the cluster encryption policy created | `string` | `"Cluster encryption policy to allow cluster role to utilize CMK provided"` | no |
859+
| <a name="input_cluster_encryption_policy_name"></a> [cluster\_encryption\_policy\_name](#input\_cluster\_encryption\_policy\_name) | Name to use on cluster encryption policy created | `string` | `null` | no |
860+
| <a name="input_cluster_encryption_policy_path"></a> [cluster\_encryption\_policy\_path](#input\_cluster\_encryption\_policy\_path) | Cluster encryption policy path | `string` | `null` | no |
861+
| <a name="input_cluster_encryption_policy_tags"></a> [cluster\_encryption\_policy\_tags](#input\_cluster\_encryption\_policy\_tags) | A map of additional tags to add to the cluster encryption policy created | `map(string)` | `{}` | no |
862+
| <a name="input_cluster_encryption_policy_use_name_prefix"></a> [cluster\_encryption\_policy\_use\_name\_prefix](#input\_cluster\_encryption\_policy\_use\_name\_prefix) | Determines whether cluster encryption policy name (`cluster_encryption_policy_name`) is used as a prefix | `string` | `true` | no |
858863
| <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 |
859864
| <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 |
860865
| <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 |

main.tf

+8-5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ locals {
174174
iam_role_name = coalesce(var.iam_role_name, "${var.cluster_name}-cluster")
175175
policy_arn_prefix = "arn:${data.aws_partition.current.partition}:iam::aws:policy"
176176

177+
cluster_encryption_policy_name = coalesce(var.cluster_encryption_policy_name, "${local.iam_role_name}-ClusterEncryption")
178+
177179
# TODO - hopefully this can be removed once the AWS endpoint is named properly in China
178180
# https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1904
179181
dns_suffix = coalesce(var.cluster_iam_role_dns_suffix, data.aws_partition.current.dns_suffix)
@@ -230,8 +232,10 @@ resource "aws_iam_role_policy_attachment" "cluster_encryption" {
230232
resource "aws_iam_policy" "cluster_encryption" {
231233
count = local.create_iam_role && var.attach_cluster_encryption_policy && length(var.cluster_encryption_config) > 0 ? 1 : 0
232234

233-
name_prefix = "${local.iam_role_name}-ClusterEncryption-"
234-
description = "Cluster encryption policy to allow cluster role to utilize CMK provided"
235+
name = var.cluster_encryption_policy_use_name_prefix ? null : local.cluster_encryption_policy_name
236+
name_prefix = var.cluster_encryption_policy_use_name_prefix ? local.cluster_encryption_policy_name : null
237+
description = var.cluster_encryption_policy_description
238+
path = var.cluster_encryption_policy_path
235239

236240
policy = jsonencode({
237241
Version = "2012-10-17"
@@ -243,14 +247,13 @@ resource "aws_iam_policy" "cluster_encryption" {
243247
"kms:ListGrants",
244248
"kms:DescribeKey",
245249
]
246-
Effect = "Allow"
247-
# TODO - does cluster_encryption_config need to be a list?!
250+
Effect = "Allow"
248251
Resource = [for config in var.cluster_encryption_config : config.provider_key_arn]
249252
},
250253
]
251254
})
252255

253-
tags = var.tags
256+
tags = merge(var.tags, var.cluster_encryption_policy_tags)
254257
}
255258

256259
################################################################################

variables.tf

+30
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,36 @@ variable "iam_role_tags" {
325325
default = {}
326326
}
327327

328+
variable "cluster_encryption_policy_use_name_prefix" {
329+
description = "Determines whether cluster encryption policy name (`cluster_encryption_policy_name`) is used as a prefix"
330+
type = string
331+
default = true
332+
}
333+
334+
variable "cluster_encryption_policy_name" {
335+
description = "Name to use on cluster encryption policy created"
336+
type = string
337+
default = null
338+
}
339+
340+
variable "cluster_encryption_policy_description" {
341+
description = "Description of the cluster encryption policy created"
342+
type = string
343+
default = "Cluster encryption policy to allow cluster role to utilize CMK provided"
344+
}
345+
346+
variable "cluster_encryption_policy_path" {
347+
description = "Cluster encryption policy path"
348+
type = string
349+
default = null
350+
}
351+
352+
variable "cluster_encryption_policy_tags" {
353+
description = "A map of additional tags to add to the cluster encryption policy created"
354+
type = map(string)
355+
default = {}
356+
}
357+
328358
################################################################################
329359
# EKS Addons
330360
################################################################################

0 commit comments

Comments
 (0)