# sns

Creates SNS topics (standard and FIFO) with optional encryption, delivery feedback logging, access policies, data protection policies, and subscriptions.

FIFO topic names are automatically suffixed with `.fifo` if not already present. All subscriptions reference topics by their map key, keeping cross-resource references clean.

## Usage

```hcl
module "sns" {
  source  = "hcassc.jfrog.io/iac-terraform-modules-virtual/messaging/sns/aws"
  version = "0.1.0"

  topics = {
    alerts = {
      name              = "prod-alerts"
      display_name      = "Production Alerts"
      kms_master_key_id = module.kms.key_arn

      lambda_success_feedback_role_arn    = aws_iam_role.sns_feedback.arn
      lambda_failure_feedback_role_arn    = aws_iam_role.sns_feedback.arn
      lambda_success_feedback_sample_rate = 100
    }

    orders = {
      name                        = "prod-orders"
      fifo_topic                  = true
      content_based_deduplication = true
      kms_master_key_id           = module.kms.key_arn
    }
  }

  topic_policies = {
    alerts = {
      policy = data.aws_iam_policy_document.sns_alerts.json
    }
  }

  subscriptions = {
    alerts_email = {
      topic_key = "alerts"
      protocol  = "email"
      endpoint  = "ops@example.com"
    }

    alerts_lambda = {
      topic_key = "alerts"
      protocol  = "lambda"
      endpoint  = module.lambda.function_arns["alert-handler"]

      filter_policy = jsonencode({
        severity = ["HIGH", "CRITICAL"]
      })
    }

    orders_sqs = {
      topic_key            = "orders"
      protocol             = "sqs"
      endpoint             = module.sqs.queue_arns["orders"]
      raw_message_delivery = true
    }
  }

  tags = {
    Environment = "prod"
    Team        = "platform"
  }
}
```

<!-- BEGIN_TF_DOCS — DO NOT EDIT BELOW THIS LINE -->
## Requirements

| Name | Version |
| ---- | ------- |
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | ~> 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement_aws) | ~> 6.50 |

## Providers

| Name | Version |
| ---- | ------- |
| <a name="provider_aws"></a> [aws](#provider_aws) | 6.50.0 |

## Resources

| Name | Type |
| ---- | ---- |
| [aws_sns_topic.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [aws_sns_topic_data_protection_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_data_protection_policy) | resource |
| [aws_sns_topic_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_policy) | resource |
| [aws_sns_topic_subscription.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |

## Inputs

| Name | Description | Type | Default | Required |
| ---- | ----------- | ---- | ------- | :------: |
| <a name="input_data_protection_policies"></a> [data_protection_policies](#input_data_protection_policies) | Map of SNS data protection policy definitions keyed by topic key | <pre>map(object({<br/>    policy = string<br/>  }))</pre> | `{}` | no |
| <a name="input_subscriptions"></a> [subscriptions](#input_subscriptions) | Map of SNS subscription definitions | <pre>map(object({<br/>    topic_key                       = string<br/>    protocol                        = string<br/>    endpoint                        = string<br/>    raw_message_delivery            = optional(bool, false)<br/>    filter_policy                   = optional(string, null)<br/>    filter_policy_scope             = optional(string, "MessageAttributes")<br/>    redrive_policy                  = optional(string, null)<br/>    delivery_policy                 = optional(string, null)<br/>    confirmation_timeout_in_minutes = optional(number, 1)<br/>    endpoint_auto_confirms          = optional(bool, false)<br/>  }))</pre> | `{}` | no |
| <a name="input_tags"></a> [tags](#input_tags) | Resource tags to apply to all resources | `map(string)` | `{}` | no |
| <a name="input_topic_policies"></a> [topic_policies](#input_topic_policies) | Map of SNS topic policy definitions keyed by topic key | <pre>map(object({<br/>    policy = string<br/>  }))</pre> | `{}` | no |
| <a name="input_topics"></a> [topics](#input_topics) | Map of SNS topic definitions | <pre>map(object({<br/>    name                        = string<br/>    display_name                = optional(string, null)<br/>    fifo_topic                  = optional(bool, false)<br/>    content_based_deduplication = optional(bool, false)<br/>    kms_master_key_id           = optional(string, null)<br/>    delivery_policy             = optional(string, null)<br/>    signature_version           = optional(number, 1)<br/>    tracing_config              = optional(string, "PassThrough")<br/>    archive_policy              = optional(string, null)<br/><br/>    # Feedback logging IAM roles per protocol<br/>    application_success_feedback_role_arn    = optional(string, null)<br/>    application_failure_feedback_role_arn    = optional(string, null)<br/>    application_success_feedback_sample_rate = optional(number, null)<br/>    http_success_feedback_role_arn           = optional(string, null)<br/>    http_failure_feedback_role_arn           = optional(string, null)<br/>    http_success_feedback_sample_rate        = optional(number, null)<br/>    lambda_success_feedback_role_arn         = optional(string, null)<br/>    lambda_failure_feedback_role_arn         = optional(string, null)<br/>    lambda_success_feedback_sample_rate      = optional(number, null)<br/>    sqs_success_feedback_role_arn            = optional(string, null)<br/>    sqs_failure_feedback_role_arn            = optional(string, null)<br/>    sqs_success_feedback_sample_rate         = optional(number, null)<br/>    firehose_success_feedback_role_arn       = optional(string, null)<br/>    firehose_failure_feedback_role_arn       = optional(string, null)<br/>    firehose_success_feedback_sample_rate    = optional(number, null)<br/>  }))</pre> | `{}` | no |

## Outputs

| Name | Description |
| ---- | ----------- |
| <a name="output_subscription_arns"></a> [subscription_arns](#output_subscription_arns) | Map of subscription keys to SNS subscription ARNs |
| <a name="output_subscription_ids"></a> [subscription_ids](#output_subscription_ids) | Map of subscription keys to SNS subscription IDs |
| <a name="output_topic_arns"></a> [topic_arns](#output_topic_arns) | Map of topic keys to SNS topic ARNs |
| <a name="output_topic_ids"></a> [topic_ids](#output_topic_ids) | Map of topic keys to SNS topic IDs (same as ARN) |
| <a name="output_topic_names"></a> [topic_names](#output_topic_names) | Map of topic keys to SNS topic names |
<!-- END_TF_DOCS — DO NOT EDIT ABOVE THIS LINE -->
