0% found this document useful (0 votes)
30 views5 pages

Terraform Configuration File For Windows VM

Uploaded by

mayukh.bzs.uem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Terraform Configuration File For Windows VM

Uploaded by

mayukh.bzs.uem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Terraform Configuration file for Windows VM

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.90.0"
}
}
}

provider "azurerm" {
subscription_id = "69058312-04c0-48e3-b420-92b39991c676"
client_id = "feb487ba-b1f0-4031-a9a4-081aab9f9c19"
client_secret =
"Vvp8Q~STJWkkBvIehOf~3ji7Q07qr22tJPtR.bsf"
tenant_id = "290d1691-f0d9-4ad9-932a-fdbeb0493b55"
features {}
}

# define locals

locals {
resource_group="vm-resource"
location="Central US"
}

# create resource group

resource "azurerm_resource_group" "vm_resource" {


name = local.resource_group
location = local.location
}
# create virtual network

resource "azurerm_virtual_network" "vm_vnet" {


name = "vm-vnet"
location = local.location
resource_group_name = local.resource_group
address_space = ["10.0.0.0/16"]
depends_on = [ azurerm_resource_group.vm_resource
]

# create subnet

resource "azurerm_subnet" "subnetA" {


name = "subnetA"
resource_group_name = local.resource_group
virtual_network_name =
azurerm_virtual_network.vm_vnet.name
address_prefixes = ["10.0.1.0/24"]
depends_on = [
azurerm_virtual_network.vm_vnet

# create network interface card

resource "azurerm_network_interface" "vm_nic" {


name = "vmnic"
location = local.location
resource_group_name = local.resource_group
ip_configuration {
name = "internal"
subnet_id =
azurerm_subnet.subnetA.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id =
azurerm_public_ip.terraform_public.id

depends_on = [
azurerm_virtual_network.vm_vnet,
azurerm_public_ip.terraform_public,
azurerm_subnet.subnetA

# create windows virtual machine

resource "azurerm_windows_virtual_machine" "auto_vm" {


name = "auto-vm"
resource_group_name = local.resource_group
location = local.location
size = "Standard_D2s_v3"
admin_username = "aita"
admin_password = "Azure@123456"
availability_set_id = azurerm_availability_set.vm_set.id
network_interface_ids = [
azurerm_network_interface.vm_nic.id

]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}

depends_on = [

azurerm_network_interface.vm_nic,
azurerm_availability_set.vm_set

# create public ip

resource "azurerm_public_ip" "terraform_public" {


name = "terraform-public"
resource_group_name = local.resource_group
location = local.location
allocation_method = "Static"

You might also like