Skip to content

Commit

Permalink
feat(sqs): distribute terraform queue module
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Aug 1, 2024
1 parent d32a3c0 commit bba0698
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 4 deletions.
146 changes: 143 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"node": ">=8.0.0"
},
"files": [
"/dist"
"/dist",
"/resources"
],
"scripts": {
"build:ts": "tsc -p ./tsconfig.build.json",
Expand Down Expand Up @@ -52,6 +53,7 @@
},
"dependencies": {
"@ehmpathy/error-fns": "1.3.0",
"@ehmpathy/uni-time": "1.4.2",
"date-fns": "2.30.0",
"simple-in-memory-queue": "1.1.7",
"uuid": "9.0.0"
Expand All @@ -75,6 +77,7 @@
"declapract": "0.11.2",
"declapract-typescript-ehmpathy": "0.23.6",
"depcheck": "1.4.3",
"domain-objects": "0.22.1",
"eslint": "8.30.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-prettier": "8.5.0",
Expand Down
20 changes: 20 additions & 0 deletions resources/terraform/aws-sqs-queue/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
locals {
name = "${var.service}-${var.environment}-${var.title}"
}

resource "aws_sqs_queue" "dead_letter_queue" { # define the deadletter queue
name = "${local.name}-dlq" # https://en.wikipedia.org/wiki/Dead_letter_queue
message_retention_seconds = 14 * 24 * 60 * 60 # keep a message up to 14 days in the deadletter queue, the max amount of time permitted
tags = var.tags
}
resource "aws_sqs_queue" "queue" { # define the queeu
name = "${local.name}-llq" # live letter queue
visibility_timeout_seconds = var.visibility_timeout_seconds
message_retention_seconds = var.message_retention_seconds # keep a message up to 3 days in the queue
delay_seconds = var.delay_seconds # wait 15 seconds before reading messages
redrive_policy = jsonencode({
maxReceiveCount = var.max_receive_count
deadLetterTargetArn = aws_sqs_queue.dead_letter_queue.arn # and if feailed each time, send here
})
tags = var.tags
}
20 changes: 20 additions & 0 deletions resources/terraform/aws-sqs-queue/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
output "arn" {
value = aws_sqs_queue.queue.arn
description = "the arn of the queue"
}
output "id" {
value = aws_sqs_queue.queue.id
description = "the id of the queue"
}
output "dlq_arn" {
value = aws_sqs_queue.dead_letter_queue.arn
description = "the arn of the dead letter queue"
}
output "dlq_id" {
value = aws_sqs_queue.dead_letter_queue.id
description = "the id of the dead letter queue"
}
output "dlq_name" {
value = aws_sqs_queue.dead_letter_queue.name
description = "the name of the dead letter queue"
}
38 changes: 38 additions & 0 deletions resources/terraform/aws-sqs-queue/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "service" {
type = string
description = "the name of the service for whom this queue is being provisioned. for example: 'svc-notifications'"
}
variable "environment" {
type = string
description = "the name of the environment in which this queue is being provisioned. for example: 'dev', 'prod', 'test', etc"
}
variable "title" {
type = string
description = "a distinct name that explains what type of messages you will find in this queue. for example: 'async-task-remind-user-to-brush-teeth'"
}
variable "tags" {
type = map(any)
description = "tags to help you categorize your resources"
}
variable "visibility_timeout_seconds" {
type = number
default = 30 # the aws default
description = "how long to keep a message invisible after it is read. i.e., the period of time between retries in processing the same message"
}
variable "message_retention_seconds" {
type = number
default = 1209600 # the aws default
description = "how long messages stay in the queue before expiring without being removed"
}
variable "delay_seconds" {
type = number
default = 0 # the aws default
description = "the number of seconds between the time the message is added to the queue and the time the message is available for being read from the queue"
}
variable "max_receive_count" {
type = number
default = 3 # a lucky number
description = "the number of times to try to process the message before moving it into the dead letter queue"
}


0 comments on commit bba0698

Please sign in to comment.