How to Deploy Active Directory (AD) Domain Controller (DC) Virtual Machine (VM) in Azure with Terraform
This code:
- Define the Azure Provider
- Create a Resource Group
- Create a VNET
- Create a Subnet
- Create NSG (Network Security Group) for Client Machines to AD Domain Controllers.
- Create NSG (Network Security Group) for Communications between Domain Controllers.
- Create a NIC (Network Card) in this Subnet
- Create the Virtual Machine to Create a New AD Forest and Domain
- Create the Virtual Machine to Join an Existing Domain
- Clone the repo
- Move the files "vm-dc2-main.tf" and "vm-dc2-output.tf" outside the folder
- Execute "terraform init"
- Execute "terraform apply"
- When execution is complete and the DC1 is running, copy the files "vm-dc2-main.tf ", and "vm-dc2-output.tf" back to the folder
- Execute "terraform apply"
This code uses assign a public to each domain controller.
This is NOT recommended for production environments.
If you planning to use in production environments, make the following changes:
- Remove references to resource "azurerm_public_ip" in both VM1 and VM2 files
- Remove the line public_ip_address_id = azurerm_public_ip.dcX-eip.id in resource "azurerm_network_interface" for both VM1 and VM2 files. Replace X for 1 or 2.