Skip to content

Commit 0dce79b

Browse files
committed
feat: add support for latest downstream cognito-message-sender
- add allow list to by email verifications - use sendgrid an email provider
1 parent eca005a commit 0dce79b

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,15 @@ resource "aws_lambda_function" "email_msg_sender" {
354354

355355
environment {
356356
variables = {
357-
APP_DEBUG_MODE = var.email_sender_debug_mode
358-
APP_LOG_LEVEL = var.service_log_level
359-
APP_KMS_KEY_ID = module.kms_key.key_arn
360-
APP_EMAIL_SENDER_POLICY_PATH = local.email_sender_policy_path
361-
APP_SENDGRID_API_KEY = var.sendgrid_api_key
362-
APP_SENDGRID_EMAIL_VERIFICATION_ENABLED = var.sendgrid_email_verification_enabled
357+
APP_DEBUG_MODE = var.email_sender_debug_mode
358+
APP_LOG_LEVEL = var.service_log_level
359+
APP_KMS_KEY_ID = module.kms_key.key_arn
360+
APP_EMAIL_PROVIDER = var.email_sender_providers[0]
361+
APP_EMAIL_SENDER_POLICY_PATH = local.email_sender_policy_path
362+
APP_SENDGRID_EMAIL_SEND_API_KEY = var.sendgrid_email_send_api_key
363+
APP_SENDGRID_EMAIL_VERIFICATION_API_KEY = coalesce(var.sendgrid_email_verification_api_key, var.sendgrid_api_key)
364+
APP_SENDGRID_EMAIL_VERIFICATION_ALLOWLIST = join(",", var.sendgrid_email_verification_allowlist)
365+
APP_SENDGRID_EMAIL_VERIFICATION_ENABLED = var.sendgrid_email_verification_enabled
363366
}
364367
}
365368

variables.tf

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,54 @@ variable "email_sender_policy_content" {
4646
default = ""
4747
}
4848

49+
variable "email_sender_providers" {
50+
type = list(string)
51+
description = "List of enabled email providers."
52+
default = ["ses"]
53+
54+
validation {
55+
condition = length(var.email_sender_providers)
56+
error_message = "Must define exactly one email provider. Support for more than one coming the future."
57+
}
58+
59+
validation {
60+
condition = alltrue([for x in var.email_sender_providers : contains(["ses", "sendgrid"], x)])
61+
error_message = "Invalid email provider"
62+
}
63+
64+
validation {
65+
condition = !contains(var.email_sender_providers, "sendgrid") || (contains(var.email_sender_providers, "sendgrid") && length(var.sendgrid_email_send_api_key) > 0)
66+
error_message = "SendGrid is set as email provider but its API is not set."
67+
}
68+
}
69+
4970
variable "sendgrid_api_key" {
5071
type = string
51-
description = "The SendGrid API key used to interact with its API."
72+
description = "Deprecated: Use sendgrid_email_send_api_key"
73+
default = ""
74+
}
75+
76+
variable "sendgrid_email_send_api_key" {
77+
type = string
78+
description = "The SendGrid API key used to interact with its Mail Send API."
79+
default = ""
80+
}
81+
82+
variable "sendgrid_email_verification_api_key" {
83+
type = string
84+
description = "The SendGrid API key used to interact with its Email Verification API."
5285
default = ""
86+
87+
validation {
88+
condition = !var.sendgrid_email_verification_enabled || (var.sendgrid_email_verification_enabled && length("${var.sendgrid_email_verification_api_key}${var.sendgrid_api_key}") > 0)
89+
error_message = "SendGrid Email Verification is enabled but API Key is not set."
90+
}
91+
}
92+
93+
variable "sendgrid_email_verification_allowlist" {
94+
type = list(string)
95+
description = "List of email domains that bypass email validation."
96+
default = []
5397
}
5498

5599
variable "sendgrid_email_verification_enabled" {

0 commit comments

Comments
 (0)