Resource: aws_sns_topic

Provides an SNS topic resource

Example Usage

resource "aws_sns_topic" "user_updates" {
  name = "user-updates-topic"
}

Example with Delivery Policy

resource "aws_sns_topic" "user_updates" {
  name            = "user-updates-topic"
  delivery_policy = <<EOF
{
  "http": {
    "defaultHealthyRetryPolicy": {
      "minDelayTarget": 20,
      "maxDelayTarget": 20,
      "numRetries": 3,
      "numMaxDelayRetries": 0,
      "numNoDelayRetries": 0,
      "numMinDelayRetries": 0,
      "backoffFunction": "linear"
    },
    "disableSubscriptionOverrides": false,
    "defaultThrottlePolicy": {
      "maxReceivesPerSecond": 1
    }
  }
}
EOF
}

Example with Server-side encryption (SSE)

resource "aws_sns_topic" "user_updates" {
  name              = "user-updates-topic"
  kms_master_key_id = "alias/aws/sns"
}

Example with First-In-First-Out (FIFO)

resource "aws_sns_topic" "user_updates" {
  name                        = "user-updates-topic.fifo"
  fifo_topic                  = true
  content_based_deduplication = true
}

Message Delivery Status Arguments

The <endpoint>_success_feedback_role_arn and <endpoint>_failure_feedback_role_arn arguments are used to give Amazon SNS write access to use CloudWatch Logs on your behalf. The <endpoint>_success_feedback_sample_rate argument is for specifying the sample rate percentage (0-100) of successfully delivered messages. After you configure the <endpoint>_failure_feedback_role_arn argument, then all failed message deliveries generate CloudWatch Logs.

Argument Reference

This resource supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import SNS Topics using the topic arn. For example:

import {
  to = aws_sns_topic.user_updates
  id = "arn:aws:sns:us-west-2:0123456789012:my-topic"
}

Using terraform import, import SNS Topics using the topic arn. For example:

% terraform import aws_sns_topic.user_updates arn:aws:sns:us-west-2:0123456789012:my-topic