Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MX validation record optional #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Then, fetch the module from the [Terraform Registry](https://registry.terraform.
| custom_sites_subdomain | Subdomain for custom Sites URL | `string` | n/a |
| dkim_record_value | DKIM Identifier Value | `string` | n/a |
| dmarc_report_recipient | Recipient of DMARC Reports | `string` | n/a |
| mx_verification_record_prefix | MX Verification Record Prefix (without `.mx-verification.google.com`) | `string` | n/a |
| mx_verification_record_prefix | MX Verification Record Prefix (without `.mx-verification.google.com`) | `string` | null |
| zone_id | ID of the DNS Zone to store Records in | `string` | n/a |
| apex_domain_redirect_records | n/a | `list` | <pre>[<br> "216.239.32.21",<br> "216.239.34.21",<br> "216.239.36.21",<br> "216.239.38.21"<br>]</pre> |
| apex_spf_txt | SPF Record for Gmail | `string` | `"v=spf1 include:_spf.google.com ~all"` |
Expand Down
16 changes: 9 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ variable "mx_verification_record_priority" {
variable "mx_verification_record_prefix" {
type = string
description = "MX Verification Record Prefix (without `.mx-verification.google.com`)"
default = null
}

variable "mx_verification_record_suffix" {
Expand Down Expand Up @@ -174,7 +175,7 @@ variable "redirect_naked_domain" {
}

variable "apex_domain_redirect_records" {
type = list
type = list(any)
description = ""
default = [
"216.239.32.21",
Expand All @@ -185,10 +186,11 @@ variable "apex_domain_redirect_records" {
}

locals {
zone_name = data.aws_route53_zone.zone.name
verification_record = format("%g %s%s", var.mx_verification_record_priority, var.mx_verification_record_prefix, var.mx_verification_record_suffix)
gmail_records = var.use_dnssec_signed_records ? concat(var.dnssec_mx_records, [local.verification_record]) : concat(var.mx_records, [local.verification_record])
dmarc_report_recipient = var.dmarc_report_recipient != null ? var.dmarc_report_recipient : format("hostmaster@%s", local.zone_name)
dmarc_policy = "v=${var.dmarc_protocol_version}; p=${var.dmarc_policy_type}; pct=${var.dmarc_policy_percentage}; rua=mailto:${local.dmarc_report_recipient}; sp=${var.dmarc_subdomain_policy_type}; adkim=${var.dmarc_dkim_alignment_mode}; aspf=${var.dmarc_spf_alignment_mode}"
apex_txt_record = var.apex_verification_txt != null ? [var.apex_spf_txt, var.apex_verification_txt] : [var.apex_spf_txt]
zone_name = data.aws_route53_zone.zone.name
non_verification_records = var.use_dnssec_signed_records ? var.dnssec_mx_records : var.mx_records
verification_record = var.mx_verification_record_prefix != null ? format("%g %s%s", var.mx_verification_record_priority, var.mx_verification_record_prefix, var.mx_verification_record_suffix) : null
gmail_records = local.verification_record != null ? concat(local.non_verification_records, [local.verification_record]) : local.non_verification_records
dmarc_report_recipient = var.dmarc_report_recipient != null ? var.dmarc_report_recipient : format("hostmaster@%s", local.zone_name)
dmarc_policy = "v=${var.dmarc_protocol_version}; p=${var.dmarc_policy_type}; pct=${var.dmarc_policy_percentage}; rua=mailto:${local.dmarc_report_recipient}; sp=${var.dmarc_subdomain_policy_type} adkim=${var.dmarc_dkim_alignment_mode}; aspf=${var.dmarc_spf_alignment_mode}"
apex_txt_record = var.apex_verification_txt != null ? [var.apex_spf_txt, var.apex_verification_txt] : [var.apex_spf_txt]
}