diff --git a/aws/sqs/main.tf b/aws/sqs/main.tf new file mode 100644 index 0000000..cedb827 --- /dev/null +++ b/aws/sqs/main.tf @@ -0,0 +1,15 @@ +locals { + # This helps avoid queue names ending in "-" or "-.fifo" + given_queue_name = var.identifier == "" ? "" : "-${var.identifier}" + # All fifo queues must end in .fifo, per AWS rules + queue_suffix = var.is_fifo ? ".fifo" : "" + full_queue_name = "${var.stack}-${var.env}${local.given_queue_name}${local.queue_suffix}" +} + +resource "aws_sqs_queue" "this" { + name = local.full_queue_name + fifo_queue = var.is_fifo + content_based_deduplication = var.is_fifo && var.content_based_deduplication + receive_wait_time_seconds = var.receive_wait_time_seconds + visibility_timeout_seconds = var.visibility_timeout_seconds +} diff --git a/aws/sqs/outputs.tf b/aws/sqs/outputs.tf new file mode 100644 index 0000000..ceacaf9 --- /dev/null +++ b/aws/sqs/outputs.tf @@ -0,0 +1,11 @@ +output "arn" { + value = aws_sqs_queue.this.arn +} + +output "name" { + value = aws_sqs_queue.this.name +} + +output "url" { + value = aws_sqs_queue.this.url +} diff --git a/aws/sqs/variables.tf b/aws/sqs/variables.tf new file mode 100644 index 0000000..c65181d --- /dev/null +++ b/aws/sqs/variables.tf @@ -0,0 +1,38 @@ +variable "stack" { + description = "The name of the stack" + type = string +} + +variable "env" { + description = "The name of the environment" + type = string +} + +variable "identifier" { + description = "The shorthand name of the queue. The full queue name can be retrieved as an output. Note that an empty string is still a valid queue name." + type = string +} + +variable "visibility_timeout_seconds" { + description = "The amount of time allowed to the processor to process a message before it is declared failed. Defaults to 30 seconds." + type = number + default = 30 +} + +variable "receive_wait_time_seconds" { + description = "The time to wait when polling for new messages. Use 0 for immediate response. Longer values are preferred. Defaults to 20, which is the maximum." + type = number + default = 20 +} + +variable "is_fifo" { + description = "Specifies if this queue should be a FIFO queue, which would preserve message ordering. Defaults to true." + type = bool + default = true +} + +variable "content_based_deduplication" { + description = "Specifies if this queue should use content-based deduplication. Defaults to true. Note: If is_fifo is not set to true, then this value is ignored." + type = bool + default = true +} diff --git a/aws/sqs/versions.tf b/aws/sqs/versions.tf new file mode 100644 index 0000000..b3dfba4 --- /dev/null +++ b/aws/sqs/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "hashicorp/aws" + } + } +}