Skip to content

Commit d41099a

Browse files
authored
Merge pull request #1 from rajdban/kms
Kms changes for SFN
2 parents b36d190 + 4829d9c commit d41099a

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

source/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ provider "aws" {
33
}
44

55
provider "random" {}
6+
data "aws_caller_identity" "current" {}
67

78
locals {
89
definition_template = <<EOF
@@ -203,6 +204,10 @@ locals {
203204
}
204205
}
205206
EOF
207+
tags = {
208+
Name = "payments"
209+
Environment = "PROD"
210+
}
206211
}
207212

208213

@@ -369,6 +374,20 @@ module "fx_lambda" {
369374

370375
}
371376

377+
module "kms" {
378+
source = "terraform-aws-modules/kms/aws"
379+
version = "~> 1.0"
380+
description = "Securing SFN with KMS Keys"
381+
382+
# Aliases
383+
aliases = ["realtimepayments"]
384+
aliases_use_name_prefix = true
385+
386+
key_owners = [data.aws_caller_identity.current.arn]
387+
388+
tags = local.tags
389+
}
390+
372391
module "sfn" {
373392
source = "./stepfunction"
374393

@@ -379,6 +398,12 @@ module "sfn" {
379398
definition = local.definition_template
380399
publish = true
381400

401+
encryption_configuration = {
402+
type = "CUSTOMER_MANAGED_KMS_KEY"
403+
kms_key_id = module.kms.key_arn
404+
kms_data_key_reuse_period_seconds = 600
405+
}
406+
382407
logging_configuration = {
383408
include_execution_data = true
384409
level = "ALL"

source/stepfunction/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ resource "aws_sfn_state_machine" "this" {
2121
definition = var.definition
2222
publish = var.publish
2323

24+
dynamic "encryption_configuration" {
25+
for_each = length(var.encryption_configuration) > 0 ? [var.encryption_configuration] : []
26+
27+
content {
28+
type = encryption_configuration.value.type
29+
kms_key_id = try(encryption_configuration.value.kms_key_id, null)
30+
kms_data_key_reuse_period_seconds = try(encryption_configuration.value.kms_data_key_reuse_period_seconds, null)
31+
}
32+
}
33+
2434
dynamic "logging_configuration" {
2535
for_each = local.enable_logging ? [true] : []
2636

@@ -313,4 +323,4 @@ resource "aws_cloudwatch_log_group" "sfn" {
313323
kms_key_id = var.cloudwatch_log_group_kms_key_id
314324

315325
tags = merge(var.tags, var.cloudwatch_log_group_tags)
316-
}
326+
}

source/stepfunction/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ variable "publish" {
7373
default = false
7474
}
7575

76+
variable "encryption_configuration" {
77+
description = "Newly added encryption configuration which is used to encrypt data in the State Machine."
78+
type = any
79+
default = {}
80+
}
81+
7682
#################
7783
# CloudWatch Logs
7884
#################
@@ -256,4 +262,4 @@ variable "policy_statements" {
256262
description = "Map of dynamic policy statements to attach to IAM role"
257263
type = any
258264
default = {}
259-
}
265+
}

0 commit comments

Comments
 (0)