Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Created June 27, 2023 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasPe/e27b33ed1159b0003801216e898a51e5 to your computer and use it in GitHub Desktop.
Save ThomasPe/e27b33ed1159b0003801216e898a51e5 to your computer and use it in GitHub Desktop.
Bicep IaC to deploy An Azure Email Communication Service
param isProd bool = false
param communicationServiceName string = 'cs-medienstudio-dev'
param emailServiceName string = 'es-medienstudio-dev'
// Email Communication Service
resource emailService 'Microsoft.Communication/emailServices@2023-03-31' = {
name: emailServiceName
location: 'global'
properties: {
dataLocation: 'Europe'
}
}
// Email Communication Services Domain (Azure Managed)
resource emailServiceAzureDomain 'Microsoft.Communication/emailServices/domains@2023-03-31' = if (!isProd) {
parent: emailService
name: 'AzureManagedDomain'
location: 'global'
properties: {
domainManagement: 'AzureManaged'
userEngagementTracking: 'Disabled'
}
}
// SenderUsername (Azure Managed Domain)
resource senderUserNameAzureDomain 'Microsoft.Communication/emailServices/domains/senderUsernames@2023-03-31' = if (!isProd) {
parent: emailServiceAzureDomain
name: 'donotreply'
properties: {
username: 'DoNotReply'
displayName: 'DoNotReply'
}
}
// Email Communication Services Domain (Customer Managed)
resource emailServiceCustomDomain 'Microsoft.Communication/emailServices/domains@2023-03-31' = if (isProd) {
parent: emailService
name: 'pentenrieder.dev'
location: 'global'
properties: {
domainManagement: 'CustomerManaged '
userEngagementTracking: 'Disabled'
}
}
// SenderUsername (Customer Managed Domain)
resource senderUserNameCustomDomain 'Microsoft.Communication/emailServices/domains/senderUsernames@2023-03-31' = if (isProd) {
parent: emailServiceCustomDomain
name: 'donotreply'
properties: {
username: 'DoNotReply'
displayName: 'DoNotReply'
}
}
// Link the correct domain based on the environment
var emailServiceResource = isProd ? emailServiceCustomDomain.id : emailServiceAzureDomain.id
// Communication Service
resource communcationService 'Microsoft.Communication/communicationServices@2023-03-31' = {
name: communicationServiceName
location: 'global'
properties: {
dataLocation: 'Europe'
linkedDomains: [
emailServiceResource
]
}
}
// put this connection string into a key vault or (even better) use a Managed Identity to access Communication Service
var communicationServiceConnectionString = communcationService.listKeys().primaryConnectionString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment