Skip to content

Commit 29c5bc7

Browse files
authored
Update production branch (#36)
1 parent 461b17e commit 29c5bc7

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

app-service.tf

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ resource "azurerm_linux_web_app" "app_service" {
4747
"DB_DATABASE" = azurerm_postgresql_flexible_server_database.db.name
4848
"DB_USERNAME" = local.db_config.admin_db_user
4949
"DB_PASSWORD" = local.db_config.admin_db_password
50-
"MAIL_MAILER" = "smtp"
51-
"MAIL_HOST" = var.mail_host
52-
"MAIL_PORT" = var.mail_port
53-
"MAIL_USERNAME" = var.mail_username
54-
"MAIL_PASSWORD" = var.mail_password
55-
"MAIL_ENCRYPTION" = var.mail_encryption
56-
"MAIL_FROM_ADDRESS" = var.mail_from_address
5750
"FILESYSTEM_DRIVER" = "azure"
5851
"FILESYSTEM_CLOUD" = "azure"
5952
"AZURE_STORAGE_NAME" = azurerm_storage_account.storage_account.name
@@ -63,6 +56,19 @@ resource "azurerm_linux_web_app" "app_service" {
6356
"ADMIN_PASSWORD" = random_password.admin_password.result
6457
"SENTRY_DSN" = var.sentry_dsn
6558
"SENTRY_ENVIRONMENT" = coalesce(var.sentry_environment, var.project_slug)
59+
60+
"MAIL_MAILER" = local.mail.mailer
61+
"MAIL_FROM_ADDRESS" = local.mail.from
62+
# SMTP
63+
"MAIL_HOST" = local.mail.smtp.host
64+
"MAIL_PORT" = local.mail.smtp.port
65+
"MAIL_USERNAME" = local.mail.smtp.username
66+
"MAIL_PASSWORD" = local.mail.smtp.password
67+
"MAIL_ENCRYPTION" = local.mail.smtp.encryption
68+
69+
# Azure Communication Services
70+
"AZURE_MAIL_RESOURCE_NAME" = local.mail.azure.resource_name
71+
"AZURE_MAIL_KEY" = local.mail.azure.key
6672
}
6773

6874
connection_string {

locals.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,22 @@ locals {
3838
public_network_access_enabled = true
3939
zone = var.database_az_enabled ? var.database_az : null
4040
}
41+
42+
mail = {
43+
mailer = var.enable_acs ? "azure" : "smtp"
44+
from = var.enable_acs ? "${azurerm_email_communication_service_domain_sender_username.email[0].name}@${azurerm_email_communication_service_domain.email[0].from_sender_domain}" : var.mail_from_address
45+
46+
smtp = {
47+
host = var.enable_acs ? null : var.mail_host
48+
port = var.enable_acs ? null : var.mail_port
49+
username = var.enable_acs ? null : var.mail_username
50+
password = var.enable_acs ? null : var.mail_password
51+
encryption = var.mail_encryption
52+
}
53+
54+
azure = {
55+
resource_name = var.enable_acs ? azurerm_communication_service.comms[0].name : null
56+
key = var.enable_acs ? azurerm_communication_service.comms[0].primary_key : null
57+
}
58+
}
4159
}

mail.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "azurerm_communication_service" "comms" {
2+
count = var.enable_acs ? 1 : 0
3+
name = "acs-${local.namespace}"
4+
resource_group_name = azurerm_resource_group.resource_group.name
5+
data_location = var.acs_data_location
6+
}
7+
8+
resource "azurerm_email_communication_service" "email" {
9+
count = var.enable_acs ? 1 : 0
10+
name = "acs-email-${local.namespace}"
11+
resource_group_name = azurerm_resource_group.resource_group.name
12+
data_location = var.acs_data_location
13+
}
14+
15+
resource "azurerm_email_communication_service_domain" "email" {
16+
count = var.enable_acs ? 1 : 0
17+
name = "AzureManagedDomain"
18+
email_service_id = azurerm_email_communication_service.email[count.index].id
19+
domain_management = "AzureManaged"
20+
}
21+
22+
resource "azurerm_communication_service_email_domain_association" "association" {
23+
count = var.enable_acs ? 1 : 0
24+
email_service_domain_id = azurerm_email_communication_service_domain.email[count.index].id
25+
communication_service_id = azurerm_communication_service.comms[count.index].id
26+
}
27+
28+
resource "azurerm_email_communication_service_domain_sender_username" "email" {
29+
count = var.enable_acs ? 1 : 0
30+
name = "no-reply"
31+
email_service_domain_id = azurerm_email_communication_service_domain.email[count.index].id
32+
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ variable "region" {
3939
default = "North Europe"
4040
}
4141

42+
variable "enable_acs" {
43+
description = "Enable Azure Communication Service for email sending"
44+
type = bool
45+
default = false
46+
}
47+
48+
variable "acs_data_location" {
49+
description = "Azure Communication Service data location"
50+
type = string
51+
default = "Europe"
52+
}
53+
4254
variable "mail_host" {
4355
description = "SMTP host"
4456
type = string

0 commit comments

Comments
 (0)