Skip to content

Commit

Permalink
Merge pull request #1 from babbel/initial
Browse files Browse the repository at this point in the history
Initial version
  • Loading branch information
awendt authored Jan 26, 2022
2 parents 1d7fb7a + 7be4b48 commit 4d508d4
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
day: sunday
time: "11:00"
timezone: Europe/Berlin
20 changes: 20 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Validate

on: push

env:
AWS_REGION: local

jobs:
validate:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: _test
steps:
- uses: actions/checkout@v2.4.0
- uses: hashicorp/setup-terraform@v1.3.2
with:
terraform_version: 0.15.5
- run: terraform init
- run: terraform validate
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/_test/.terraform
/_test/.terraform.lock.hcl
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## v1.0.0

- [Initial version](https://github.com/babbel/terraform-aws-ses-sending-domain/pull/1)
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022 Babbel GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# terraform-aws-ses-sending-domain
Terraform module creating an SES sending domain
# Terraform module creating AWS SES sending domain

This module configures a sending domain for SES allowing email addresses with
that domain to be used in the `From` field of the emails sent via SES.

This includes the following components:

* [SES domain verification](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-domain-procedure.html)
* [Bounce and complaint notification to SNS](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/monitor-sending-activity-using-notifications-sns.html)
* [SPF](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-authentication-spf.html)
* [DKIM](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-authentication-dkim-easy-setup-domain.html)

## Example

```tf
resource "aws_route53_zone" "email-example" {
name = "email.example.com"
}
module "ses-sending-domain-example" {
source = "babbel/ses-sending-domain/aws"
version = "~> 1.0"
domain_name = "example.com"
route53_zone = aws_route53_zone.email-example
sns_topic_name = "example"
tags = {
environment = "production"
}
}
```
10 changes: 10 additions & 0 deletions _test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module "ses-sending-domain" {
source = "./.."

domain_name = "example.com"
route53_zone = {
id = "123"
}
sns_topic_name = "foo"
tags = {}
}
9 changes: 9 additions & 0 deletions _test/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
required_version = ">= 0.15.0"
}
18 changes: 18 additions & 0 deletions dkim.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "aws_ses_domain_dkim" "this" {
domain = aws_ses_domain_identity.this.domain

depends_on = [aws_ses_domain_identity_verification.this]
}

resource "aws_route53_record" "domainkey_cname" {
count = 3

zone_id = var.route53_zone.id
name = "${aws_ses_domain_dkim.this.dkim_tokens[count.index]}._domainkey.${var.domain_name}."
type = "CNAME"
ttl = 3600

records = [
"${aws_ses_domain_dkim.this.dkim_tokens[count.index]}.dkim.amazonses.com.",
]
}
20 changes: 20 additions & 0 deletions notifications.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "aws_sns_topic" "this" {
name = var.sns_topic_name
tags = var.tags
}

resource "aws_ses_identity_notification_topic" "bounce" {
identity = aws_ses_domain_identity.this.domain
notification_type = "Bounce"
include_original_headers = true

topic_arn = aws_sns_topic.this.arn
}

resource "aws_ses_identity_notification_topic" "complaint" {
identity = aws_ses_domain_identity.this.domain
notification_type = "Complaint"
include_original_headers = true

topic_arn = aws_sns_topic.this.arn
}
15 changes: 15 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "ses_domain_identity" {
value = aws_ses_domain_identity.this

description = <<EOS
The configured SES sending domain.
EOS
}

output "sns_topic" {
value = aws_sns_topic.this

description = <<EOS
SNS topic receiving bounce and complaint notifications from the configured SES sending domain.
EOS
}
20 changes: 20 additions & 0 deletions ses.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "aws_ses_domain_identity" "this" {
domain = var.domain_name
}

resource "aws_route53_record" "amazonses_txt" {
zone_id = var.route53_zone.id
name = "_amazonses.${var.domain_name}."
type = "TXT"
ttl = 600

records = [
aws_ses_domain_identity.this.verification_token,
]
}

resource "aws_ses_domain_identity_verification" "this" {
domain = aws_ses_domain_identity.this.domain

depends_on = [aws_route53_record.amazonses_txt]
}
10 changes: 10 additions & 0 deletions spf.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "aws_route53_record" "txt" {
zone_id = var.route53_zone.id
name = "${var.domain_name}."
type = "TXT"
ttl = 600

records = [
"v=spf1 include:amazonses.com ~all",
]
}
34 changes: 34 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
variable "domain_name" {
type = string

description = <<EOS
Domain name which shall be used as sender domain by SES.
EOS
}

variable "route53_zone" {
type = object({ id = string })

description = <<EOS
The Route53 hosted zone to which all DNS records shall be added.
The domain name specified as `var.domain_name` must be within the Route53 hosted zone specified by this parameter.
EOS
}

variable "sns_topic_name" {
type = string

description = <<EOS
Name of SNS topic
EOS
}

variable "tags" {
type = map(string)
default = {}

description = <<EOS
Tags which will be attached to all resources.
EOS
}
9 changes: 9 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
required_version = ">= 0.13"
}

0 comments on commit 4d508d4

Please sign in to comment.