Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDLS-408 add dynamodb kms key part 1 of 2 #1737

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions terraform/account/region/dynamodb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ resource "aws_dynamodb_table" "workspace_cleanup_table" {
enabled = true
}

server_side_encryption {
enabled = true
kms_key_arn = module.dynamodb_kms.eu_west_1_target_key_arn
}

lifecycle {
prevent_destroy = false
}
Expand Down Expand Up @@ -71,6 +76,11 @@ resource "aws_dynamodb_table" "blocked_ips_table" {
enabled = true
}

# server_side_encryption {
# enabled = true
# kms_key_arn = module.dynamodb_kms.eu_west_1_target_key_arn
# }

lifecycle {
prevent_destroy = false
}
Expand Down
14 changes: 8 additions & 6 deletions terraform/account/region/elasticache.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ resource "aws_elasticache_replication_group" "cache_api" {
}

resource "aws_security_group" "cache_api_sg" {
name = "${var.account.name}-account-cache-api"
vpc_id = aws_vpc.main.id
tags = merge(var.default_tags, { Name = "${var.account.name}-account-cache--api" })
name = "${var.account.name}-account-cache-api"
vpc_id = aws_vpc.main.id
tags = merge(var.default_tags, { Name = "${var.account.name}-account-cache--api" })
description = "cache api - ${var.account.name}"

lifecycle {
create_before_destroy = true
Expand Down Expand Up @@ -63,9 +64,10 @@ resource "aws_elasticache_replication_group" "front_api" {
}

resource "aws_security_group" "cache_front_sg" {
name = "${var.account.name}-account-cache-frontend"
vpc_id = aws_vpc.main.id
tags = merge(var.default_tags, { Name = "${var.account.name}-account-cache-frontend" })
name = "${var.account.name}-account-cache-frontend"
vpc_id = aws_vpc.main.id
description = "cache front - ${var.account.name}"
tags = merge(var.default_tags, { Name = "${var.account.name}-account-cache-frontend" })

lifecycle {
create_before_destroy = true
Expand Down
56 changes: 56 additions & 0 deletions terraform/account/region/kms_service_dynamo.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
##### Shared KMS key for DynamoDB #####

# Account dynamodb encryption
module "dynamodb_kms" {
source = "./modules/kms_key"
encrypted_resource = "DynamoDB"
kms_key_alias_name = "digideps_dynamodb_encryption_key"
enable_key_rotation = true
enable_multi_region = false
deletion_window_in_days = 10
kms_key_policy = var.account.name == "development" ? data.aws_iam_policy_document.kms_dynamodb_merged_for_development.json : data.aws_iam_policy_document.kms_dynamodb_merged.json
providers = {
aws.eu_west_1 = aws.eu_west_1
aws.eu_west_2 = aws.eu_west_2
}
}

# Policies
data "aws_iam_policy_document" "kms_dynamodb_merged_for_development" {
provider = aws.global
source_policy_documents = [
data.aws_iam_policy_document.kms_dynamodb.json,
data.aws_iam_policy_document.kms_base_permissions.json,
data.aws_iam_policy_document.kms_development_account_operator_admin.json
]
}

data "aws_iam_policy_document" "kms_dynamodb_merged" {
provider = aws.global
source_policy_documents = [
data.aws_iam_policy_document.kms_dynamodb.json,
data.aws_iam_policy_document.kms_base_permissions.json
]
}

data "aws_iam_policy_document" "kms_dynamodb" {
statement {
sid = "Allow Key to be used for Encryption by DynamoDB"
effect = "Allow"
resources = ["*"]
actions = [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
]

principals {
type = "Service"
identifiers = [
"dynamodb.amazonaws.com"
]
}
}
}
Loading