# terraform-sns

This terraform module creates an SNS topic and corresponding subscription to lambda or SQS (including FIFO queues).

## Usage examples

1. Lambda consumer, standard queue, deploy with subscription disabled:

    ```hcl
    source = "github.com/theorchard/terraform-sns//some-version"
        environment                     = "dev"  
        sns_topic_name                  = "sometopic"
        sns_subscription_protocol       = "lambda"
        sns_subscription_enabled        = false
        application_family              = "myteam"
    ```

2. SQS consumer, standard queue:

    ```hcl
    source = "github.com/theorchard/terraform-sns//some-version"
        environment                         = "dev"  
        sns_topic_name                      = "sometopic"
        sns_subscription_protocol           = "sqs"
    ```

3. SQS consumer, FIFO queue (with [https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html](content-based deduping)):

    ```hcl
    source = "github.com/theorchard/terraform-sns//some-version"
        environment                         = "dev"  
        sns_topic_name                      = "sometopic"
        sns_subscription_protocol           = "sqs"
        is_fifo_topic                       = true
        enable_content_based_deduplication  = true
    ```

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.57.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_sns_topic.topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [aws_sns_topic_subscription.subscription](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_tags"></a> [additional\_tags](#input\_additional\_tags) | Optional map of additional tags to set on resources. These will be combined with programmatically set required tags. | `map(string)` | `{}` | no |
| <a name="input_application_family"></a> [application\_family](#input\_application\_family) | Application family to which this service belongs | `string` | n/a | yes |
| <a name="input_enable_content_based_deduplication"></a> [enable\_content\_based\_deduplication](#input\_enable\_content\_based\_deduplication) | Whether or not to enable content-based deduplication | `bool` | `false` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | prod, qa or dev | `string` | `"dev"` | no |
| <a name="input_is_fifo_topic"></a> [is\_fifo\_topic](#input\_is\_fifo\_topic) | Whether or not to create a FIFO topic | `bool` | `false` | no |
| <a name="input_sns_kms_master_key_id"></a> [sns\_kms\_master\_key\_id](#input\_sns\_kms\_master\_key\_id) | The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK. | `string` | `"alias/aws/sns"` | no |
| <a name="input_sns_subscription_enabled"></a> [sns\_subscription\_enabled](#input\_sns\_subscription\_enabled) | Enable SNS subscription | `bool` | `true` | no |
| <a name="input_sns_subscription_protocol"></a> [sns\_subscription\_protocol](#input\_sns\_subscription\_protocol) | Currently-supported subscription protocols | `string` | `"lambda"` | no |
| <a name="input_sns_topic_name"></a> [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create, minus environment prefix | `string` | `"test-topic"` | no |
| <a name="sns_subscription_endpoint"></a> [sns\_subscription\_endpoint](#sns\_subscription\_endpoint) | The endpoint SQS, Lmabda ARN or E-mail for SNS topic subscription | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_topic_arn"></a> [topic\_arn](#output\_topic\_arn) | ARN of SNS topic |
| <a name="output_topic_name"></a> [topic\_name](#output\_topic\_name) | Name of SNS topic |
<!-- END_TF_DOCS -->
