Skip to content

Commit

Permalink
Merge pull request #270 from mark5cinco/eks-cluster-encryption
Browse files Browse the repository at this point in the history
EKS: Enable specifying of KMS arn for cluster encryption
  • Loading branch information
pst authored Mar 1, 2022
2 parents f02567b + 96226cc commit feb1f71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aws/_modules/eks/master.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ resource "aws_eks_cluster" "current" {
public_access_cidrs = var.cluster_public_access_cidrs
}

dynamic "encryption_config" {
for_each = var.cluster_encryption_key_arn != null ? toset([1]) : toset([])
content {
resources = ["secrets"]

provider {
key_arn = var.cluster_encryption_key_arn
}
}
}

depends_on = [
aws_iam_role_policy_attachment.master_cluster_policy,
aws_iam_role_policy_attachment.master_service_policy,
Expand Down
6 changes: 6 additions & 0 deletions aws/_modules/eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ variable "cluster_public_access_cidrs" {
default = null
description = "List of CIDR blocks which can access the Amazon EKS public API server endpoint. EKS defaults this to a list with 0.0.0.0/0."
}

variable "cluster_encryption_key_arn" {
type = string
default = null
description = "Arn of an AWS KMS symmetric key to be used for encryption of kubernetes resources."
}
2 changes: 2 additions & 0 deletions aws/cluster/configuration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ locals {
cluster_endpoint_public_access = lookup(local.cfg, "cluster_endpoint_public_access", true)
cluster_public_access_cidrs_lookup = lookup(local.cfg, "cluster_public_access_cidrs", null)
cluster_public_access_cidrs = local.cluster_public_access_cidrs_lookup == null ? null : split(",", local.cluster_public_access_cidrs_lookup)

cluster_encryption_key_arn = lookup(local.cfg, "cluster_encryption_key_arn", null)
}
2 changes: 2 additions & 0 deletions aws/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module "cluster" {
cluster_endpoint_public_access = local.cluster_endpoint_public_access
cluster_public_access_cidrs = local.cluster_public_access_cidrs

cluster_encryption_key_arn = local.cluster_encryption_key_arn

# cluster module configuration is still map(string)
# once module_variable_optional_attrs isn't experimental anymore
# we can migrate cluster module configuration to map(object(...))
Expand Down

0 comments on commit feb1f71

Please sign in to comment.