-
Notifications
You must be signed in to change notification settings - Fork 0
/
kms.tf
48 lines (44 loc) · 1.21 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
resource "aws_kms_key" "static_site_kms" {
enable_key_rotation = true
tags = local.common_tags
}
resource "aws_kms_key_policy" "static_site_kms_policy" {
key_id = aws_kms_key.static_site_kms.id
policy = jsonencode({
"Version" : "2012-10-17",
"Id" : "static_site_kms_policy",
"Statement" : [
{
"Sid" : "EnableIAMUserPermissions",
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam::${local.account_id}:root"
},
"Action" : "kms:*",
"Resource" : "*"
},
{
"Sid" : "CloudFrontServiceKmsPolicyKey",
"Effect" : "Allow",
"Principal" : {
"Service" : "cloudfront.amazonaws.com"
},
"Action" : [
"kms:Decrypt",
"kms:Encrypt",
"kms:GenerateDataKey*"
],
"Resource" : "*",
"Condition" : {
"StringEquals" : {
"aws:SourceArn" : aws_cloudfront_distribution.static_site_distribution.arn
}
}
}
]
})
}
resource "aws_kms_alias" "static_site_kms_alias" {
name = "alias/static_site/${aws_s3_bucket.static_site.id}"
target_key_id = aws_kms_key.static_site_kms.key_id
}