-
Notifications
You must be signed in to change notification settings - Fork 9
/
kms.tf
60 lines (58 loc) · 1.86 KB
/
kms.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
data "aws_iam_policy_document" "cloudwatch" {
policy_id = "key-policy-cloudwatch"
statement {
sid = "Enable IAM User Permissions"
actions = [
"kms:*",
]
effect = "Allow"
principals {
type = "AWS"
identifiers = [
format(
"arn:%s:iam::%s:root",
data.aws_partition.current.partition,
data.aws_caller_identity.current.account_id
)
]
}
resources = ["*"]
}
statement {
sid = "AllowCloudWatchLogs"
actions = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
effect = "Allow"
principals {
type = "Service"
identifiers = [
format(
"logs.%s.amazonaws.com",
data.aws_region.current.name
)
]
}
resources = ["*"]
}
}
resource "aws_kms_key" "cluster" {
count = var.enabled && var.cluster_encryption_config_enabled ? 1 : 0
description = "EKS Cluster ${module.labels.id} Encryption Config KMS Key"
enable_key_rotation = var.cluster_encryption_config_kms_key_enable_key_rotation
deletion_window_in_days = var.cluster_encryption_config_kms_key_deletion_window_in_days
policy = var.cluster_encryption_config_kms_key_policy
tags = module.labels.tags
}
resource "aws_kms_key" "cloudwatch_log" {
count = var.enabled && var.cluster_encryption_config_enabled ? 1 : 0
description = "CloudWatch log group ${module.labels.id} Encryption Config KMS Key"
enable_key_rotation = var.cluster_encryption_config_kms_key_enable_key_rotation
deletion_window_in_days = var.cluster_encryption_config_kms_key_deletion_window_in_days
policy = data.aws_iam_policy_document.cloudwatch.json
tags = module.labels.tags
}