-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from kunduso/create-amazon-elasticache
Corrected AWS KMS Key policy to attach the AWS CloudWatch log group
- Loading branch information
Showing
6 changed files
with
77 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
resource "aws_cloudwatch_log_group" "slow_log" { | ||
name = "/elasticache/${var.replication_group_id}/slow-log" | ||
retention_in_days = 365 | ||
kms_key_id = aws_kms_key.encrytion_rest.id | ||
kms_key_id = aws_kms_key.encryption_rest.arn | ||
} | ||
resource "aws_cloudwatch_log_group" "engine_log" { | ||
name = "/elasticache/${var.replication_group_id}/engine-log" | ||
retention_in_days = 365 | ||
kms_key_id = aws_kms_key.encrytion_rest.id | ||
} | ||
kms_key_id = aws_kms_key.encryption_rest.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
data "aws_caller_identity" "current" {} | ||
locals { | ||
principal_root_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" | ||
principal_logs_arn = "logs.${var.region}.amazonaws.com" | ||
slow_log_arn = "arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:/elasticache/${var.replication_group_id}/slow-log" | ||
engine_log_arn = "arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:/elasticache/${var.replication_group_id}/engine-log" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
resource "aws_kms_key" "encryption_secret" { | ||
enable_key_rotation = true | ||
description = "Key to encrypt secret" | ||
deletion_window_in_days = 7 | ||
#checkov:skip=CKV2_AWS_64: Not including a KMS Key policy | ||
} | ||
resource "aws_kms_alias" "encryption_secret" { | ||
name = "alias/elasticache-app-4-in-transit" | ||
target_key_id = aws_kms_key.encryption_secret.key_id | ||
} | ||
resource "aws_kms_key" "encryption_rest" { | ||
enable_key_rotation = true | ||
description = "Key to encrypt cache at rest." | ||
deletion_window_in_days = 7 | ||
#checkov:skip=CKV2_AWS_64: KMS Key policy in a separate resource | ||
} | ||
resource "aws_kms_alias" "encryption_rest" { | ||
name = "alias/elasticache-app-4-at-rest" | ||
target_key_id = aws_kms_key.encryption_rest.key_id | ||
} | ||
resource "aws_kms_key_policy" "encryption_rest_policy" { | ||
key_id = aws_kms_key.encryption_rest.id | ||
policy = jsonencode({ | ||
Id = "encryption-rest" | ||
Statement = [ | ||
{ | ||
Action = "kms:*" | ||
Effect = "Allow" | ||
Principal = { | ||
AWS = "${local.principal_root_arn}" | ||
} | ||
Resource = "*" | ||
Sid = "Enable IAM User Permissions" | ||
}, | ||
{ | ||
Effect : "Allow", | ||
Principal : { | ||
Service : "${local.principal_logs_arn}" | ||
}, | ||
Action : [ | ||
"kms:Encrypt*", | ||
"kms:Decrypt*", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:Describe*" | ||
], | ||
Resource : "*", | ||
Condition : { | ||
ArnEquals : { | ||
"kms:EncryptionContext:aws:logs:arn" : [local.slow_log_arn, local.engine_log_arn] | ||
} | ||
} | ||
} | ||
] | ||
Version = "2012-10-17" | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters