Search code examples
azureterraformazure-communication-services

Connect Azure Email Communication Service to Azure Communication Service using Terraform


I'm trying to set up new Azure resources, Azure Email Communication Service(AECS) and Azure Communication Service(ACS). Is there a way to connect AECS to ACS only using Terraform?

I want to do this https://mailtrap.io/blog/azure-send-email/ not using Azure UI, programatically on Terraform.

I also want to set up custom domain and get verified for my email services using terraform. Is it possible?

Thanks!

I searched online, but didn't find any resource.


Solution

  • To connect Azure Email Communication Service to Azure Communication Service, there is no direct service provider registered for it. Instead, you can use azapi_update_resource as detailed below.

    Firstly, I have created a communication service and an email communication service with terraform and referenced them in the azapi_update_resource with below configuration.

    terraform {
      required_providers {
        azapi = {
          source = "Azure/azapi"
          version = "1.13.1"
        }
      }
    }
    provider "azapi" {}
    provider "azurerm"{
    features{}
    }
    resource "azurerm_communication_service" "example" {
      name                = "jahcomm"
      resource_group_name = data.azurerm_resource_group.example.name
      data_location       = "United States"
    }
    resource "azurerm_email_communication_service" "example" {
      name                = "jah-emailcommunicationservice"
      resource_group_name = data.azurerm_resource_group.example.name
      data_location       = "United States"
    }
    

    Communication service and an email service has been deployed.

    enter image description here

    enter image description here

    Now I have used azapi_update_resource to link the services with a domain as shown below.

    resource "azapi_update_resource" "update" {
      type      = "Microsoft.Communication/communicationServices@2022-07-01-preview"
      resource_id = data.azurerm_communication_service.example.id
    
      body = jsonencode({
        properties = {
          linkedDomains = [
            "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Communication/EmailServices/jah-emailcommunicationservice/domains/AzureManagedDomain"
          ]    
        }
      })
    }
    

    Deployment succeeded:

    enter image description here

    enter image description here

    Refer Github issue for the relevant information.