From 8a625567befbf3cc11dbe04af8151be38c17beab Mon Sep 17 00:00:00 2001
From: bt-justtrack <168745819+bt-justtrack@users.noreply.github.com>
Date: Wed, 2 Oct 2024 15:43:27 +0200
Subject: [PATCH] feat: allow customizing the dlq name, add outputs (#61)
## Description
Allow specifying the name of the created dlq compared to using normal
queue name + "-dlq". Add outputs of the created sqs queues.
## Motivation and Context
We want to have a custom named sqs queue from which we can read using a
different consumer, as such the default -dlq ending would be misleading.
---
README.md | 10 +++++++++-
main.tf | 1 +
outputs.tf | 28 ++++++++++++++++++++++++++++
variables.tf | 6 ++++++
4 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 58892a0..ac5ad65 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,7 @@ Terraform module which creates a sqs queue
| [dlq\_alarm\_enabled](#input\_dlq\_alarm\_enabled) | Defines if the DLQ alarm should be created. | `bool` | `true` | no |
| [dlq\_enabled](#input\_dlq\_enabled) | Defines if Dead Letter Queue (DLQ) is enabled. | `bool` | `true` | no |
| [dlq\_max\_receive\_count](#input\_dlq\_max\_receive\_count) | The maximum number of times a message can be received from the DLQ before it's discarded. | `number` | `5` | no |
+| [dlq\_name](#input\_dlq\_name) | Sets a custom name for the to be created dlq. | `string` | `null` | no |
| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| [fifo\_queue](#input\_fifo\_queue) | Boolean designating a FIFO queue | `bool` | `false` | no |
@@ -71,5 +72,12 @@ Terraform module which creates a sqs queue
## Outputs
-No outputs.
+| Name | Description |
+|------|-------------|
+| [dlq\_queue\_arn](#output\_dlq\_queue\_arn) | queue arn of the dead letter sqs queue |
+| [dlq\_queue\_name](#output\_dlq\_queue\_name) | queue name of the dead letter sqs queue |
+| [dlq\_queue\_url](#output\_dlq\_queue\_url) | queue url of the dead letter sqs queue |
+| [sqs\_queue\_arn](#output\_sqs\_queue\_arn) | queue arn of the main sqs queue |
+| [sqs\_queue\_name](#output\_sqs\_queue\_name) | queue name of the main sqs queue |
+| [sqs\_queue\_url](#output\_sqs\_queue\_url) | queue url of the main sqs queue |
diff --git a/main.tf b/main.tf
index 6d42efb..1fac114 100644
--- a/main.tf
+++ b/main.tf
@@ -32,6 +32,7 @@ module "sqs" {
create_dlq = var.dlq_enabled
create_queue_policy = length(var.subscription) >= 1
delay_seconds = var.delay_seconds
+ dlq_name = var.dlq_name
fifo_queue = var.fifo_queue
message_retention_seconds = var.message_retention_seconds
name = module.this.id
diff --git a/outputs.tf b/outputs.tf
index e69de29..6f52044 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -0,0 +1,28 @@
+output "sqs_queue_url" {
+ value = module.sqs.queue_url
+ description = "queue url of the main sqs queue"
+}
+output "sqs_queue_arn" {
+ value = module.sqs.queue_arn
+ description = "queue arn of the main sqs queue"
+}
+
+output "sqs_queue_name" {
+ value = module.sqs.queue_name
+ description = "queue name of the main sqs queue"
+}
+
+output "dlq_queue_url" {
+ value = module.sqs.dead_letter_queue_url
+ description = "queue url of the dead letter sqs queue"
+}
+
+output "dlq_queue_arn" {
+ value = module.sqs.dead_letter_queue_arn
+ description = "queue arn of the dead letter sqs queue"
+}
+
+output "dlq_queue_name" {
+ value = module.sqs.dead_letter_queue_name
+ description = "queue name of the dead letter sqs queue"
+}
diff --git a/variables.tf b/variables.tf
index bc48750..4ec5953 100644
--- a/variables.tf
+++ b/variables.tf
@@ -60,6 +60,12 @@ variable "dlq_max_receive_count" {
default = 5
}
+variable "dlq_name" {
+ type = string
+ description = "Sets a custom name for the to be created dlq."
+ default = null
+}
+
variable "fifo_queue" {
type = bool
description = "Boolean designating a FIFO queue"