-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudwatch.tf
52 lines (50 loc) · 1.41 KB
/
cloudwatch.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
resource "aws_cloudwatch_log_group" "this" {
count = var.create_log_group ? 1 : 0
name = local.log_group_name
skip_destroy = var.skip_destroy
retention_in_days = 30
kms_key_id = aws_kms_key.this[0].arn
}
resource "aws_kms_key" "this" {
count = var.create_log_group ? 1 : 0
description = "KMS key to encrypt logs for ${var.service_name}"
key_usage = "ENCRYPT_DECRYPT"
enable_key_rotation = true
}
resource "aws_kms_key_policy" "this" {
count = var.create_log_group ? 1 : 0
key_id = aws_kms_key.this[0].key_id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "Enable IAM User Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${local.account_id}:root"
}
Action = "kms:*"
Resource = "*"
},
{
Effect = "Allow",
Principal = {
Service = "logs.${local.region}.amazonaws.com"
}
Action = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
Resource = "*",
Condition = {
ArnEquals = {
"kms:EncryptionContext:aws:logs:arn" = "arn:aws:logs:${local.region}:${local.account_id}:log-group:${local.log_group_name}"
}
}
}
]
})
}