diff --git a/README.md b/README.md index b7190e9..e357ce0 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,7 @@ Available targets: | [redrive\_policy](#input\_redrive\_policy) | The SNS redrive policy as JSON. This overrides `var.redrive_policy_max_receiver_count` and the `deadLetterTargetArn` (supplied by `var.fifo_queue = true`) passed in by the module. | `string` | `null` | no | | [redrive\_policy\_max\_receiver\_count](#input\_redrive\_policy\_max\_receiver\_count) | The number of times a message is delivered to the source queue before being moved to the dead-letter queue. When the ReceiveCount for a message exceeds the maxReceiveCount for a queue, Amazon SQS moves the message to the dead-letter-queue. | `number` | `5` | no | | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | +| [sns\_topic\_name](#input\_sns\_topic\_name) | The name of sns topic | `string` | `"sns-topic-${uuid()}"` | no | | [sns\_topic\_policy\_json](#input\_sns\_topic\_policy\_json) | The fully-formed AWS policy as JSON | `string` | `""` | no | | [sqs\_dlq\_enabled](#input\_sqs\_dlq\_enabled) | Enable delivery of failed notifications to SQS and monitor messages in queue. | `bool` | `false` | no | | [sqs\_dlq\_max\_message\_size](#input\_sqs\_dlq\_max\_message\_size) | The limit of how many bytes a message can contain before Amazon SQS rejects it. An integer from 1024 bytes (1 KiB) up to 262144 bytes (256 KiB). The default for this attribute is 262144 (256 KiB). | `number` | `262144` | no | diff --git a/main.tf b/main.tf index 4f58382..b1d14e3 100644 --- a/main.tf +++ b/main.tf @@ -3,7 +3,9 @@ locals { kms_key_id = local.enabled && var.encryption_enabled && var.kms_master_key_id != "" ? var.kms_master_key_id : "" - sns_topic_name = var.fifo_topic ? "${module.this.id}.fifo" : module.this.id + default_sns_topic_name = var.sns_topic_name != "" ? var.sns_topic_name : "sns-topic-${uuid()}" + + sns_topic_name = var.fifo_topic ? "${local.default_sns_topic_name}.fifo" : local.default_sns_topic_name sqs_queue_name = var.fifo_queue_enabled ? "${module.this.id}.fifo" : module.this.id sqs_dlq_enabled = local.enabled && var.sqs_dlq_enabled @@ -15,7 +17,7 @@ resource "aws_sns_topic" "this" { count = local.enabled ? 1 : 0 name = local.sns_topic_name - display_name = replace(module.this.id, ".", "-") # dots are illegal in display names and for .fifo topics required as part of the name (AWS SNS by design) + display_name = replace(local.sns_topic_name, ".", "-") # dots are illegal in display names and for .fifo topics required as part of the name (AWS SNS by design) kms_master_key_id = local.kms_key_id delivery_policy = var.delivery_policy fifo_topic = var.fifo_topic diff --git a/variables.tf b/variables.tf index cb4a0bb..4ea0049 100644 --- a/variables.tf +++ b/variables.tf @@ -49,6 +49,12 @@ variable "allowed_iam_arns_for_sns_publish" { default = [] } +variable "sns_topic_name" { + type = string + description = "The name of sns topic" + default = "" +} + variable "sns_topic_policy_json" { type = string description = "The fully-formed AWS policy as JSON"