Skip to content

Commit 680d6ca

Browse files
chrisbloerobg-test
authored andcommitted
[PRM-741] Rearchitect SES
1 parent 94c6418 commit 680d6ca

18 files changed

Lines changed: 52 additions & 170 deletions

infrastructure/buckets.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ module "ses-feedback-store" {
527527
force_destroy = local.is_force_destroy
528528
}
529529

530-
resource "aws_s3_bucket_lifecycle_configuration" "ses_feedback_lifecycle_rules" {
530+
resource "aws_s3_bucket_lifecycle_configuration" "ses_feedback_store" {
531531
bucket = module.ses-feedback-store.bucket_id
532532

533533
rule {

infrastructure/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ data "aws_iam_policy_document" "reporting_ses" {
372372
condition {
373373
test = "StringEquals"
374374
variable = "ses:FromAddress"
375-
values = [local.reporting_ses_from_address_value]
375+
values = [module.ses.report_email_address]
376376
}
377377
}
378378
}

infrastructure/lambda-report-distribution.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module "report-distribution-lambda" {
2121
CONTACT_TABLE_NAME = module.bulk_upload_contact_lookup_table.table_name
2222

2323
PRM_MAILBOX_EMAIL = data.aws_ssm_parameter.prm_mailbox_email.value
24-
SES_FROM_ADDRESS = local.reporting_ses_from_address_value
24+
SES_FROM_ADDRESS = module.ses.report_email_address
2525
SES_CONFIGURATION_SET = aws_ses_configuration_set.reporting.name
2626
}
2727

infrastructure/lambda-send-feedback.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module "send-feedback-lambda" {
105105
depends_on = [
106106
aws_api_gateway_rest_api.ndr_doc_store_api,
107107
module.send-feedback-gateway,
108-
module.ndr-feedback-mailbox,
108+
module.ses,
109109
module.ndr-app-config
110110
]
111111
}

infrastructure/lambda-ses-feedback-monitor.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ module "ses-feedback-monitor-lambda" {
1919
SES_FEEDBACK_BUCKET_NAME = module.ses-feedback-store.bucket_id
2020
SES_FEEDBACK_PREFIX = "ses-feedback/"
2121
PRM_MAILBOX_EMAIL = data.aws_ssm_parameter.prm_mailbox_email.value
22-
SES_FROM_ADDRESS = local.reporting_ses_from_address_value
22+
SES_FROM_ADDRESS = module.ses.report_email_address
2323
ALERT_ON_EVENT_TYPES = "BOUNCE,REJECT"
2424
}
2525

2626
is_gateway_integration_needed = false
2727
is_invoked_from_gateway = false
28-
29-
depends_on = [
30-
module.ses-feedback-store
31-
]
3228
}

infrastructure/modules/ses/main.tf

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_ses_domain_identity" "ndr_ses" {
2-
domain = var.domain
2+
domain = "${terraform.workspace}.${var.domain}"
33
count = var.enable ? 1 : 0
44
}
55

