Set Up Azure Active Directory Domain Services (AADDS) With Terraform
I wanted to revisit this topic for a while because the previous guide I wrote about setting up Azure Active Directory Domain Services (AADDS) with Terraform is outdated. However, the article still attracts around 100 visitors per month. People also keep downloading the deprecated Terraform module I created. Time to set things right!
With v2.69.0 of the official Terraform azurerm provider released, the active_directory_domain_service
resource is now available. In this post, I’ll briefly walk you through the required steps of setting up AADDS. See also the official Microsoft documentation for more details.
I also published the code to a sample GitHub repo.
What Are Azure Active Directory Domain Services?
Bringing traditional Active Directory Domain Services (AD DS) to the cloud, typically required to set up, secure, and maintain domain controllers (DCs). Azure Active Directory Domain Services (AADDS or Azure AD DS) is a Microsoft-managed solution, providing a subset of traditional AD DS features without the need to self-manage DCs. One such service that requires AD DS features is Azure Virtual Desktop (AVD).
Prerequisites
Before getting started, you need the following things:
- Active Azure subscription
- Azure Active Directory (Azure AD / AAD) tenant
Service Principal
First, create the service principal for the Domain Controller Services published application. In public Azure, the ID is 2565bd9d-da50-47d4-8b85-4c97f669dc36
. For other clouds the value is 6ba9a5d4-8456-4118-b521-9c5ca10cdf84
.
If the service principal already exists, the following error occurs:
Import the service principal with the following command:
Note that 11111111-1111-1111-1111-111111111111
is the Object ID and not the Application ID.
Microsoft.AAD
Resource Provider Registration
To use AADDS, register the Microsoft.AAD
resource provider:
If the provider is already registered, you can import it into Terraform with the following command:
DC Admin Group and User
Next, create an Azure AD group for users administering the AADDS domain and add an admin.
Resource Group
Add the resource group for AADDS resources:
Network Resources
Add the virtual network and subnet next.
To lock down access to the managed domain, add the following network security group. The AllowRD
and AllowPSRemoting
rules allow the Azure platform to monitor, manage, and update the managed domain:
When you enable secure LDAP, it’s recommended to create an additional security rule to restrict inbound LDAPS access to specific IP addresses to protect the managed domain from brute force attacks:
AADDS Managed Domain
Finally, deploy the AADDS managed domain:
Run terraform apply
to deploy everything. It takes an hour to complete. Please share your thoughts with me in the comments or on Twitter!