Free lab guide

The home lab that got me into cloud.

You'll build a Windows 11 virtual machine at home, use Terraform to build a Windows Server domain controller in Azure, connect the two over a VPN, and join your home VM to the domain. It's the hybrid cloud setup companies run every day, on your own machine.

About 43¢ an hour while it runs, and one command deletes all of it.

  • Every step, command and file
  • The PDF and Terraform files by email
  • Goes with the video

Free · opens right here

I'll also email you the files (the PDF and the six Terraform files), then a short note every once in a while about getting into cloud. Leave whenever. Your email goes to Kit, the service I send with; this browser keeps a small note (nothing personal) so the guide opens straight away next time.

It's open.

The whole guide is right below.

Check your inbox too: the button in my email gets you the files (the PDF and the six Terraform files) and confirms you're on the list.

Welcome back.

The whole guide is open below. Your files are in the email I sent you when you signed up.

Free lab guide

The whole guide is right below.

Contents
  1. Before you start
  2. 1 · The Windows 11 VM
  3. 2 · Your tools
  4. 3 · The VPN certificate
  5. 4 · Terraform builds the server
  6. 5 · The VPN
  7. 6 · Join the domain
  8. 7 · Destroy it
  9. If something breaks
  10. More free stuff
  11. Appendix A · group.tf
  12. Appendix B · vm.tf
  13. Your resume line

Follow along with the video, and keep this guide open next to it: it has every command and file I use, in order.

Before you start

What you'll build

What you'll build A Windows 11 VM called Titan-Lab runs in VirtualBox on your PC, with VS Code, Terraform and the Azure CLI. A point-to-site VPN (IKEv2, certificate) connects it to Azure: resource group Titan-Lab-RG in East US 2, virtual network Titan-VNET 10.0.0.0/24. The VPN gateway vpngw-lab sits in GatewaySubnet 10.0.0.32/27, and DC01, a Windows Server 2025 domain controller for lab.local at 10.0.0.4, sits in server-sn 10.0.0.0/27. YOUR PC· VirtualBox Windows 11 VM Titan-Lab VS Code · Terraform · Azure CLI Point-to-site VPN IKEv2 · certificate AZURE· Titan-Lab-RG · East US 2 Titan-VNET · 10.0.0.0/24 GatewaySubnet · 10.0.0.32/27 VPN gateway vpngw-lab server-sn · 10.0.0.0/27 DC01 Windows Server 2025 · domain controller lab.local · 10.0.0.4

What you need

  • A Windows PC with at least 16 GB of RAM and about 80 GB of free disk space.
  • Virtualization turned on in your PC's BIOS or UEFI: Intel VT-x (Intel Virtualization Technology) or AMD-V (often called SVM Mode). Most PCs have it on already. If VirtualBox ever says VT-x or AMD-V is disabled or not available, restart into your firmware (Settings → System → Recovery → Advanced startup → Restart now, then Troubleshoot → Advanced options → UEFI Firmware Settings → Restart; on Windows 10, start from Settings → Update & Security → Recovery), turn it on, then save and exit. No UEFI Firmware Settings tile? Your PC starts in the older BIOS mode: restart it and press the setup key the first screen shows (often Del, F2 or F10).
  • A Microsoft account for Azure.
  • About 2 to 3 hours. Most of it is waiting: the Windows 11 download, the install, and the VPN gateway (25 to 45 minutes).

What it costs

About 43¢ an hour while it's running (East US 2 list prices, November 2026). Build it, practice for an evening and destroy it, and it's a dollar or two. Left running, it's about $10 a day, or $72 a week. The VPN gateway is about half of that and DC01 most of the rest, and they bill by the hour whether you're using them or not. Azure's free credit covers it if you still have it. Either way, set the $5 budget in section 2 and destroy everything when you're done (section 7). One command builds it back.

How to read the code blocks

LabelWhat it means
COPY AND PASTEPaste it exactly as it is.
TEMPLATEType this one yourself while you watch: fill in the parts in < > (the comment next to each one says what I used). This is where you learn Terraform. The finished file is at the bottom of this guide (Appendix A and B), ready to paste, if you get stuck or want to check yours.
KNOW IT BY HEARTA command you'll type for the rest of your career. Type it, don't paste it.

The video times next to each step are where I do it on screen. Two things in this guide aren't in the video, and both are marked: switching on Azure's network and VM services (section 2), and one line in vm.tf (section 4). Do both. Typing vm.tf along with the video? Add provision_vm_agent = true when I add its block, not later (section 4 says why). And if you destroy the lab and build it again, "Bringing it back" in section 7 has three things to redo, not just the one the video mentions.

The rest of the guide

Parts 1 to 7 are one email away.

Every step, command and Terraform file, plus what to do when something breaks, the finished files and a line for your resume. Pop in your email and it all opens right here, instantly.

Put your email in at titancloud.education/home-lab to open them.

I'll also email you the files (the PDF and the six Terraform files), then a short note every once in a while about getting into cloud. Leave whenever. Your email goes to Kit, the service I send with; this browser keeps a small note (nothing personal) so the guide opens straight away next time.

1 · The Windows 11 VM

Get Windows 11 Enterprise video 0:36

  1. Search "Windows 11 Enterprise ISO" and open Microsoft's Evaluation Center (the first link, from microsoft.com).
  2. Fill out the form. It's a free 90-day evaluation: no product key, nothing to cancel.
  3. Download the ISO, Enterprise download (64-bit, your language). It's big; start it and move on.