@@ -12,7 +12,7 @@ resource "aws_ses_domain_dkim" "ndr_dkim" {
1212

1313
resource "aws_route53_record" "ndr_ses_dkim_record" {
1414
zone_id = var.zone_id
15-
name = "${aws_ses_domain_dkim.ndr_dkim[0].dkim_tokens[count.index]}._domainkey.${var.domain_prefix}"
15+
name = "${aws_ses_domain_dkim.ndr_dkim[0].dkim_tokens[count.index]}._domainkey.${terraform.workspace}"
1616
type = "CNAME"
1717
ttl = 1800
1818
records = ["${aws_ses_domain_dkim.ndr_dkim[0].dkim_tokens[count.index]}.dkim.amazonses.com"]
@@ -27,3 +27,35 @@ resource "aws_ses_domain_identity_verification" "ndr_ses_domain_verification" {
2727
count = var.enable ? 1 : 0
2828
depends_on = [aws_route53_record.ndr_ses_dkim_record[0]]
2929
}
30+
31+
resource "aws_ses_domain_mail_from" "reporting" {
32+
count = var.enable ? 1 : 0
33+
domain = module.ses.domain_identity
34+
mail_from_domain = "mail.${terraform.workspace}.${var.domain}"
35+
36+
behavior_on_mx_failure = "UseDefaultValue"
37+
}
38+
39+
resource "aws_route53_record" "ses_mail_from_mx" {
40+
count = var.enable ? 1 : 0
41+
zone_id = module.route53_fargate_ui.zone_id
42+
name = "mail.${terraform.workspace}.${var.domain}"
43+
type = "MX"
44+
ttl = 600
45+
46+
records = [
47+
"10 feedback-smtp.eu-west-2.amazonses.com"
48+
]
49+
}
50+
51+
resource "aws_route53_record" "ses_mail_from_spf" {
52+
count = var.enable ? 1 : 0
53+
zone_id = module.route53_fargate_ui.zone_id
54+
name = "mail.${terraform.workspace}.${var.domain}"
55+
type = "TXT"
56+
ttl = 600
57+
58+
records = [
59+
"v=spf1 include:amazonses.com -all"
60+
]
61+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "report_email_address" {
2+
value = "ndr-reports@${aws_ses_domain_identity.ndr_ses[0].domain}"
3+
}

infrastructure/modules/ses/variable.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
variable "domain_prefix" {
2-
description = "The subdomain or prefix used to construct the full SES identity domain."
3-
type = string
4-
}
5-
61
variable "domain" {
72
description = "The root domain name to be registered with SES and used for verification."
83
type = string

infrastructure/modules/sns/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ module "sns_topic" {
9393
| <a name="input_enable_ses_publish"></a> [enable\_ses\_publish](#input\_enable\_ses\_publish) | If true, module appends a statement allowing ses.amazonaws.com to SNS:Publish to this topic. | `bool` | `false` | no |
9494
| <a name="input_is_topic_endpoint_list"></a> [is\_topic\_endpoint\_list](#input\_is\_topic\_endpoint\_list) | Whether to use the topic\_endpoint\_list instead of a single topic\_endpoint. | `bool` | `false` | no |
9595
| <a name="input_raw_message_delivery"></a> [raw\_message\_delivery](#input\_raw\_message\_delivery) | Whether to enable raw message delivery for the SNS subscription. | `bool` | `false` | no |
96-
| <a name="input_ses_source_account_id"></a> [ses\_source\_account\_id](#input\_ses\_source\_account\_id) | AWS account ID used in the AWS:SourceAccount condition for SES publishing. | `string` | `""` | no |
9796
| <a name="input_sns_encryption_key_id"></a> [sns\_encryption\_key\_id](#input\_sns\_encryption\_key\_id) | The ARN (or ID) of the KMS key used for encrypting the SNS topic. | `string` | n/a | yes |
9897
| <a name="input_sqs_feedback"></a> [sqs\_feedback](#input\_sqs\_feedback) | Map of IAM role ARNs and sample rate for success and failure feedback. | `map(string)` | `{}` | no |
9998
| <a name="input_topic_endpoint"></a> [topic\_endpoint](#input\_topic\_endpoint) | A single endpoint (e.g., SQS queue or Lambda function ARN) to subscribe to the topic. | `any` | `null` | no |

infrastructure/modules/sns/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
data "aws_caller_identity" "current" {}
2+
13
locals {
24
base_topic_policy_json = var.topic_policy_json != null ? var.topic_policy_json : var.delivery_policy
35
base_topic_policy_obj = jsondecode(local.base_topic_policy_json)
@@ -24,7 +26,7 @@ locals {
2426
Resource = aws_sns_topic.sns_topic.arn
2527
Condition = {
2628
StringEquals = {
27-
"AWS:SourceAccount" = var.ses_source_account_id
29+
"AWS:SourceAccount" = data.aws_caller_identity.current.account_id
2830
}
2931
}
3032
} : null

0 commit comments

Comments
 (0)