-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
51 lines (42 loc) · 1.51 KB
/
main.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
data "aws_caller_identity" "current" {
}
locals {
account_id = data.aws_caller_identity.current.account_id
}
resource "aws_kms_key" "key" {
description = var.key_description
deletion_window_in_days = var.deletion_window_in_days
enable_key_rotation = var.enable_key_rotation
policy = data.aws_iam_policy_document.combined_key_policy.json
tags = var.tags
}
resource "aws_kms_alias" "key" {
count = var.alias != null && var.alias != "" ? 1 : 0
name = var.alias
target_key_id = aws_kms_key.key.key_id
}
#####################################
# Allow IAM access to keys
# See https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html
# for more information on key policies
#####################################
data "aws_iam_policy_document" "iam_key_policy" {
#checkov:skip=CKV_AWS_109:The policy is deliberately wide because it allows IAM control of the KMS
#checkov:skip=CKV_AWS_111:The policy is deliberately wide because it allows IAM control of the KMS
#checkov:skip=CKV_AWS_356:The policyi s kept wide for IAM control of KMS
statement {
sid = "Allow administration of the key by key creator account"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${local.account_id}:root"]
}
actions = ["kms:*"]
resources = ["*"]
}
}
data "aws_iam_policy_document" "combined_key_policy" {
source_policy_documents = concat(
[data.aws_iam_policy_document.iam_key_policy.json],
var.key_policy_statements,
)
}