Add custom domain support to SES module (#86)

- Added variable to drive custom mail from configuration
- Added resource for MX record to a specific route 53 zone, if custom
mail value from is enabled
- Add SPF record to local.spf_records list, if custom mail value from is
enabled. Current spf resource takes care of
  - Creating the record if the value is present
- Destroying the record if the value is not present (when disabled or
variable is not set)
This commit is contained in:
Jorge Falcon authored and GitHub committed 2025-08-07 17:13:18 -04:00
1 parent 4a7fbf79cc
commit 0166b67f74
3 files changed
+41 -5

No files matched your search

+6 -1
View File
@@ -9,7 +9,7 @@ No requirements.
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.62.2 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.7.0 |
## Modules
@@ -21,15 +21,20 @@ No modules.
|------|------|
| [aws_iam_policy.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_route53_record.amazonses_dkim_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.dmarc_domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.mx_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.spf_domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_ses_domain_dkim.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_domain_dkim) | resource |
| [aws_ses_domain_identity.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_domain_identity) | resource |
| [aws_ses_domain_mail_from.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_domain_mail_from) | resource |
| [aws_iam_policy_document.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_custom_mail_from"></a> [custom\_mail\_from](#input\_custom\_mail\_from) | Custom MAIL FROM domain settings | <pre>object({<br/> enabled = optional(bool, false)<br/> domain_prefix = optional(string, "")<br/> })</pre> | <pre>{<br/> "domain_prefix": "",<br/> "enabled": false<br/>}</pre> | no |
| <a name="input_domain"></a> [domain](#input\_domain) | Domain to use for SES. | `string` | n/a | yes |
| <a name="input_extra_txt_records"></a> [extra\_txt\_records](#input\_extra\_txt\_records) | Extra TXT records that have to match the same name as the Fleet instance | `list(string)` | `[]` | no |
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | Route53 Zone ID | `string` | n/a | yes |
+23 -4
View File
@@ -1,11 +1,14 @@
locals {
spf_domains = [
spf_domains = compact(concat([
aws_ses_domain_identity.default.domain,
"_amazonses.${aws_ses_domain_identity.default.domain}"
]
"_amazonses.${aws_ses_domain_identity.default.domain}",
var.custom_mail_from.enabled == true ? "${var.custom_mail_from.domain_prefix}.${aws_ses_domain_identity.default.domain}" : null
]))
dmarc_domain = "_dmarc.${aws_ses_domain_identity.default.domain}"
}
data "aws_region" "current" {}
resource "aws_ses_domain_identity" "default" {
domain = var.domain
}
@@ -14,6 +17,23 @@ resource "aws_ses_domain_dkim" "default" {
domain = aws_ses_domain_identity.default.domain
}
### CUSTOM MAIL FROM SETTINGS ###
resource "aws_ses_domain_mail_from" "default" {
count = var.custom_mail_from.enabled == true ? 1 : 0
domain = aws_ses_domain_identity.default.domain
mail_from_domain = "${var.custom_mail_from.domain_prefix}.${aws_ses_domain_identity.default.domain}"
}
resource "aws_route53_record" "mx_record" {
count = var.custom_mail_from.enabled == true ? 1 : 0
zone_id = var.zone_id
name = aws_ses_domain_mail_from.default[count.index].mail_from_domain
type = "MX"
ttl = "600"
records = ["10 feedback-smtp.${data.aws_region.current.region}.amazonses.com"]
}
###DKIM VERIFICATION#######
resource "aws_route53_record" "amazonses_dkim_record" {
@@ -25,7 +45,6 @@ resource "aws_route53_record" "amazonses_dkim_record" {
records = ["${element(aws_ses_domain_dkim.default.dkim_tokens, count.index)}.dkim.amazonses.com"]
}
resource "aws_route53_record" "spf_domain" {
for_each = toset(local.spf_domains)
zone_id = var.zone_id
+12
View File
@@ -13,3 +13,15 @@ variable "extra_txt_records" {
description = "Extra TXT records that have to match the same name as the Fleet instance"
default = []
}
variable "custom_mail_from" {
type = object({
enabled = optional(bool, false)
domain_prefix = optional(string, "")
})
default = {
enabled = false
domain_prefix = ""
}
description = "Custom MAIL FROM domain settings"
}