Skip to content

Commit

Permalink
Merge pull request #33 from trussworks/mk-add-kms-terratest
Browse files Browse the repository at this point in the history
Include kms key in simple terratest
  • Loading branch information
Michael Kania authored Nov 25, 2019
2 parents 413ecdc + 6d5b31f commit 5fcbdc7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@

#
# KMS Key
#
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

data "aws_iam_policy_document" "cloudwatch_logs_allow_kms" {
statement {
sid = "Enable IAM User Permissions"
effect = "Allow"
principals {
type = "AWS"
identifiers = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:root",
]
}
actions = [
"kms:*",
]
resources = ["*"]
}
statement {
sid = "Allow logs KMS access"
effect = "Allow"
principals {
type = "Service"
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"]
}
actions = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
resources = ["*"]
}
}

resource "aws_kms_key" "main" {
description = "Key for ECS log encryption"
enable_key_rotation = true
policy = data.aws_iam_policy_document.cloudwatch_logs_allow_kms.json
}

#
# ECS Service Module
#
Expand All @@ -8,6 +54,8 @@ module "app_ecs_service" {
name = var.ecs_service_name
environment = "test"

kms_key_id = aws_kms_key.main.arn

ecs_cluster = aws_ecs_cluster.main
ecs_vpc_id = aws_vpc.main.id
ecs_subnet_ids = [aws_subnet.main.id]
Expand Down

0 comments on commit 5fcbdc7

Please sign in to comment.