diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..3612f40 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 + +updates: +- package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + day: sunday + time: "11:00" + timezone: Europe/Berlin diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..56a4e49 --- /dev/null +++ b/.github/workflows/validate.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..576c848 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/_test/.terraform +/_test/.terraform.lock.hcl diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ad09c10 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## v1.0.0 + +- [Initial version](https://github.com/babbel/terraform-aws-ses-sending-domain/pull/1) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a226c2e --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index 2b50b2f..bec3918 100644 --- a/README.md +++ b/README.md @@ -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" + } +} +``` diff --git a/_test/main.tf b/_test/main.tf new file mode 100644 index 0000000..9582a1e --- /dev/null +++ b/_test/main.tf @@ -0,0 +1,10 @@ +module "ses-sending-domain" { + source = "./.." + + domain_name = "example.com" + route53_zone = { + id = "123" + } + sns_topic_name = "foo" + tags = {} +} diff --git a/_test/versions.tf b/_test/versions.tf new file mode 100644 index 0000000..78ef0a8 --- /dev/null +++ b/_test/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.0" + } + } + required_version = ">= 0.15.0" +} diff --git a/dkim.tf b/dkim.tf new file mode 100644 index 0000000..685ad24 --- /dev/null +++ b/dkim.tf @@ -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.", + ] +} diff --git a/notifications.tf b/notifications.tf new file mode 100644 index 0000000..dec7a8b --- /dev/null +++ b/notifications.tf @@ -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 +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..4b60a54 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,15 @@ +output "ses_domain_identity" { + value = aws_ses_domain_identity.this + + description = <