You have an existing AVD deployment using this Terraform accelerator.
The new modules need variable definitions. Add them to your variables.tf:
# Navigate to your project directory
cd /Users/travis/Developer/projects/avd-accelator-avm
# Append new variables
cat variables_new_modules.tf >> variables.tf
# Verify
tail -20 variables.tf
What this does: Adds 19 new optional variables for backup, image gallery, and policy modules.
Best for new deployments or dev/test environments.
# Use the all-features example
cp terraform-all-features.tfvars.example terraform.tfvars
# Edit with your values
code terraform.tfvars # Or use nano, vim, etc.
# Initialize and deploy
terraform init
terraform plan
terraform apply
Best for existing production deployments.
# Edit your existing terraform.tfvars
code terraform.tfvars
Add just one feature at a time:
Week 1 - Add Backup:
# Add to your terraform.tfvars
enable_backup = true
backup_frequency = "Daily"
backup_time = "02:00"
backup_timezone = "UTC"
backup_daily_retention_count = 30
backup_weekly_retention_count = 12
backup_monthly_retention_count = 12
backup_yearly_retention_count = 5
terraform plan # Review: Should show Recovery Vault + Backup Policy
terraform apply
Week 2 - Add Image Gallery:
# Add to your terraform.tfvars
enable_image_gallery = true
create_win11_image_definition = true
create_win10_image_definition = false
terraform plan # Review: Should show Shared Image Gallery
terraform apply
Week 3 - Add Policies:
# Add to your terraform.tfvars
enable_policies = true
policy_require_environment_tag = true
policy_allowed_vm_sizes = ["Standard_D2s_v5", "Standard_D4s_v5", "Standard_D8s_v5"]
policy_deploy_antimalware = true
policy_audit_disk_encryption = true
policy_enable_vm_diagnostics = true
terraform plan # Review: Should show 6 policy assignments
terraform apply
# Check Recovery Services Vault
az backup vault list --resource-group <your-rg-name> --output table
# Check backup jobs
az backup job list --resource-group <your-rg-name> --vault-name <vault-name> --output table
# Check protected items
az backup item list --resource-group <your-rg-name> --vault-name <vault-name> --output table
Azure Portal:
# Check Shared Image Gallery
az sig list --resource-group <your-rg-name> --output table
# Check image definitions
az sig image-definition list --resource-group <your-rg-name> --gallery-name <gallery-name> --output table
Azure Portal:
# Check policy assignments
az policy assignment list --resource-group <your-rg-name> --output table
# Check compliance state
az policy state summarize --resource-group <your-rg-name>
Azure Portal:
If you need to disable a feature:
# In terraform.tfvars
enable_backup = false
terraform plan # Review: Will destroy Recovery Vault
terraform apply
⚠️ WARNING: This will delete all backup data. Ensure you don’t need recovery points!
# In terraform.tfvars
enable_image_gallery = false
terraform plan # Review: Will destroy Image Gallery
terraform apply
⚠️ WARNING: This will delete image definitions. Any built images will be lost!
# In terraform.tfvars
enable_policies = false
terraform plan # Review: Will remove policy assignments
terraform apply
✅ SAFE: Policy removal doesn’t affect existing resources.
Solution: You need to add the new variables to variables.tf:
cat variables_new_modules.tf >> variables.tf
Check:
enable_backup = true (or other feature) in terraform.tfvars?terraform init after adding new modules?Solution:
terraform init
terraform plan -var-file=terraform.tfvars
Solution: Your Terraform service principal needs these permissions:
# Add Policy Contributor role
az role assignment create \
--assignee <service-principal-id> \
--role "Resource Policy Contributor" \
--scope "/subscriptions/<subscription-id>"
Common causes:
Microsoft.RecoveryServices provider registeredSolution:
# Register provider
az provider register --namespace Microsoft.RecoveryServices
# Check registration
az provider show --namespace Microsoft.RecoveryServices --query "registrationState"
az backup protection backup-now \
--resource-group <rg-name> \
--vault-name <vault-name> \
--container-name <vm-container-name> \
--item-name <vm-name> \
--backup-management-type AzureIaaSVM \
--retain-until 30-12-2025
# Option 1: Use Azure Image Builder (recommended)
# See: https://learn.microsoft.com/azure/virtual-machines/image-builder-overview
# Option 2: Manually create from existing VM
az vm deallocate --resource-group <rg> --name <source-vm>
az vm generalize --resource-group <rg> --name <source-vm>
az sig image-version create \
--resource-group <rg> \
--gallery-name <gallery-name> \
--gallery-image-definition <image-def-name> \
--gallery-image-version 1.0.0 \
--managed-image /subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.Compute/virtualMachines/<source-vm>
modules/compute/variables.tf to support custom imagesaz policy state summarize --resource-group <rg-name>
After enabling new features, monitor:
Enable cost tracking for new features:
# View costs by resource type
az consumption usage list \
--start-date 2025-10-01 \
--end-date 2025-10-07 \
--query "[?contains(instanceName, 'backup') || contains(instanceName, 'gallery')]" \
--output table
Expected costs (US East):
RECOMMENDATIONS.mdNEW-FEATURES.mdEXAMPLE-ALL-FEATURES.mdSUMMARY.mdQuestions? Check the module source code in modules/*/ or review the comprehensive examples.