Azure Virtual Machine Terraform module — parameterised, azurerm 4.x, CI-validated.
Enterprise-grade Azure Virtual Machine module with comprehensive security, monitoring, and compliance features.
✅ Full Linux and Windows Support - Complete support for both operating systems
✅ Advanced Security - Encryption at host, Secure Boot, vTPM, Azure Disk Encryption
✅ Managed Identity - System-assigned and user-assigned managed identities
✅ Comprehensive Monitoring - Azure Monitor Agent, Dependency Agent, Network Watcher
✅ Data Disk Management - Multiple data disks with encryption and custom caching
✅ High Availability - Availability Zones and Availability Sets support
✅ Azure Policy Integration - Built-in policy assignments for compliance
✅ Naming Conventions - Microsoft CAF compliant naming patterns
✅ Boot Diagnostics - Enhanced troubleshooting capabilities
✅ Patch Management - Automated patch orchestration
✅ Network Security - Accelerated networking, NSG integration
Pin the module to a release tag:
module "virtual_machine" {
source = "git::https://github.com/AIRCLOUD-PL/azure-virtual-machine-module.git?ref=v1.0.0"
# required inputs
admin_username = "..."
environment = "..."
location = "..."
os_type = "..."
resource_group_name = "..."
subnet_id = "..."
vm_size = "..."
}All inputs and outputs are listed in the generated reference below (Inputs, Outputs). Worked examples live in examples/.
module "virtual_machine" {
source = "git::https://github.com/AIRCLOUD-PL/azure-virtual-machine-module.git?ref=v1.0.0"
name = "vm-prod-westeu-001"
location = "westeurope"
resource_group_name = "rg-production"
environment = "prod"
vm_size = "Standard_D2s_v3"
os_type = "Linux"
admin_username = "azureuser"
subnet_id = azurerm_subnet.main.id
# SSH Key Authentication
disable_password_authentication = true
admin_ssh_public_key = file("~/.ssh/id_rsa.pub")
# Managed Identity
identity_type = "SystemAssigned"
tags = {
Environment = "Production"
}
}module "virtual_machine" {
source = "git::https://github.com/AIRCLOUD-PL/azure-virtual-machine-module.git?ref=v1.0.0"
# Naming
name = "vm-prod-westeu-001"
location = "westeurope"
resource_group_name = "rg-production"
environment = "prod"
# VM Configuration
vm_size = "Standard_D4s_v3"
os_type = "Linux"
admin_username = "azureuser"
# Network
subnet_id = azurerm_subnet.main.id
enable_accelerated_networking = true
private_ip_address_allocation = "Static"
private_ip_address = "10.0.1.10"
# High Availability
availability_zone = "1"
# Image
source_image_reference = {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts-gen2"
version = "latest"
}
# Authentication
disable_password_authentication = true
admin_ssh_public_key = var.ssh_public_key
# Storage
os_disk_storage_account_type = "Premium_LRS"
os_disk_size_gb = 128
data_disks = [
{
lun = 0
disk_size_gb = 512
storage_account_type = "Premium_LRS"
caching = "ReadWrite"
create_option = "Empty"
}
]
# Security
encryption_at_host_enabled = true
secure_boot_enabled = true
vtpm_enabled = true
# Identity
identity_type = "SystemAssigned"
# Monitoring
enable_monitoring = true
log_analytics_workspace_id = azurerm_log_analytics_workspace.main.workspace_id
log_analytics_workspace_key = azurerm_log_analytics_workspace.main.primary_shared_key
enable_dependency_agent = true
enable_network_watcher = true
# Policies
enable_policy_assignments = true
# Patch Management
patch_mode = "AutomaticByPlatform"
patch_assessment_mode = "AutomaticByPlatform"
tags = {
Environment = "Production"
CostCenter = "IT"
Compliance = "PCI-DSS"
}
}- Basic - Minimal configuration
- Complete - Full enterprise features
- Windows - Windows Server VM
- High Availability - Multi-zone deployment
- Encryption at Host - Hardware-based encryption
- Azure Disk Encryption - BitLocker/dm-crypt encryption
- Customer-Managed Keys - Disk Encryption Set support
- TLS/HTTPS - Encrypted communications
- Managed Identity - Azure AD integrated identity
- SSH Key Authentication - No password authentication for Linux
- Just-In-Time Access - Azure Security Center JIT
- RBAC Integration - Role-based access control
- Azure Monitor - Metrics, logs, and alerts
- Network Watcher - Network diagnostics
- Boot Diagnostics - Serial console and screenshots
- Azure Policy - Compliance enforcement
- Microsoft Defender - Threat protection
- NSG Integration - Network security groups
- Application Security Groups - Micro-segmentation
- Azure Firewall - Stateful firewall
- Private Endpoints - Private connectivity
The module follows Microsoft Cloud Adoption Framework naming conventions:
{workload}-{environment}-{region}-{resource-type}-{instance}
Example: web-prod-westeu-vm-001
See naming.tf for region and environment abbreviations.
cd test
go test -v -timeout 30mgo test -v -run TestVirtualMachineModuleBasicgo test -v -coverprofile=coverage.out
go tool cover -html=coverage.out- Fork the repository
- Create a feature branch
- Make your changes
- Add/update tests
- Run tests locally
- Submit a pull request
MIT
Platform Engineering Team
For issues and questions:
- Create an issue in the repository
- Contact: platform-team@company.com
See CHANGELOG.md for version history.
| Name | Version |
|---|---|
| terraform | >= 1.5.0 |
| azurerm | ~> 4.0 |
| Name | Version |
|---|---|
| azurerm | 4.81.0 |
No modules.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| admin_password | Administrator password for the VM (required for Windows, optional for Linux) | string |
null |
no |
| admin_ssh_public_key | SSH public key for Linux VMs when password authentication is disabled | string |
null |
no |
| admin_username | Administrator username for the VM | string |
n/a | yes |
| antimalware_exclusions | Antimalware exclusions configuration | object({ |
{ |
no |
| application_security_group_id | ID of Application Security Group to associate with NIC | string |
null |
no |
| approved_vm_extensions | List of approved VM extension types | list(string) |
[ |
no |
| availability_set_id | ID of the availability set | string |
null |
no |
| availability_zone | Availability zone number (1, 2, or 3) | string |
null |
no |
| boot_diagnostics_storage_account_uri | Storage account URI for boot diagnostics (leave null for managed storage) | string |
null |
no |
| bypass_platform_safety_checks_on_user_schedule_enabled | Bypass platform safety checks on user schedule | bool |
false |
no |
| custom_data | Custom data to pass to the VM (cloud-init for Linux, will be base64 encoded) | string |
null |
no |
| custom_script_extension | Custom script extension configuration | object({ |
null |
no |
| data_disks | List of data disks to attach to the VM | list(object({ |
[] |
no |
| disable_password_authentication | Disable password authentication for Linux VMs (SSH key only) | bool |
true |
no |
| disk_encryption_set_id | ID of Disk Encryption Set for disk encryption with customer-managed keys | string |
null |
no |
| dns_servers | List of DNS servers for the network interface | list(string) |
[] |
no |
| enable_accelerated_networking | Enable accelerated networking (requires supported VM size) | bool |
false |
no |
| enable_antimalware | Enable Microsoft Antimalware extension (Windows only) | bool |
true |
no |
| enable_automatic_updates | Enable automatic updates for Windows VM | bool |
true |
no |
| enable_azure_disk_encryption | Enable Azure Disk Encryption extension | bool |
false |
no |
| enable_backup_policy | Enable backup policy requirement | bool |
true |
no |
| enable_boot_diagnostics | Enable boot diagnostics | bool |
true |
no |
| enable_dependency_agent | Enable Dependency Agent for VM Insights | bool |
false |
no |
| enable_ip_forwarding | Enable IP forwarding on the network interface | bool |
false |
no |
| enable_monitoring | Enable Azure Monitor Agent | bool |
true |
no |
| enable_network_watcher | Enable Network Watcher Agent | bool |
true |
no |
| enable_policy_assignments | Enable Azure Policy assignments for this VM | bool |
true |
no |
| encryption_at_host_enabled | Enable encryption at host (requires VM size support) | bool |
false |
no |
| environment | Environment name (e.g., prod, dev, test) | string |
n/a | yes |
| hotpatching_enabled | Enable hotpatching for Windows VM | bool |
false |
no |
| identity_ids | List of User Assigned Identity IDs | list(string) |
[] |
no |
| identity_type | Type of Managed Identity: SystemAssigned, UserAssigned, or 'SystemAssigned, UserAssigned' | string |
"SystemAssigned" |
no |
| instance_number | Instance number for the VM (used in auto-generated names) | string |
"001" |
no |
| key_encryption_key_url | Key Encryption Key URL in Key Vault | string |
null |
no |
| key_vault_id | Key Vault resource ID for disk encryption | string |
null |
no |
| key_vault_url | Key Vault URL for disk encryption | string |
null |
no |
| license_type | License type for Azure Hybrid Benefit: Windows_Client, Windows_Server, RHEL_BYOS, SLES_BYOS | string |
null |
no |
| location | Azure region where resources will be created | string |
n/a | yes |
| log_analytics_workspace_id | Log Analytics Workspace ID for monitoring | string |
null |
no |
| log_analytics_workspace_key | Log Analytics Workspace Key | string |
null |
no |
| name | Name of the virtual machine. If null, will be auto-generated based on naming convention. | string |
null |
no |
| naming_prefix | Prefix for resource naming when auto-generating names | string |
"vm" |
no |
| network_interface_name | Name of the network interface. If null, will be auto-generated. | string |
null |
no |
| os_disk_caching | OS disk caching type: None, ReadOnly, or ReadWrite | string |
"ReadWrite" |
no |
| os_disk_diff_disk_settings | Ephemeral OS disk settings | object({ |
null |
no |
| os_disk_name | Name of the OS disk. If null, will be auto-generated. | string |
null |
no |
| os_disk_size_gb | Size of the OS disk in GB (optional, defaults to image size) | number |
null |
no |
| os_disk_storage_account_type | OS disk storage account type: Standard_LRS, Premium_LRS, StandardSSD_LRS, UltraSSD_LRS | string |
"Premium_LRS" |
no |
| os_type | Operating system type: Linux or Windows | string |
n/a | yes |
| patch_assessment_mode | Patch assessment mode: AutomaticByPlatform or ImageDefault | string |
"AutomaticByPlatform" |
no |
| patch_mode | Patch mode: AutomaticByPlatform, AutomaticByOS, Manual, ImageDefault | string |
"AutomaticByPlatform" |
no |
| plan | Plan information for marketplace images | object({ |
null |
no |
| private_ip_address | Static private IP address (required if allocation is Static) | string |
null |
no |
| private_ip_address_allocation | Private IP address allocation method: Dynamic or Static | string |
"Dynamic" |
no |
| public_ip_address_id | ID of public IP address to associate with VM (optional) | string |
null |
no |
| resource_group_name | Name of the resource group | string |
n/a | yes |
| secure_boot_enabled | Enable secure boot (requires trusted launch VM) | bool |
false |
no |
| source_image_id | ID of custom image (overrides source_image_reference) | string |
null |
no |
| source_image_reference | Source image reference for the VM | object({ |
{ |
no |
| subnet_id | ID of the subnet where VM will be deployed | string |
n/a | yes |
| tags | Tags to apply to all resources | map(string) |
{} |
no |
| timezone | Timezone for Windows VM | string |
null |
no |
| ultra_ssd_enabled | Enable Ultra SSD support | bool |
false |
no |
| user_data | User data to pass to the VM (will be base64 encoded) | string |
null |
no |
| vm_size | Size of the Virtual Machine (e.g., Standard_D2s_v3) | string |
n/a | yes |
| vtpm_enabled | Enable vTPM (requires trusted launch VM) | bool |
false |
no |
| Name | Description |
|---|---|
| admin_username | Administrator username |
| data_disk_ids | IDs of attached data disks |
| identity | Managed identity block |
| identity_principal_id | Principal ID of the system-assigned managed identity |
| naming_convention_example | Naming convention example |
| naming_convention_pattern | Naming convention pattern used |
| network_interface_id | ID of the network interface |
| os_disk_id | ID of the OS disk |
| private_ip_address | Private IP address of the VM |
| public_ip_address | Public IP address of the VM (if assigned) |
| vm_id | ID of the virtual machine |
| vm_name | Name of the virtual machine |
Browse all modules with usage snippets in the module catalog or on github.com/AIRCLOUD-PL. Built and maintained by AIRCLOUD: DevOps, cloud and AI engineering. Need a hand with Azure landing zones or platform engineering? See aircloud.com.pl/consulting.
