Terraform
Terraform
provider "azurerm" {
features {}
}
# Define variables
variable "location" {
description = "Azure region where the resources will be created"
default = "eastus" # Change this to your preferred region
}
variable "resource_group_name" {
description = "Name of the Azure resource group"
default = "my-resource-group" # Change this to your preferred name
}
variable "vm_name" {
description = "Name of the virtual machine"
default = "my-vm" # Change this to your preferred name
}
variable "admin_username" {
description = "Admin username for the virtual machine"
default = "adminuser" # Change this to your preferred username
}
variable "admin_password" {
description = "Admin password for the virtual machine"
default = "Password12345!" # Change this to your preferred password
}
vm_size = "Standard_DS1_v2"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
storage_os_disk {
name = "${var.vm_name}-osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = var.vm_name
admin_username = var.admin_username
admin_password = var.admin_password
}
os_profile_windows_config {
provision_vm_agent = true
}
tags = {
environment = "dev"
}
}
ip_configuration {
name = "my-nic-ipconfig"
subnet_id = azurerm_subnet.my_subnet.id
private_ip_address_allocation = "Dynamic"
}
}
tags = {
environment = "dev"
}
}
# Create a subnet
resource "azurerm_subnet" "my_subnet" {
name = "my-subnet"
resource_group_name = azurerm_resource_group.my_resource_group.name
virtual_network_name = azurerm_virtual_network.my_vnet.name
address_prefixes = ["10.0.1.0/24"]
}