Skip to content

Commit f7175c4

Browse files
email identity validation added
1 parent 285bcb3 commit f7175c4

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.0"
6+
}
7+
}
8+
}
9+
110
data "aws_caller_identity" "current" {}
211
data "aws_region" "current" {}
312

pinpoint-email.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ resource "aws_pinpoint_email_channel" "email" {
99

1010
application_id = aws_pinpoint_app.project[each.key].application_id
1111
from_address = each.value.from_email
12-
identity = aws_ses_email_identity.email[each.value.from_email].arn
12+
# domain identify (if domain identity verification), if not then Email identity
13+
identity = (each.value.verify_domain_identity) ? aws_ses_domain_identity.domain[split("@", each.value.from_email)[1]].arn : aws_ses_email_identity.email[each.value.from_email].arn
1314
role_arn = aws_iam_role.pinpoint[each.key].arn
1415
}

ses-identity-domain.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
locals {
2-
valid_from_emails = [for p in local.projects_need_email : p.from_email]
3-
valid_to_emails = flatten([for p in local.projects_need_email : (p.to_emails != null) ? p.to_emails : []])
4-
email_identities = toset(distinct(concat(local.valid_from_emails, local.valid_to_emails)))
5-
6-
valid_domains = [for p in local.projects_need_email : split("@", p.from_email)[1]]
7-
domain_identities = toset(distinct(local.valid_domains))
8-
2+
valid_domains = [for p in local.projects_need_email : split("@", p.from_email)[1]]
3+
domain_identities = toset(distinct(local.valid_domains))
94
valid_domains_to_verify = [for p in local.projects_need_domain_verification : split("@", p.from_email)[1]]
105
domains_to_verify = toset(distinct(local.valid_domains_to_verify))
116
}

ses-identity-email.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
locals {
2+
valid_from_emails = [for p in local.projects_need_email : p.from_email]
3+
from_emails_for_identities = flatten([for p in local.projects_need_email : (p.verify_domain_identity) ? [] : [p.from_email]])
4+
valid_to_emails = flatten([for p in local.projects_need_email : (p.to_emails != null) ? p.to_emails : []])
5+
emails_for_identities = toset(distinct(concat(local.from_emails_for_identities, local.valid_to_emails)))
6+
}
17

28
# create all Email identities
39
resource "aws_ses_email_identity" "email" {
4-
for_each = local.email_identities
10+
for_each = local.emails_for_identities
511

612
email = each.value
713
}

0 commit comments

Comments
 (0)