-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* UML-3722: create event bus * add module * add provider block * add missing resource instance key * add missing var * apply to env * add mrk for sqs * add sqs * FIX TYPO * fix region var * comment out lambda for now * add missing region * resource key * remove kms * change alias * add count to policy * add resource key * enable event bus for demo env --------- Co-authored-by: gillettmoj <[email protected]>
- Loading branch information
1 parent
550e0de
commit 1145cae
Showing
8 changed files
with
158 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module "event_bus" { | ||
source = "./modules/event_bus" | ||
environment_name = var.environment_name | ||
event_bus_enabled = var.event_bus_enabled | ||
current_region = data.aws_region.current.name | ||
providers = { | ||
aws.region = aws.region | ||
} | ||
} |
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,100 @@ | ||
resource "aws_cloudwatch_event_bus" "main" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = var.environment_name | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_cloudwatch_event_archive" "main" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = var.environment_name | ||
event_source_arn = aws_cloudwatch_event_bus.main[0].arn | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_cloudwatch_event_rule" "receive_events_mlpa" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = "${var.environment_name}-mlpa-events-to-use" | ||
description = "receive events from mlpa" | ||
event_bus_name = aws_cloudwatch_event_bus.main[0].name | ||
|
||
event_pattern = jsonencode({ | ||
source = ["opg.poas.makeregister"], | ||
}) | ||
provider = aws.region | ||
} | ||
|
||
data "aws_kms_alias" "sqs" { | ||
name = "alias/sqs-mrk" | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_sqs_queue" "receive_events_queue" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = "${var.environment_name}-receive-events-queue" | ||
kms_master_key_id = data.aws_kms_alias.sqs.target_key_id | ||
kms_data_key_reuse_period_seconds = 300 | ||
|
||
visibility_timeout_seconds = 300 | ||
|
||
redrive_policy = jsonencode({ | ||
deadLetterTargetArn = aws_sqs_queue.receive_events_deadletter[0].arn | ||
maxReceiveCount = 3 | ||
}) | ||
policy = data.aws_iam_policy_document.receive_events_queue_policy[0].json | ||
|
||
provider = aws.region | ||
} | ||
|
||
data "aws_iam_policy_document" "receive_events_queue_policy" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
statement { | ||
sid = "${var.current_region}-ReceiveFromMLPA" | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["events.amazonaws.com"] | ||
} | ||
|
||
actions = ["sqs:SendMessage"] | ||
resources = ["*"] | ||
|
||
condition { | ||
test = "ArnEquals" | ||
variable = "aws:SourceArn" | ||
values = [ | ||
aws_cloudwatch_event_rule.receive_events_mlpa[0].arn | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_sqs_queue" "receive_events_deadletter" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = "${var.environment_name}-receive-events-deadletter" | ||
kms_master_key_id = data.aws_kms_alias.sqs.target_key_id | ||
kms_data_key_reuse_period_seconds = 300 | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_sqs_queue_redrive_allow_policy" "receive_events_redrive_allow_policy" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
queue_url = aws_sqs_queue.receive_events_deadletter[0].id | ||
|
||
redrive_allow_policy = jsonencode({ | ||
redrivePermission = "byQueue", | ||
sourceQueueArns = [aws_sqs_queue.receive_events_queue[0].arn] | ||
}) | ||
provider = aws.region | ||
} | ||
|
||
/* | ||
resource "aws_lambda_event_source_mapping" "reveive_events_mapping" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
event_source_arn = aws_sqs_queue.receive_events_queue[0].arn | ||
enabled = false | ||
function_name = var.ingress_lambda_name | ||
batch_size = 10 | ||
provider = aws.region | ||
} | ||
*/ |
13 changes: 13 additions & 0 deletions
13
terraform/environment/region/modules/event_bus/terraform.tf
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,13 @@ | ||
terraform { | ||
required_version = "~> 1.9.4" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
configuration_aliases = [ | ||
aws.region, | ||
] | ||
version = "~> 5.64.0" | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
terraform/environment/region/modules/event_bus/variables.tf
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,22 @@ | ||
variable "environment_name" { | ||
description = "The name of the environment" | ||
type = string | ||
} | ||
|
||
variable "event_bus_enabled" { | ||
description = "Whether to enable Event Bus" | ||
type = bool | ||
default = false | ||
} | ||
|
||
/* | ||
variable "ingress_lambda_name" { | ||
description = "The name of the ingress lambda" | ||
type = string | ||
} | ||
*/ | ||
|
||
variable "current_region" { | ||
description = "The current region" | ||
type = string | ||
} |
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