Note: Scroll down this article to download the terrafom files in zip format.


Terraform AWS SNS Topic for Email Alerts

This Terraform module creates a Simple Notification Service (SNS) topic in AWS and sets up an email subscription to receive notifications.

Description

This configuration will provision the following resources in your AWS account:

  • AWS SNS Topic: A managed messaging service topic that acts as a communication channel.
  • AWS SNS Topic Subscription: A subscription that forwards messages published to the SNS topic to a specified email address.

This setup is ideal for creating a simple alerting mechanism where events in your AWS environment can trigger email notifications.


Prerequisites

Before you begin, ensure you have the following installed and configured:

  • Terraform: Version 1.0 or later.
  • AWS Account: An active AWS account.
  • AWS CLI: Configured with credentials that have permissions to create SNS topics and subscriptions.

Configuration

The module utilizes the following variables to configure the resources.

Input Variables

NameDescriptionType
aws_regionThe AWS region where resources will be created.string
sns_topic_nameThe name for the SNS topic.string
email_addressThe email address to receive alerts from the SNS topic.string

Example Configuration

You can provide values for these variables by using the included terraform.auto.tfvars file:

# terraform.auto.tfvars

aws_region     = "us-east-1"
sns_topic_name = "csc-ha-alerts-topic"
email_address  = "alerts@mydomain.com"

Usage

Follow these steps to deploy the infrastructure.

  1. Initialize Terraform: Download the necessary provider plugins.

    terraform init
    
  2. Plan the Deployment: Review the resources that Terraform will create.

    terraform plan
    
  3. Apply the Configuration: Create the resources in your AWS account.

    terraform apply
    

    Once you type yes, Terraform will provision the SNS topic and subscription.

  4. Confirm the Subscription: After applying, an email will be sent to the specified email_address. You must click the confirmation link in that email to activate the subscription and begin receiving alerts.


Outputs

Upon successful creation, the module will output the following value:

NameDescription
sns_topic_arnThe Amazon Resource Name (ARN) of the created SNS topic.

This ARN is required by the CSC High Availiability function to publish messages to this topic.


Cleanup

To remove the resources created by this module, run the following command:

terraform destroy