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
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 = "[email protected]"
}
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"
}
}
Requirements
| Name | Version |
|---|---|
| terraform | ~> 1.5 |
| aws | ~> 6.50 |
Providers
| Name | Version |
|---|---|
| aws | 6.50.0 |
Resources
| Name | Type |
|---|---|
| aws_sns_topic.this | resource |
| aws_sns_topic_data_protection_policy.this | resource |
| aws_sns_topic_policy.this | resource |
| aws_sns_topic_subscription.this | resource |
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| data_protection_policies | Map of SNS data protection policy definitions keyed by topic key | map(object({ policy = string })) | {} |
no |
| subscriptions | Map of SNS subscription definitions | map(object({ topic_key = string protocol = string endpoint = string raw_message_delivery = optional(bool, false) filter_policy = optional(string, null) filter_policy_scope = optional(string, "MessageAttributes") redrive_policy = optional(string, null) delivery_policy = optional(string, null) confirmation_timeout_in_minutes = optional(number, 1) endpoint_auto_confirms = optional(bool, false) })) | {} |
no |
| tags | Resource tags to apply to all resources | map(string) |
{} |
no |
| topic_policies | Map of SNS topic policy definitions keyed by topic key | map(object({ policy = string })) | {} |
no |
| topics | Map of SNS topic definitions | map(object({ name = string display_name = optional(string, null) fifo_topic = optional(bool, false) content_based_deduplication = optional(bool, false) kms_master_key_id = optional(string, null) delivery_policy = optional(string, null) signature_version = optional(number, 1) tracing_config = optional(string, "PassThrough") archive_policy = optional(string, null) # Feedback logging IAM roles per protocol application_success_feedback_role_arn = optional(string, null) application_failure_feedback_role_arn = optional(string, null) application_success_feedback_sample_rate = optional(number, null) http_success_feedback_role_arn = optional(string, null) http_failure_feedback_role_arn = optional(string, null) http_success_feedback_sample_rate = optional(number, null) lambda_success_feedback_role_arn = optional(string, null) lambda_failure_feedback_role_arn = optional(string, null) lambda_success_feedback_sample_rate = optional(number, null) sqs_success_feedback_role_arn = optional(string, null) sqs_failure_feedback_role_arn = optional(string, null) sqs_success_feedback_sample_rate = optional(number, null) firehose_success_feedback_role_arn = optional(string, null) firehose_failure_feedback_role_arn = optional(string, null) firehose_success_feedback_sample_rate = optional(number, null) })) | {} |
no |
Outputs
| Name | Description |
|---|---|
| subscription_arns | Map of subscription keys to SNS subscription ARNs |
| subscription_ids | Map of subscription keys to SNS subscription IDs |
| topic_arns | Map of topic keys to SNS topic ARNs |
| topic_ids | Map of topic keys to SNS topic IDs (same as ARN) |
| topic_names | Map of topic keys to SNS topic names |