Skip to content
Merged
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
15 changes: 9 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,15 @@ resource "aws_lambda_function" "email_msg_sender" {

environment {
variables = {
APP_DEBUG_MODE = var.email_sender_debug_mode
APP_LOG_LEVEL = var.service_log_level
APP_KMS_KEY_ID = module.kms_key.key_arn
APP_EMAIL_SENDER_POLICY_PATH = local.email_sender_policy_path
APP_SENDGRID_API_KEY = var.sendgrid_api_key
APP_SENDGRID_EMAIL_VERIFICATION_ENABLED = var.sendgrid_email_verification_enabled
APP_DEBUG_MODE = var.email_sender_debug_mode
APP_LOG_LEVEL = var.service_log_level
APP_KMS_KEY_ID = module.kms_key.key_arn
APP_EMAIL_PROVIDER = var.email_sender_providers[0]
APP_EMAIL_SENDER_POLICY_PATH = local.email_sender_policy_path
APP_SENDGRID_EMAIL_SEND_API_KEY = var.sendgrid_email_send_api_key
APP_SENDGRID_EMAIL_VERIFICATION_API_KEY = coalesce(var.sendgrid_email_verification_api_key, var.sendgrid_api_key)
APP_SENDGRID_EMAIL_VERIFICATION_ALLOWLIST = join(",", var.sendgrid_email_verification_allowlist)
APP_SENDGRID_EMAIL_VERIFICATION_ENABLED = var.sendgrid_email_verification_enabled
}
}

Expand Down
46 changes: 45 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,54 @@ variable "email_sender_policy_content" {
default = ""
}

variable "email_sender_providers" {
type = list(string)
description = "List of enabled email providers."
default = ["ses"]

validation {
condition = length(var.email_sender_providers) == 1
error_message = "Must define exactly one email provider. Support for more than one coming the future."
}

validation {
condition = alltrue([for x in var.email_sender_providers : contains(["ses", "sendgrid"], x)])
error_message = "Invalid email provider"
}

validation {
condition = !contains(var.email_sender_providers, "sendgrid") || (contains(var.email_sender_providers, "sendgrid") && try(length(var.sendgrid_email_send_api_key) > 0, false))
error_message = "SendGrid is set as email provider but its API is not set."
}
}

variable "sendgrid_api_key" {
type = string
description = "The SendGrid API key used to interact with its API."
description = "Deprecated: Use sendgrid_email_send_api_key"
default = ""
}

variable "sendgrid_email_send_api_key" {
type = string
description = "The SendGrid API key used to interact with its Mail Send API."
default = ""
}

variable "sendgrid_email_verification_api_key" {
type = string
description = "The SendGrid API key used to interact with its Email Verification API."
default = ""

validation {
condition = !var.sendgrid_email_verification_enabled || (var.sendgrid_email_verification_enabled && try(length("${var.sendgrid_email_verification_api_key}${var.sendgrid_api_key}") > 0, false))
error_message = "SendGrid Email Verification is enabled but API Key is not set."
}
}

variable "sendgrid_email_verification_allowlist" {
type = list(string)
description = "List of email domains that bypass email validation."
default = []
}

variable "sendgrid_email_verification_enabled" {
Expand Down