From 742f3831d86a25ac3fcf2cd1e68698a0c3896d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wendt?= Date: Tue, 25 Jan 2022 11:26:25 +0100 Subject: [PATCH 1/6] Initial version --- .github/dependabot.yml | 10 ++++++++++ .github/workflows/validate.yml | 20 ++++++++++++++++++++ .gitignore | 2 ++ README.md | 30 ++++++++++++++++++++++++++++-- _test/main.tf | 8 ++++++++ _test/versions.tf | 9 +++++++++ dkim.tf | 18 ++++++++++++++++++ notifications.tf | 20 ++++++++++++++++++++ outputs.tf | 15 +++++++++++++++ ses.tf | 20 ++++++++++++++++++++ spf.tf | 10 ++++++++++ variables.tf | 34 ++++++++++++++++++++++++++++++++++ versions.tf | 9 +++++++++ 13 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/validate.yml create mode 100644 .gitignore create mode 100644 _test/main.tf create mode 100644 _test/versions.tf create mode 100644 dkim.tf create mode 100644 notifications.tf create mode 100644 outputs.tf create mode 100644 ses.tf create mode 100644 spf.tf create mode 100644 variables.tf create mode 100644 versions.tf 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/README.md b/README.md index 2b50b2f..bac4c6b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ -# 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 +module "ses-sending-domain-example" { + source = "babbel/ses-sending-domain/aws" + version = "~> 1.0" + + domain_name = "example.com" + route53_zone_id = "A123456789" + sns_topic_name = "example" + + tags = { + environment = "production" + } +} +``` diff --git a/_test/main.tf b/_test/main.tf new file mode 100644 index 0000000..6998c53 --- /dev/null +++ b/_test/main.tf @@ -0,0 +1,8 @@ +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..94cec2a --- /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 = < Date: Tue, 25 Jan 2022 14:38:12 +0100 Subject: [PATCH 2/6] Prefer passing the whole object for existing resources --- README.md | 10 +++++++--- _test/main.tf | 10 ++++++---- dkim.tf | 2 +- ses.tf | 2 +- spf.tf | 2 +- variables.tf | 6 +++--- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index bac4c6b..e9893e9 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,17 @@ This includes the following components: ## Example ```tf +resource "aws_route53_zone" "zone-example" { + name = "zone.example.com" +} + module "ses-sending-domain-example" { source = "babbel/ses-sending-domain/aws" version = "~> 1.0" - domain_name = "example.com" - route53_zone_id = "A123456789" - sns_topic_name = "example" + domain_name = "example.com" + route53_zone = aws_route53_zone.zone-example + sns_topic_name = "example" tags = { environment = "production" diff --git a/_test/main.tf b/_test/main.tf index 6998c53..6f83c88 100644 --- a/_test/main.tf +++ b/_test/main.tf @@ -1,8 +1,10 @@ module "ses-sending-domain" { source = "./.." - domain_name = "example.com" - route53_zone_id = "123" - sns_topic_name = "foo" - tags = {} + domain_name = "example.com" + route53_zone = { + id = "123" + } + sns_topic_name = "foo" + tags = {} } diff --git a/dkim.tf b/dkim.tf index 94cec2a..685ad24 100644 --- a/dkim.tf +++ b/dkim.tf @@ -7,7 +7,7 @@ resource "aws_ses_domain_dkim" "this" { resource "aws_route53_record" "domainkey_cname" { count = 3 - zone_id = var.route53_zone_id + zone_id = var.route53_zone.id name = "${aws_ses_domain_dkim.this.dkim_tokens[count.index]}._domainkey.${var.domain_name}." type = "CNAME" ttl = 3600 diff --git a/ses.tf b/ses.tf index a7e675e..59c6de6 100644 --- a/ses.tf +++ b/ses.tf @@ -3,7 +3,7 @@ resource "aws_ses_domain_identity" "this" { } resource "aws_route53_record" "amazonses_txt" { - zone_id = var.route53_zone_id + zone_id = var.route53_zone.id name = "_amazonses.${var.domain_name}." type = "TXT" ttl = 600 diff --git a/spf.tf b/spf.tf index 635d9af..e409a26 100644 --- a/spf.tf +++ b/spf.tf @@ -1,5 +1,5 @@ resource "aws_route53_record" "txt" { - zone_id = var.route53_zone_id + zone_id = var.route53_zone.id name = "${var.domain_name}." type = "TXT" ttl = 600 diff --git a/variables.tf b/variables.tf index da54fbf..44cbe7d 100644 --- a/variables.tf +++ b/variables.tf @@ -6,11 +6,11 @@ Domain name which shall be used as sender domain by SES. EOS } -variable "route53_zone_id" { - type = string +variable "route53_zone" { + type = object({ id = string }) description = < Date: Tue, 25 Jan 2022 15:23:29 +0100 Subject: [PATCH 3/6] Rename DNS zone in example --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e9893e9..f8fe0fc 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ This includes the following components: ## Example ```tf -resource "aws_route53_zone" "zone-example" { - name = "zone.example.com" +resource "aws_route53_zone" "email-example" { + name = "email.example.com" } module "ses-sending-domain-example" { @@ -22,7 +22,7 @@ module "ses-sending-domain-example" { version = "~> 1.0" domain_name = "example.com" - route53_zone = aws_route53_zone.zone-example + route53_zone = aws_route53_zone.email-example sns_topic_name = "example" tags = { From 4dc59a87b963c422596821bfbb66798ba319e785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wendt?= Date: Tue, 25 Jan 2022 16:12:05 +0100 Subject: [PATCH 4/6] Add license --- LICENSE | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 LICENSE 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. From 99b927be541ac10f6d24704aa339de42045a7d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wendt?= Date: Wed, 26 Jan 2022 08:47:46 +0100 Subject: [PATCH 5/6] Add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CHANGELOG.md 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) From 7be4b48ec978fea1a5db37f7bd576fd31c984045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wendt?= Date: Wed, 26 Jan 2022 08:50:52 +0100 Subject: [PATCH 6/6] Fix formatting Co-authored-by: Jan Sebastian Siwy --- README.md | 2 +- _test/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f8fe0fc..bec3918 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This includes the following components: ```tf resource "aws_route53_zone" "email-example" { - name = "email.example.com" + name = "email.example.com" } module "ses-sending-domain-example" { diff --git a/_test/main.tf b/_test/main.tf index 6f83c88..9582a1e 100644 --- a/_test/main.tf +++ b/_test/main.tf @@ -1,7 +1,7 @@ module "ses-sending-domain" { source = "./.." - domain_name = "example.com" + domain_name = "example.com" route53_zone = { id = "123" }