generated from aws-ia/terraform-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 7
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 #10 from alexknez/f-encryption
Add encryption configuration
- Loading branch information
Showing
8 changed files
with
157 additions
and
64 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
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
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,122 @@ | ||
# DATA SOURCE: AWS CALLER IDENTITY - Used to get the Account ID | ||
data "aws_caller_identity" "current" {} | ||
|
||
# KMS Key for CloudWatch Log Groups | ||
resource "aws_kms_key" "log_key" { | ||
description = "KMS Logs Key" | ||
deletion_window_in_days = 7 | ||
enable_key_rotation = true | ||
policy = data.aws_iam_policy_document.policy_kms_logs_document.json | ||
|
||
tags = { | ||
Name = "kms-key-${var.identifier}" | ||
} | ||
} | ||
|
||
# KMS Policy - it allows the use of the Key by the CloudWatch log groups created in this sample | ||
data "aws_iam_policy_document" "policy_kms_logs_document" { | ||
statement { | ||
sid = "Enable IAM User Permissions" | ||
actions = ["kms:*"] | ||
resources = ["arn:aws:kms:${var.aws_region}:${data.aws_caller_identity.current.account_id}:*"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"] | ||
} | ||
} | ||
|
||
statement { | ||
sid = "Enable KMS to be used by CloudWatch Logs" | ||
actions = [ | ||
"kms:Encrypt*", | ||
"kms:Decrypt*", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:Describe*" | ||
] | ||
resources = ["arn:aws:kms:${var.aws_region}:${data.aws_caller_identity.current.account_id}:*"] | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["logs.${var.aws_region}.amazonaws.com"] | ||
} | ||
|
||
condition { | ||
test = "ArnLike" | ||
variable = "kms:EncryptionContext:aws:logs:arn" | ||
values = ["arn:aws:logs:${var.aws_region}:${data.aws_caller_identity.current.account_id}:*"] | ||
} | ||
} | ||
} | ||
|
||
# Encryption KMS Key | ||
resource "aws_kms_key" "encryption_key" { | ||
description = "KMS Encryption Key" | ||
deletion_window_in_days = 7 | ||
enable_key_rotation = true | ||
policy = data.aws_iam_policy_document.policy_encryption_key_document.json | ||
|
||
tags = { | ||
Name = "kms-key-${var.identifier}" | ||
} | ||
} | ||
|
||
# KMS Policy - it allows the use of the KMS Key by the root account and key creator | ||
data "aws_iam_policy_document" "policy_encryption_key_document" { | ||
statement { | ||
sid = "Enable IAM User Permissions" | ||
actions = ["kms:*"] | ||
resources = ["arn:aws:kms:${var.aws_region}:${data.aws_caller_identity.current.account_id}:*"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"] | ||
} | ||
} | ||
|
||
statement { | ||
sid = "Allow access for Key Administrators" | ||
actions = [ | ||
"kms:Create*", | ||
"kms:Describe*", | ||
"kms:Enable*", | ||
"kms:List*", | ||
"kms:Put*", | ||
"kms:Update*", | ||
"kms:Revoke*", | ||
"kms:Disable*", | ||
"kms:Get*", | ||
"kms:Delete*", | ||
"kms:TagResource", | ||
"kms:UntagResource", | ||
"kms:ScheduleKeyDeletion", | ||
"kms:CancelKeyDeletion" | ||
] | ||
|
||
resources = ["*"] | ||
principals { | ||
type = "AWS" | ||
identifiers = [data.aws_caller_identity.current.arn] | ||
} | ||
} | ||
|
||
statement { | ||
sid = "Allow attachment of persistent resources" | ||
actions = [ | ||
"kms:CreateGrant", | ||
"kms:ListGrants", | ||
"kms:RevokeGrant" | ||
] | ||
resources = ["*"] | ||
principals { | ||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"] | ||
type = "AWS" | ||
} | ||
condition { | ||
test = "Bool" | ||
values = ["true"] | ||
variable = "kms:GrantIsForAWSResource" | ||
} | ||
} | ||
} |
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