-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.tf
38 lines (36 loc) · 1.17 KB
/
key.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
resource "aws_kms_key" "encrypt" {
count = length(var.accounts)
description = "Encryption key for ${var.application_name} ${var.accounts[count.index].name}"
policy = data.aws_iam_policy_document.encrypt[count.index].json
}
resource "aws_kms_alias" "encrypt" {
count = length(var.accounts)
target_key_id = aws_kms_key.encrypt[count.index].id
name = "alias/${var.application_name}-${var.accounts[count.index].name}"
}
data "aws_iam_policy_document" "encrypt" {
count = length(var.accounts)
statement {
sid = "AllowKeyUsageByRemote"
effect = "Allow"
resources = ["*"]
actions = ["kms:Decrypt", "kms:DescribeKey"]
principals {
identifiers = var.accounts[count.index].authorized_principals
type = "AWS"
}
}
statement {
# todo do not allow the creator of the secret access
sid = "AllowKeyManagement"
effect = "Allow"
resources = ["*"]
actions = [
"kms:*"
]
principals {
identifiers = [local.root_account]
type = "AWS"
}
}
}