Install VirtualBox video 1:40

  1. Go to virtualbox.org, click Download, then Windows hosts. That gets you VirtualBox 7.2. (In the video I'm on an older 7.0 I already had, so a few screens look a little different. The next part gives both names.)
  2. Run the installer and keep the defaults. Click Yes if it warns about a Network Disconnection (your internet drops for a moment) or about missing Python (you don't need it). If it says it needs the Microsoft Visual C++ 2019 Redistributable, install Microsoft's x64 package from aka.ms/vc14/vc_redist.x64.exe, then run the VirtualBox installer again.
  3. Open VirtualBox.

Create the VM video 2:24

On 7.2 the window is called New Virtual Machine, a few labels are different (in brackets below), and the disk size is on the hardware page. If every setting shows on one page, that's 7.2's expert view: choose File → Preferences → Basic and click New again.

  1. Click New (on 7.2: Home, then New).
  2. Name [VM Name]: Titan-Lab. Keep the folder VirtualBox suggests.
  3. ISO Image: pick the Windows 11 ISO you downloaded. VirtualBox detects Windows 11 Enterprise Evaluation [in OS Edition]. Keep the unattended install on: don't tick Skip Unattended Installation (on 7.2, keep Proceed with Unattended Installation ticked). Click Next.
  4. Unattended Guest OS Install Setup [Set up unattended guest OS installation]:
    • Username [User Name]: titanuser (or anything you like).
    • Password: something simple you'll remember. It's a home lab.
    • Hostname [Host Name]: keep Titan-Lab.
    • Click Next.
  5. Hardware [Specify virtual hardware]: keep 4096 MB of Base Memory and 2 Processors [Number of CPUs], Windows 11's minimum, and leave Enable EFI [Use EFI] ticked. On 7.2 this page also has Disk Size: set it to 64 GB. Click Next.
  6. Virtual Hard disk (7.0 only; 7.2 skips this page): keep Create a Virtual Hard Disk Now and set Disk Size to 64 GB. That's Windows 11's minimum and plenty for this lab, so you don't need the 80 GB it suggests (the file only grows as Windows fills it). Click Next. On the Summary page, click Finish.
  7. The VM starts. When you see "Press any key to boot from CD or DVD", press a key. Windows installs itself; let it finish. If you miss the prompt and VirtualBox says The virtual machine failed to boot, pick your Windows ISO in the DVD list, click Mount and Retry Boot, and press a key this time.

Copy and paste between your PC and the VM video 4:10

You'll be pasting a lot from this guide, so set this up now.

  1. In the VM's window menu: Devices → Insert Guest Additions CD image.
  2. In the VM, open File Explorer, open the VirtualBox Guest Additions CD, run VBoxWindowsAdditions, click Next and Install.
  3. Click Finish to reboot the VM. You have to.
  4. While it reboots: in the VirtualBox window, select Titan-Lab → Settings → General → Advanced [Features] → Shared Clipboard → Bidirectional → OK. (Or in the VM's window menu: Devices → Shared Clipboard → Bidirectional.)

You can stop here and just practice breaking and fixing Windows: nothing you do in the VM touches your real PC. To go further into cloud engineering, keep going.

2 · Your tools

Everything from here happens inside the Windows 11 VM.

Install VS Code video 5:25

  1. Open Microsoft Edge and go to code.visualstudio.com. Click Download for Windows.
  2. Accept the agreement, keep the default path, and tick Create a desktop icon.
  3. Skip GitHub Copilot. You're learning to write the code yourself.
  4. Install, then open VS Code.

Your Azure account video 6:26

  1. Go to azure.microsoft.com and click Try Azure for free (or sign in if you already have an account).
  2. If your free credit is used up, a Pay-As-You-Go subscription works. It bills you for what you use, so do the next step.

Set a budget video 7:14

  1. In the Azure portal, search Budgets and click Add.
  2. Name it anything, keep Monthly, and set the amount to $5.
  3. Set an alert (for example at 80% and 100%) with your email, then Create.

A budget only emails you: it doesn't stop anything or cap your bill. Destroying the lab is what stops the cost.

Install Terraform and the Azure CLI video 8:09

In VS Code: Terminal → New Terminal. Then:

COPY AND PASTE
winget install --exact --id Hashicorp.Terraform --source winget
COPY AND PASTE
winget install --exact --id Microsoft.AzureCLI --source winget

Click Yes when Windows asks to allow changes. Then close VS Code and open it again, so the terminal finds the new commands.

Sign in to Azure video 9:08

KNOW IT BY HEART
az login

Sign in with the same account as your Azure subscription. When it lists your subscriptions, type the number next to yours.

If you get "Authentication failed", the end of the error tells you what to run: az login with your tenant. Copy the tenant ID from the error into this:

KNOW IT BY HEARTwith your tenant ID in place of <YOUR_TENANT_ID>
az login --tenant <YOUR_TENANT_ID>

Tip: if the terminal gets cluttered, press Ctrl+L or type clear.

Switch on networking and VMs not in the video

Azure makes you switch on (register) a service before you can build with it. On a new subscription, Microsoft.Network (networks and the VPN) and Microsoft.Compute (VMs, disks and extensions) are off, and the Terraform provider version this guide uses (5.0.0) doesn't switch them on for you. Do this once, right after az login:

COPY AND PASTE
az provider register --namespace Microsoft.Network --wait
COPY AND PASTE
az provider register --namespace Microsoft.Compute --wait

Each one can take a few minutes and shows nothing while it works: it's done when the prompt comes back. Never assume it worked. Check it:

COPY AND PASTE
az provider show --namespace Microsoft.Network --query registrationState --output tsv
az provider show --namespace Microsoft.Compute --query registrationState --output tsv

Both should say Registered. (The portal way: Subscriptions → your subscription → Settings → Resource providers → select it → Register.)

3 · The VPN certificate video 10:12

This step lets your VM at home connect to the server you'll build in Azure. It's optional if you only want the Terraform part, but do it: it's how you get the full Active Directory experience.

Nobody knows this one by heart (I adapted it from an answer I found online, which is what cloud engineers do). It makes two certificates: a root that you give to Azure, and a child that stays in this VM and proves it's you when you connect.

Do this signed in as titanuser, the Windows user who'll click Connect on the VPN later. The certificates go into that user's own store; made by a different user, the VPN fails with error 798.

  1. Click Start, type PowerShell, right-click Windows PowerShell → Run as administrator → Yes.
  2. Paste this whole block and press Enter:
COPY AND PASTE
New-Item -ItemType Directory -Path C:\home-lab -Force | Out-Null
$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature -Subject 'CN=P2SRootCert' -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -CertStoreLocation 'Cert:\CurrentUser\My' -KeyUsageProperty Sign -KeyUsage CertSign
New-SelfSignedCertificate -Type Custom -DnsName P2SChildCert -KeySpec Signature -Subject 'CN=P2SChildCert' -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -CertStoreLocation 'Cert:\CurrentUser\My' -Signer $cert -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.2')
[Convert]::ToBase64String($cert.RawData) | Set-Content -Encoding ascii C:\home-lab\P2SRootCert-base64.txt
  1. Never assume it worked. Check it:
COPY AND PASTE
Get-ChildItem Cert:\CurrentUser\My

You should see CN=P2SRootCert and CN=P2SChildCert. The root certificate's public part is now in C:\home-lab\P2SRootCert-base64.txt; Terraform reads it in section 5.

4 · Terraform builds the server

A folder for the code video 11:50

  1. In VS Code: File → Open Folder.
  2. Go to Documents, make a New folder called Terraform, and Select Folder.
  3. If a Restricted Mode banner shows at the top, click Manage and trust the folder.

Every file below goes in this folder. Make each one with the New File button in the Explorer, and press Ctrl+S to save it after you type or paste (a dot on the file's tab means it isn't saved yet). Terraform only reads what's saved, and that goes for every change you make later too.

main.tf: the provider video 12:18

This tells Terraform you're building in Azure, and which version of the Azure provider to use.

COPY AND PASTEmain.tf
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=5.0.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}

When you look things up in the Terraform docs (registry.terraform.io, azurerm), switch the docs to version 5.0.0, the version in this file, and make sure you're on the azurerm_virtual_machine page. azurerm_windows_virtual_machine is a different resource with different settings.

group.tf: resource group, network, subnet video 16:15

Every resource gets two names:

  • the label in quotes after the resource type (like labrg) is how your code refers to it;
  • name is what it's called in Azure.
TEMPLATEgroup.tfnot copy and paste on purpose: type it while you watch. The finished file is in Appendix A at the bottom.
# Create a resource group
resource "azurerm_resource_group" "<label>" {          # labrg
  name     = "<name in Azure>"                        # Titan-Lab-RG
  location = "<region>"                               # eastus2 (the cheapest region)
}

# Create a virtual network within the resource group
resource "azurerm_virtual_network" "<label>" {         # vnet
  name                = "<name in Azure>"             # Titan-VNET
  resource_group_name = azurerm_resource_group.<resource group label>.name
  location            = azurerm_resource_group.<resource group label>.location
  address_space       = ["<range>"]                   # 10.0.0.0/24: 256 addresses, plenty
}

resource "azurerm_subnet" "<label>" {                  # server
  name                 = "<name in Azure>"            # server-sn
  resource_group_name  = azurerm_resource_group.<resource group label>.name
  virtual_network_name = azurerm_virtual_network.<network label>.name
  address_prefixes     = ["<range>"]                  # 10.0.0.0/27: 32 addresses, just for servers
}

Use these labels: labrg, vnet and server. vpn.tf (copy and paste, section 5) refers to labrg, and the finished files in Appendix A and B use all three.

vm.tf: the network card and the virtual machine video 19:00

This server becomes your domain controller: the server that manages the other computers on the domain.

TEMPLATEvm.tftype it while you watch. The finished file is in Appendix B at the bottom.
resource "azurerm_network_interface" "<label>" {        # dc01
  name                = "<name in Azure>"              # nic-dc01
  location            = azurerm_resource_group.<resource group label>.location
  resource_group_name = azurerm_resource_group.<resource group label>.name

  ip_configuration {
    name                          = "<any name>"       # internal
    subnet_id                     = azurerm_subnet.<server subnet label>.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_virtual_machine" "<label>" {          # dc01 (lowercase, same as the network card)
  name                  = "<name in Azure>"            # DC01
  location              = azurerm_resource_group.<resource group label>.location
  resource_group_name   = azurerm_resource_group.<resource group label>.name
  network_interface_ids = [azurerm_network_interface.<network card label>.id]
  vm_size               = "<VM size>"                  # Standard_D2ls_v7 (see "VM size" below)

  delete_os_disk_on_termination = true                 # NOT in the video: destroy also deletes DC01's hard drive

  storage_image_reference {                            # which operating system: Windows Server 2025
    publisher = "<publisher>"                          # MicrosoftWindowsServer
    offer     = "<offer>"                              # WindowsServer
    sku       = "<sku>"                                # 2025-datacenter-g2
    version   = "latest"
  }
  storage_os_disk {                                    # the hard drive
    name              = "<disk name>"                  # Standard_SSD (just a label)
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "<disk type>"                  # Standard_LRS
  }
  os_profile {
    computer_name  = "<computer name>"                 # DC01 (same as the name in Azure)
    admin_username = "<admin username>"                # titanadmin
    admin_password = "${var.<password variable>}"      # ${var.dc_password}: you make this variable in vars.tf next
  }
  os_profile_windows_config {                          # required for a Windows VM
    enable_automatic_upgrades = false
    provision_vm_agent        = true                   # lets Azure run the ad.tf extension on this VM
  }
}

Use these labels: dc01 for both the network card and the VM.

The delete_os_disk_on_termination line isn't in the video. Type it anyway. Without it, terraform destroy deletes DC01 but keeps its hard drive (the Standard_SSD disk). That disk keeps costing money, and it stops Terraform from deleting the resource group: the destroy fails after about 10 minutes.

VM size: I first typed a burstable (B-series) size, Standard_B2s_v2, but my subscription had a quota of 0 for that family in East US 2, so I switch sizes right before the first apply video 28:27. My code and plan around that first apply still show Standard_B2s_v2, because they were recorded before the switch: keep Standard_D2ls_v7. Free and pay-as-you-go subscriptions can't use every size in every region: some sizes have a quota of 0 for you, and some regions run short. If Azure refuses your size, pick one from another family.

The last line (provision_vm_agent = true, video 31:43) matters: it installs the Azure VM agent, and the agent is what runs the ad.tf extension later. Azure only sets it when it creates DC01, so it has to be in vm.tf before the apply that builds DC01. It's in the template.

Typing vm.tf along with the video? Add provision_vm_agent = true at the same time as enable_automatic_upgrades = false video 30:51, not later like I do. On camera my DC01 hadn't been built yet when I added it. If yours already is, Azure won't switch the agent on afterwards (see provisionVMAgent in If something breaks).

Where the values come from: the Terraform docs for azurerm_virtual_machine list every setting a VM can have. For the Windows Server 2025 image values, I searched the provider docs for storage_image_reference and Windows Server 2025.

vars.tf: the password video 23:54

The password never goes in your code. Terraform asks for it every time you run it.

COPY AND PASTEvars.tf
variable "dc_password" {
    type      = string
    sensitive = true
}

Pick the password now and use the same one every time. It's DC01's admin password and its Active Directory recovery password.

  • At least 12 characters, with uppercase, lowercase, a number and a symbol. That's more than Azure asks for (3 of those 4 is enough), and it passes Active Directory's rules too.
  • No quotes and no % sign (' or ", the curly ‘ ’ “ ” a phone or Word makes, or %): ad.tf passes the password through a Windows command line, and those break the command or quietly change the recovery password it sets. Everything else on your keyboard is fine.

A different password later won't change DC01, but it does change ad.tf's command: the plan shows azurerm_virtual_machine_extension.promote will be updated in-place. Don't apply that. It reruns the domain controller setup on a server that's already one, and restarts it. Run the command again with your real password.

terraform init and terraform plan video 25:30

Use the VS Code terminal: if none is open, Terminal → New Terminal. Because you opened the Terraform folder, it starts there, and the prompt ends in \Documents\Terraform>. Run every terraform command, and the Copy-Item in section 5, in this terminal. You stay signed in to Azure when you close VS Code or restart the VM; run az login again only if a command tells you to.

KNOW IT BY HEART
terraform init

It downloads the Azure provider and makes a .terraform folder and a .terraform.lock.hcl file (it records the provider version, so every run uses the same one). Before it downloads anything, it reads your files and stops if one is broken, like a missing } or a <label> you forgot to replace. It doesn't check the settings inside your resources; plan does that.

KNOW IT BY HEART
terraform plan

It asks for var.dc_password; for this first plan you can type anything. Read what it says it will build: a resource group, a virtual network, a subnet, a network card and a virtual machine. Get used to reading plans: it's how you catch mistakes before they cost money.

terraform apply video 28:55

KNOW IT BY HEART
terraform apply

Type your real password, then yes. Terraform builds things in the right order on its own: the network card waits for the subnet, the VM waits for the network card.

If it stops with "The Resource Provider was not registered" (Azure adds that your subscription is not registered to use namespace Microsoft.Network or Microsoft.Compute), you skipped the last step of section 2. Run its two az provider register commands, wait for Registered, then run terraform apply again. Terraform keeps what it already built and carries on.

When it finishes, open the Azure portal: your Titan-Lab-RG resource group is there with everything in it. That's you deploying infrastructure with code.

Your state file (terraform.tfstate, and terraform.tfstate.backup next to it) stays in this folder. It holds your DC password in plain text (sensitive = true only hides it on screen), so never share, upload or commit these files. Companies keep state in locked-down cloud storage; for a home lab, local is fine.

ad.tf: make it a domain controller video 32:44

This is an extension I put together from several sources. You don't need to know how to write it: it runs a PowerShell command on DC01 that installs Active Directory, creates the lab.local domain, and restarts the server.

COPY AND PASTEad.tf
locals {
  promote = "Install-WindowsFeature AD-Domain-Services -IncludeManagementTools; Install-ADDSForest -DomainName lab.local -DomainNetbiosName LAB -InstallDns -SafeModeAdministratorPassword (ConvertTo-SecureString '${var.dc_password}' -AsPlainText -Force) -Force -NoRebootOnCompletion; shutdown /r /t 60"
}

resource "azurerm_virtual_machine_extension" "promote" {
  name                 = "promote-dc"
  virtual_machine_id   = azurerm_virtual_machine.dc01.id
  publisher            = "Microsoft.Compute"
  type                 = "CustomScriptExtension"
  type_handler_version = "1.10"

  protected_settings = jsonencode({
    commandToExecute = "powershell -ExecutionPolicy Bypass -Command \"${local.promote}\""
  })
}

output "dc_ip" {
  value = azurerm_network_interface.dc01.private_ip_address
}

Then video 33:38:

KNOW IT BY HEART
terraform apply

Same password, then yes. When it finishes, it prints dc_ip = "10.0.0.4": your domain controller's address. Give the server about 10 minutes to finish restarting as a domain controller.

5 · The VPN video 34:09

Your VM at home can't reach a private address in Azure. The VPN gateway gives it a tunnel in.

The gateway subnet video 34:59

The gateway needs a subnet of its own.

TEMPLATEadd it at the bottom of group.tf · the finished file is in Appendix A.
resource "azurerm_subnet" "<label>" {                  # vpn
  name                 = "GatewaySubnet"              # it HAS to be called exactly this
  resource_group_name  = azurerm_resource_group.<resource group label>.name
  virtual_network_name = azurerm_virtual_network.<network label>.name
  address_prefixes     = ["<range>"]                  # 10.0.0.32/27: the 32 addresses right after server-sn
}

Use the label vpn: vpn.tf below refers to azurerm_subnet.vpn.

Put the certificate where Terraform can read it video 35:46

Terraform looks for P2SRootCert-base64.txt in the Terraform folder, next to vpn.tf. Copy it there from C:\home-lab (or drag it over in File Explorer):

COPY AND PASTEin the VS Code terminal
Copy-Item C:\home-lab\P2SRootCert-base64.txt .

If you skip this, terraform validate (two steps down) fails with Invalid value for "path" parameter: no file exists at "./P2SRootCert-base64.txt", and so do plan and apply.

vpn.tf: the VPN gateway video 36:16

COPY AND PASTEvpn.tfit works out of the box if you used my labels. If you named your gateway subnet something other than vpn, change azurerm_subnet.vpn.id to match.
resource "azurerm_public_ip" "vpn" {
  name                = "pip-vpngw"
  location            = azurerm_resource_group.labrg.location
  resource_group_name = azurerm_resource_group.labrg.name
  sku                 = "Standard"
  allocation_method   = "Static"
  zones               = ["1", "2", "3"]
}

resource "azurerm_virtual_network_gateway" "vpn" {
  name                = "vpngw-lab"
  location            = azurerm_resource_group.labrg.location
  resource_group_name = azurerm_resource_group.labrg.name
  type                = "Vpn"
  vpn_type            = "RouteBased"
  sku                 = "VpnGw1AZ"
  generation          = "Generation1"
  active_active       = false

  ip_configuration {
    name                          = "vnetGatewayConfig"
    public_ip_address_id          = azurerm_public_ip.vpn.id
    private_ip_address_allocation = "Dynamic"
    subnet_id                     = azurerm_subnet.vpn.id
  }

  vpn_client_configuration {
    address_space        = ["172.16.201.0/24"] # addresses your Win11 VM gets on the VPN
    vpn_client_protocols = ["IkeV2"]           # SSTP can't be enabled anymore
    vpn_auth_types       = ["Certificate"]

    root_certificate {
      name             = "P2SRootCert"
      public_cert_data = trimspace(file("${path.module}/P2SRootCert-base64.txt"))
    }
  }

  timeouts {
    create = "2h"
  }
}

terraform validate video 36:39

KNOW IT BY HEART
terraform validate

"Success! The configuration is valid." means every reference points at something that exists. See it catch a mistake: in vpn.tf, change azurerm_public_ip.vpn.id in the gateway block to azurerm_public_ip.vpn2.id, save, and validate again. It tells you there's no public IP called vpn2. Change it back and save.

Point the network's DNS at your domain controller video 37:07

Your VM at home has to find lab.local, and the domain controller is the DNS server that knows where it is. Add the dc_ip Terraform printed as the network's DNS server.

TEMPLATEone line in the virtual network block of group.tf · the finished file is in Appendix A.
  dns_servers         = ["<dc_ip>"]                   # 10.0.0.4

Plan it and build it video 37:39

KNOW IT BY HEART
terraform plan

Type your real password for this plan too, then read it before you apply. You should see 3 to add (the public IP, the gateway subnet and the gateway), 1 to change (the virtual network getting its DNS server) and 0 to destroy. Go by these numbers, not the plan on my screen: that bit is partly an earlier take, so mine shows 2 to change, my gateway subnet's old name and, in the plan I apply, 1 to destroy. Keep the name GatewaySubnet. If yours says 2 to change and one of them is azurerm_virtual_machine_extension.promote will be updated in-place, you typed a different password: don't apply it, run the plan again with the real one. Lines like (12 unchanged attributes hidden) are settings that stay the same; read past them. Nothing should be destroyed.

KNOW IT BY HEART
terraform apply

The same password as before, then yes. The gateway takes 25 to 45 minutes. Go get something to eat.

First command: download the VPN client video 38:34

COPY AND PASTEin the VS Code terminal
az network vnet-gateway vpn-client generate --resource-group Titan-Lab-RG --name vpngw-lab --processor-architecture Amd64 --output tsv | Set-Clipboard

The end of it, Set-Clipboard, puts a download link in your clipboard. Then:

  1. Open Edge, paste into the address bar, and press Enter. A zip file downloads.
  2. Right-click the zip → Extract All → Extract.
  3. Open the WindowsAmd64 folder and run VpnClientSetupAmd64.
  4. If Windows says it protected your PC: More info → Run anyway. It's your own VPN client in your own VM.
  5. "Do you wish to install a Vpn client for Titan-VNET?" → Yes.
  6. Settings → Network & internet → VPN → Titan-VNET → Connect, then Connect again in the Azure VPN window that opens. When it says Connection Manager needs elevated privilege (to update your routing table), click Continue, then Yes when Windows asks to allow changes. If a Select Certificate box appears, pick P2SChildCert and click OK.

It says Connected. You'll do the same four clicks (Connect, Connect, Continue, Yes) every time you connect.

Second command: turn on Remote Desktop on DC01 video 43:08

This opens Remote Desktop on your domain controller, so you can sign in to it from your VM over the VPN. (Azure's own way in, Bastion, has a free Developer tier, but it only works inside the Azure portal, one VM at a time; the paid tiers start at about 19¢ an hour.) In the video I run it after joining the domain, in section 6; running it now works the same.

COPY AND PASTEin the VS Code terminal
az vm run-command invoke --resource-group Titan-Lab-RG --name DC01 --command-id RunPowerShellScript --scripts "Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0; Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'"

Check the port is open, with the VPN connected video 43:44:

COPY AND PASTE
Test-NetConnection 10.0.0.4 -Port 3389

TcpTestSucceeded : True means Remote Desktop (port 3389) is reachable.

Every time you rebuild the lab with terraform apply, run this command again: it's a brand-new DC01.

6 · Join the domain video 40:39

Join your VM to lab.local

  1. Make sure the VPN is Connected.
  2. In Windows search, type Run and open it (or press Win+R). Type sysdm.cpl and press Enter. (Remember what this window looks like; you can always search how to get back to it.)
  3. Click Change...
  4. Under Member of, choose Domain and type lab.local. Click OK.
  5. User name: LAB\titanadmin (the admin username from vm.tf, with the domain first). Password: your domain controller password.
  6. "Welcome to the lab.local domain." → OK, OK, Close, then Restart Now.

After the restart video 42:31

  1. Sign in with your regular account (titanuser), not the domain one yet. If titanuser isn't on the sign-in screen, click Other user and type .\titanuser: the .\ means this PC's own account, not the LAB domain.
  2. Connect the VPN: Settings → Network & internet → VPN → Titan-VNET → Connect (Connect, Connect, Continue, Yes, as before). The first sign-in with a domain account needs the VPN up, and the VPN lives in this account.
  3. If you didn't run it in section 5, run the Remote Desktop command now (section 5, second command, video 43:08) in the VS Code terminal. Here it is again:
COPY AND PASTE
az vm run-command invoke --resource-group Titan-Lab-RG --name DC01 --command-id RunPowerShellScript --scripts "Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0; Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'"

Then check the port video 43:44:

COPY AND PASTE
Test-NetConnection 10.0.0.4 -Port 3389

Sign in with the domain account video 44:11

  1. Lock the VM's screen: in the VM, click Start, then your account picture or the power button, and choose Lock. (Not Win+L: your real PC takes that key and locks itself instead.) Click the lock screen, then Other user at the bottom left. It says Sign in to: LAB. Type titanadmin and your domain controller password.
  2. Windows sets up the new account. Check it: Settings → Accounts shows LAB\titanadmin. Your home VM is on the domain.

Remote Desktop into the domain controller video 45:16

  1. Switch back to titanuser: lock the VM's screen (Start → account picture or power → Lock) and pick titanuser at the bottom left. The VPN connection belongs to that account, so titanadmin can't use it. Connect the VPN if it isn't connected.
  2. Open Remote Desktop Connection (search for it, or run mstsc).
  3. Computer: 10.0.0.4 (your dc_ip). Click Show Options, and for User name type LAB\titanadmin.
  4. Connect, enter your password, and click Yes on the certificate warning.

You're on DC01: Windows Server 2025, running in Azure.

Active Directory Users and Computers video 46:12

  1. On DC01, open Start and type Active Directory. Several tools show up; open Active Directory Users and Computers. It's about 70% of what a system administrator does in Active Directory; the others are admin tools too, for sites and replication, trusts between domains, and Active Directory in PowerShell.
  2. Expand lab.local → Computers: TITAN-LAB, your VM at home, is there.
  3. Click Users, then right-click → New → User video 47:04:
    • First name: t, Last name: user (any name works), User logon name: t-user. Click Next.
    • Type a password with uppercase and lowercase letters, a number and a symbol (the domain won't take a simple one). Untick "User must change password at next logon" (it's a test), then Next and Finish.
  4. Minimize Remote Desktop. On your VM, lock the screen (Start → account picture or power → Lock) → Other user → t-user and that password video 48:04. It signs in.

You created a user on a domain controller in Azure and signed in with it on a computer at home. That's a hybrid cloud, and it's the work system administrators and cloud engineers do every day.

7 · Destroy it video 49:02

Keep it up for a few days of practice if you like (about $10 a day), but when you're done, tear it all down so the cost stops.

  1. Switch to titanuser (Start → account picture or power → Lock, then pick titanuser), close Remote Desktop and disconnect the VPN.
  2. In the VS Code terminal, in the Terraform folder:
KNOW IT BY HEART
terraform destroy

Your password, then yes. It removes all 9 resources it built, and DC01's hard drive goes with DC01.

Built DC01 without the delete_os_disk_on_termination line? (For example, you typed vm.tf along with the video.) Then the destroy deletes everything else, waits on the resource group for about 10 minutes, and stops with the Resource Group still contains Resources: DC01's hard drive is still in it, and it bills about $6 a month until you delete it. Delete it, then destroy again:

COPY AND PASTE
az disk delete --resource-group Titan-Lab-RG --name Standard_SSD --yes
KNOW IT BY HEART
terraform destroy

This time it says 1 to destroy and finishes. Add the line to vm.tf (section 4) before you build again.

Bringing it back

terraform apply builds the whole thing again from your finished files (the gateway takes its 25 to 45 minutes again). Everything in Azure is brand new, so afterwards you need all three of these, not just the Remote Desktop command:

  1. Turn Remote Desktop back on: run the second command in section 5. It's a different DC01.
  2. Get the new VPN client: run the first command in section 5 and install it. The new gateway has a new address, so the old connection can't reach it. If the installer doesn't finish, or Titan-VNET is missing or won't connect afterwards, open %AppData%\Microsoft\Network\Connections\Cm in File Explorer, delete the folders in it, and run VpnClientSetupAmd64 again.
  3. Leave the old domain, then join the new one. The new lab.local is a brand-new domain that has never seen your VM, and the old domain controller is gone, so take the VM off the old domain first (it works with the VPN connected or not). Sign in as titanuser, open Windows PowerShell as administrator (Start, type PowerShell, right-click → Run as administrator → Yes), and paste:
COPY AND PASTE
$pc = Get-CimInstance Win32_ComputerSystem
Invoke-CimMethod -InputObject $pc -MethodName UnjoinDomainOrWorkgroup -Arguments @{ FUnjoinOptions = [uint32]0 }
Invoke-CimMethod -InputObject $pc -MethodName JoinDomainOrWorkgroup -Arguments @{ Name = 'WORKGROUP'; FJoinOptions = [uint32]0 }

Under ReturnValue you should see 0 twice. (2692 on the first one means the VM had already left the domain; that's fine. Any other number: open PowerShell again with Run as administrator and paste again.) Then restart with Restart-Computer -Force (-Force because titanadmin or t-user may still be signed in), sign in as titanuser (or .\titanuser under Other user), connect the VPN, and join lab.local exactly as in section 6.

Your certificates (section 3) and your code stay the same.

If something breaks

What you seeFix
terraform or az "is not recognized"Close VS Code and open it again after the installs.
terraform init says Terraform initialized in an empty directory, or plan says No changes without asking for the passwordYour files aren't saved. File → Save All, then run it again.
Authentication failed on az loginRun az login --tenant <YOUR_TENANT_ID> with the ID from the error.
The Resource Provider was not registered, or not registered to use namespace 'Microsoft.Network' (or 'Microsoft.Compute')Run the two az provider register ... --wait commands from section 2, check both say Registered, then terraform apply again.
Plan errors about secure_boot_enabled, vtpm_enabled or a missing create_optionThat code came from the docs for azurerm_windows_virtual_machine, a different resource. This guide uses azurerm_virtual_machine: it has no secure_boot_enabled or vtpm_enabled, and its storage_os_disk block needs create_option = "FromImage". Check your vm.tf against Appendix B.
Apply error asking for os_profile_windows_configA Windows VM needs that block. It's in the template. Add provision_vm_agent = true in it now too, before DC01 gets built.
An apply stops on DC01 with Changing property 'windowsConfiguration.provisionVMAgent' is not allowedDC01 was built before provision_vm_agent = true was in vm.tf, and Azure only sets that when it creates a VM. Delete DC01 and its hard drive, then build it again: az vm delete --resource-group Titan-Lab-RG --name DC01 --yes, then az disk delete --resource-group Titan-Lab-RG --name Standard_SSD --yes, then terraform apply.
Quota error ("exceeding approved ... Cores quota", "Current Limit: 0")Your subscription can't use that VM size family in that region. Use Standard_D2ls_v7 or another family.
no file exists at "./P2SRootCert-base64.txt" (from validate, plan or apply)Copy the file from C:\home-lab into the Terraform folder (section 5).
terraform validate says a resource isn't declaredYour labels don't match. ad.tf and vpn.tf expect labrg, vpn (the gateway subnet) and dc01; the finished files in Appendix A and B also use vnet and server.
terraform apply stops while creating DC01 with a password errorAzure checks the password when it creates DC01, so DC01 wasn't made. Run terraform apply again with a password that meets the rules (section 4, vars.tf).
The domain extension (promote-dc) failsUsually a quote or a % in the password. DC01 already has that password and a new one won't change it, so start clean: terraform destroy, then terraform apply with a password without them (section 4, vars.tf).
The plan shows azurerm_virtual_machine_extension.promote will be updated in-placeYou typed a different password. Don't apply it: run the command again with your real password.
Error 798: A certificate could not be found that can be used with this Extensible Authentication ProtocolThe child certificate isn't in this Windows user's store. Sign in as the user who clicks Connect, run section 3 again and check with Get-ChildItem Cert:\CurrentUser\My. That makes a new root certificate, and your gateway only trusts the old one: copy the new P2SRootCert-base64.txt into the Terraform folder again (section 5, Copy-Item) and run terraform apply with your same password. It shows the gateway will be updated in-place (0 to add, 1 to change); type yes, let it finish, then connect.
A Select Certificate box when you connectNormal. Pick P2SChildCert, then OK.
Joining says it can't find lab.localConnect the VPN first. If you changed the network's DNS server after you downloaded the VPN client, download and install the client again (section 5, first command). Give DC01 10 minutes after the ad.tf apply to finish becoming a domain controller.
Test-NetConnection ... -Port 3389 says FalseConnect the VPN, then run the Remote Desktop command again (section 5, second command).
The domain sign-in says no logon servers are availableSign in as titanuser, connect the VPN, then switch user.
Signing in as titanuser says the user name or password is incorrect, or that the domain isn't availableClick Other user and type .\titanuser. Without the .\, Windows looks for titanuser in the LAB domain.
Creating t-user says the password doesn't meet the requirementsUse uppercase and lowercase letters, a number and a symbol, and leave the user's name out of it.
terraform destroy waits on the resource group for about 10 minutes, then says the Resource Group still contains Resources and lists .../disks/Standard_SSDDC01's hard drive was left behind: vm.tf didn't have delete_os_disk_on_termination = true when DC01 was built. Run az disk delete --resource-group Titan-Lab-RG --name Standard_SSD --yes, then terraform destroy again (section 7).
Apply error on DC01: Disk Standard_SSD already exists in resource group ... Only CreateOption.Attach is supportedThe hard drive from your last DC01 is still there. Add delete_os_disk_on_termination = true to vm.tf, run az disk delete --resource-group Titan-Lab-RG --name Standard_SSD --yes, then terraform apply again (it adds DC01 and its domain extension). Then follow "Bringing it back" in section 7.

More free stuff

  • Azure cheat sheet: the Azure services and the knowledge you need to be an Azure administrator, on one PDF. titancloud.education/azure-sheet
  • Don't want the Terraform part? My guide to building your first virtual machine and fixing simple network and Windows problems: titancloud.education/vm-guide
  • Stuck? Leave a comment on the video. I read every one.

Appendix A · group.tf (the finished file)

COPY AND PASTEgroup.tfthe final version, with the gateway subnet and the DNS server from section 5.
# Create a resource group
resource "azurerm_resource_group" "labrg" {
  name     = "Titan-Lab-RG"
  location = "eastus2"
}

# Create a virtual network within the resource group
resource "azurerm_virtual_network" "vnet" {
  name                = "Titan-VNET"
  resource_group_name = azurerm_resource_group.labrg.name
  location            = azurerm_resource_group.labrg.location
  address_space       = ["10.0.0.0/24"]
  dns_servers         = ["10.0.0.4"]
}

resource "azurerm_subnet" "server" {
  name                 = "server-sn"
  resource_group_name  = azurerm_resource_group.labrg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  address_prefixes     = ["10.0.0.0/27"]
}

resource "azurerm_subnet" "vpn" {
  name                 = "GatewaySubnet"
  resource_group_name  = azurerm_resource_group.labrg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  address_prefixes     = ["10.0.0.32/27"]
}

If you build it all in one go from this file, 10.0.0.4 is right: DC01 is the first machine in server-sn, and Azure keeps five addresses in every subnet for itself (the first four and the last), so the first machine gets .4.

Appendix B · vm.tf (the finished file)

COPY AND PASTEvm.tfwith the delete_os_disk_on_termination line from section 4 that isn't in the video.
resource "azurerm_network_interface" "dc01" {
  name                = "nic-dc01"
  location            = azurerm_resource_group.labrg.location
  resource_group_name = azurerm_resource_group.labrg.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.server.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_virtual_machine" "dc01" {
  name                  = "DC01"
  location              = azurerm_resource_group.labrg.location
  resource_group_name   = azurerm_resource_group.labrg.name
  network_interface_ids = [azurerm_network_interface.dc01.id]
  vm_size               = "Standard_D2ls_v7"

  delete_os_disk_on_termination = true

  storage_image_reference {
    publisher = "MicrosoftWindowsServer"
    offer     = "WindowsServer"
    sku       = "2025-datacenter-g2"
    version   = "latest"
  }
  storage_os_disk {
    name              = "Standard_SSD"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  os_profile {
    computer_name  = "DC01"
    admin_username = "titanadmin"
    admin_password = "${var.dc_password}"
  }
  os_profile_windows_config {
    enable_automatic_upgrades = false
    provision_vm_agent        = true
  }
}

A gift for those who made it to the end: your resume line video 48:31

If you did every step in this lab, you've earned this line. Put it on your resume:

Built a hybrid Active Directory lab: Terraform deployed a Windows Server 2025 domain controller and a VPN gateway in Azure, and joined an on-prem Windows 11 machine to the domain over point-to-site VPN.

We're not just learning cloud technology. We're building more Titans in tech.

Titan Cloud Education · titancloud.education · Azure list prices checked November 2026.