-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
kms.tf
59 lines (56 loc) · 1.48 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
resource "aws_kms_key" "cluster_secrets" {
description = "EKS Cluster ${var.environment_name} Encryption Config KMS Key"
enable_key_rotation = true
deletion_window_in_days = 30
policy = var.cluster_kms_policy
tags = local.tags
}
resource "aws_kms_key" "cloudwatch_log" {
description = "CloudWatch log group ${var.environment_name} Encryption Config KMS Key"
enable_key_rotation = true
deletion_window_in_days = 30
policy = data.aws_iam_policy_document.cloudwatch.json
tags = local.tags
}
data "aws_iam_policy_document" "cloudwatch" {
policy_id = "${var.environment_name}-kms-key-cloudwatch"
statement {
sid = "Enable IAM User Permissions"
actions = [
"kms:*",
]
effect = "Allow"
principals {
type = "AWS"
identifiers = [
format(
"arn:%s:iam::%s:root",
join("", 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 = ["*"]
}
}