generated from GSA/grace-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kms.tf
57 lines (52 loc) · 1.24 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
data "aws_iam_policy_document" "kms" {
statement {
effect = "Allow"
actions = ["kms:*"]
resources = ["*"]
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${local.account_id}:root"]
}
}
# TODO: this statement should only exist if the user
# provided an AWS Config role ARN
#
# statement {
# effect = "Allow"
# actions = [
# "kms:Decrypt",
# "kms:DescribeKey"
# ]
# principals {
# type = "AWS"
# identifiers = var.config_role
# }
# resources = ["*"]
# }
statement {
effect = "Allow"
actions = [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
]
resources = ["*"]
principals {
type = "AWS"
identifiers = [aws_iam_role.role.arn]
}
}
}
resource "aws_kms_key" "kms" {
description = "Key used for ${local.app_name}"
deletion_window_in_days = 7
enable_key_rotation = true
policy = data.aws_iam_policy_document.kms.json
depends_on = [aws_iam_role.role]
}
resource "aws_kms_alias" "kms" {
name = "alias/${local.app_name}"
target_key_id = aws_kms_key.kms.key_id
}