# Azurerm provider configuration | |
provider "azurerm" { | |
features {} | |
} | |
data "azurerm_log_analytics_workspace" "example" { | |
name = "loganalytics-we-sharedtest2" | |
resource_group_name = "rg-shared-westeurope-01" | |
} | |
module "virtual-machine" { | |
source = "kumarvna/virtual-machine/azurerm" | |
version = "2.3.0" | |
# Resource Group, location, VNet and Subnet details | |
resource_group_name = "rg-shared-westeurope-01" | |
location = "westeurope" | |
virtual_network_name = "vnet-shared-hub-westeurope-001" | |
subnet_name = "snet-management" | |
virtual_machine_name = "win-machine" | |
# This module support multiple Pre-Defined Linux and Windows Distributions. | |
# Check the README.md file for more pre-defined images for WindowsServer, MSSQLServer. | |
# Please make sure to use gen2 images supported VM sizes if you use gen2 distributions | |
# This module creates a random admin password if `admin_password` is not specified | |
# Specify a valid password with `admin_password` argument to use your own password | |
os_flavor = "windows" | |
windows_distribution_name = "windows2019dc" | |
virtual_machine_size = "Standard_A2_v2" | |
admin_username = "azureadmin" | |
admin_password = "P@$$w0rd1234!" | |
instances_count = 2 | |
# Proxymity placement group, Availability Set and adding Public IP to VM's are optional. | |
# remove these argument from module if you dont want to use it. | |
enable_proximity_placement_group = true | |
enable_vm_availability_set = true | |
enable_public_ip_address = true | |
# Network Seurity group port allow definitions for each Virtual Machine | |
# NSG association to be added automatically for all network interfaces. | |
# Remove this NSG rules block, if `existing_network_security_group_id` is specified | |
nsg_inbound_rules = [ | |
{ | |
name = "rdp" | |
destination_port_range = "3389" | |
source_address_prefix = "*" | |
}, | |
{ | |
name = "http" | |
destination_port_range = "80" | |
source_address_prefix = "*" | |
}, | |
] | |
# Boot diagnostics to troubleshoot virtual machines, by default uses managed | |
# To use custom storage account, specify `storage_account_name` with a valid name | |
# Passing a `null` value will utilize a Managed Storage Account to store Boot Diagnostics | |
enable_boot_diagnostics = true | |
# Attach a managed data disk to a Windows/Linux VM's. Possible Storage account type are: | |
# `Standard_LRS`, `StandardSSD_ZRS`, `Premium_LRS`, `Premium_ZRS`, `StandardSSD_LRS` | |
# or `UltraSSD_LRS` (UltraSSD_LRS only available in a region that support availability zones) | |
# Initialize a new data disk - you need to connect to the VM and run diskmanagemnet or fdisk | |
data_disks = [ | |
{ | |
name = "disk1" | |
disk_size_gb = 100 | |
storage_account_type = "StandardSSD_LRS" | |
}, | |
{ | |
name = "disk2" | |
disk_size_gb = 200 | |
storage_account_type = "Standard_LRS" | |
} | |
] | |
# (Optional) To enable Azure Monitoring and install log analytics agents | |
# (Optional) Specify `storage_account_name` to save monitoring logs to storage. | |
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.example.id | |
# Deploy log analytics agents to virtual machine. | |
# Log analytics workspace customer id and primary shared key required. | |
deploy_log_analytics_agent = true | |
log_analytics_customer_id = data.azurerm_log_analytics_workspace.example.workspace_id | |
log_analytics_workspace_primary_shared_key = data.azurerm_log_analytics_workspace.example.primary_shared_key | |
# Adding additional TAG's to your Azure resources | |
tags = { | |
ProjectName = "demo-project" | |
Env = "dev" | |
Owner = "user@example.com" | |
BusinessUnit = "CORP" | |
ServiceClass = "Gold" | |
} | |
} |
To run this example you need to execute following Terraform commands
terraform init
terraform plan
terraform apply
Run terraform destroy
when you don’t need these resources.
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND