-
Notifications
You must be signed in to change notification settings - Fork 10
/
kms.tf
41 lines (36 loc) · 1.04 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
locals {
kms = { for key in ["ebs", "ssm"] :
key => {
alias = format("%s-%s-%s", var.name, var.environment, key)
description = format("Key to be used to encrypt/decrypt AWS %s", upper(key))
}
}
}
resource "aws_kms_key" "this" {
for_each = local.kms
description = each.value.description
deletion_window_in_days = 10
enable_key_rotation = true
policy = data.aws_iam_policy_document.kms.json
tags = var.tags
}
resource "aws_kms_alias" "this" {
for_each = aws_kms_key.this
name = format("alias/%s", local.kms[each.key].alias)
target_key_id = each.value.id
}
data "aws_iam_policy_document" "kms" {
statement {
sid = "CurrentAccountKmsKeyPolicy"
actions = ["kms:*"]
resources = ["*"]
principals {
type = "AWS"
identifiers = [format("arn:aws:iam::%s:root", data.aws_caller_identity.this.account_id)]
}
principals {
type = "Service"
identifiers = ["logs.amazonaws.com"]
}
}
}