-
Notifications
You must be signed in to change notification settings - Fork 2
/
kms.tf
43 lines (33 loc) · 860 Bytes
/
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
data "aws_iam_policy_document" "master" {
count = length(local.arns) > 0 ? 1 : 0
statement {
principals {
type = "AWS"
identifiers = [data.aws_caller_identity.current.account_id]
}
actions = ["kms:*"]
resources = ["*"]
}
statement {
principals {
type = "AWS"
identifiers = flatten(values(local.arns))
}
actions = [
"kms:Decrypt",
"kms:DescribeKey",
]
resources = ["*"]
}
}
resource "aws_kms_key" "master" {
count = length(local.arns) > 0 ? 1 : 0
description = "The master key for ${var.app_name} application"
policy = data.aws_iam_policy_document.master[0].json
tags = var.tags
}
resource "aws_kms_alias" "master" {
count = length(local.arns) > 0 ? 1 : 0
name = "alias/${var.app_name}"
target_key_id = aws_kms_key.master[0].key_id
}