How to add SMS subscribers to an AWS SNS topic with Terraform

Bjorn Krolsavatar

Bjorn Krols

Published on
07 October 2021
locals {
  phone_numbers = ["+00000000000"]
}

resource "aws_sns_topic" "topic" {
  name            = "my-topic"
  delivery_policy = jsonencode({
    "http" : {
      "defaultHealthyRetryPolicy" : {
        "minDelayTarget" : 20,
        "maxDelayTarget" : 20,
        "numRetries" : 3,
        "numMaxDelayRetries" : 0,
        "numNoDelayRetries" : 0,
        "numMinDelayRetries" : 0,
        "backoffFunction" : "linear"
      },
      "disableSubscriptionOverrides" : false,
      "defaultThrottlePolicy" : {
        "maxReceivesPerSecond" : 1
      }
    }
  })
}

resource "aws_sns_topic_subscription" "topic_sms_subscription" {
  count     = length(local.phone_numbers)
  topic_arn = aws_sns_topic.topic.arn
  protocol  = "sms"
  endpoint  = local.phone_numbers[count.index]
}

Subscribe to our newsletter

The latest news, articles, and resources, sent to your inbox weekly.

More like this