@@ -3,6 +3,7 @@ provider "aws" {
3
3
}
4
4
5
5
provider "random" {}
6
+ data "aws_caller_identity" "current" {}
6
7
7
8
locals {
8
9
definition_template = << EOF
@@ -203,6 +204,10 @@ locals {
203
204
}
204
205
}
205
206
EOF
207
+ tags = {
208
+ Name = " payments"
209
+ Environment = " PROD"
210
+ }
206
211
}
207
212
208
213
@@ -225,6 +230,7 @@ module "dynamodb" {
225
230
module "event_bridge" {
226
231
source = " ./event_bridge"
227
232
event_bridge_name = var. event_bridge_name
233
+ kms_key_id = module. kms . key_arn
228
234
posting_queue_arn = module. posting_queue . arn
229
235
posted_queue_arn = module. posted_queue . arn
230
236
enrich_lambda_arn = module. enrich_lambda . arn
@@ -263,6 +269,7 @@ module "event-pipes" {
263
269
stream_arn = module. dynamodb . stream_arn
264
270
eb_arn = module. event_bridge . arn
265
271
lambda_arn = module. dedup_lambda . arn
272
+ kms_key_id = module. kms . key_arn
266
273
target_event_detail_type = " TransactionAuthorized"
267
274
target_event_source = " octank.payments.posting.visaIngest"
268
275
}
@@ -369,6 +376,51 @@ module "fx_lambda" {
369
376
370
377
}
371
378
379
+ module "kms" {
380
+ source = " terraform-aws-modules/kms/aws"
381
+ version = " ~> 1.0"
382
+ description = " Securing SFN and EventBridge with KMS Keys"
383
+
384
+ # Aliases
385
+ aliases = [" realtimepayments" ]
386
+ aliases_use_name_prefix = true
387
+
388
+ # key_owners = [data.aws_caller_identity.current.arn]
389
+ policy = jsonencode ({
390
+ Version = " 2012-10-17" ,
391
+ Id = " default" ,
392
+ Statement = [
393
+ {
394
+ Sid = " Enable IAM User Permissions"
395
+ Effect = " Allow"
396
+ Principal = {
397
+ AWS = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root"
398
+ }
399
+ Action = " kms:*"
400
+ Resource = " *"
401
+ },
402
+ {
403
+ Sid = " AllowSFNEventBridgeToGenerateDataKey" ,
404
+ Effect = " Allow" ,
405
+ Principal = {
406
+ # Service = "events.amazonaws.com"
407
+ Service = [" events.amazonaws.com" , " pipes.amazonaws.com" , " states.amazonaws.com" ]
408
+ },
409
+ Action = [
410
+ " kms:Encrypt" ,
411
+ " kms:Decrypt" ,
412
+ " kms:ReEncrypt*" ,
413
+ " kms:GenerateDataKey*" ,
414
+ " kms:DescribeKey"
415
+ ]
416
+ Resource = " *"
417
+ }
418
+ ]
419
+ })
420
+
421
+ tags = local. tags
422
+ }
423
+
372
424
module "sfn" {
373
425
source = " ./stepfunction"
374
426
@@ -379,6 +431,12 @@ module "sfn" {
379
431
definition = local. definition_template
380
432
publish = true
381
433
434
+ encryption_configuration = {
435
+ type = " CUSTOMER_MANAGED_KMS_KEY"
436
+ kms_key_id = module.kms.key_arn
437
+ kms_data_key_reuse_period_seconds = 600
438
+ }
439
+
382
440
logging_configuration = {
383
441
include_execution_data = true
384
442
level = " ALL"
@@ -390,6 +448,10 @@ module "sfn" {
390
448
xray = true
391
449
}
392
450
451
+ kms = {
452
+ kms = true
453
+ }
454
+
393
455
stepfunction = {
394
456
stepfunction = true
395
457
}
0 commit comments