-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
87 lines (71 loc) · 1.78 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
provider "azurerm" {
version = "=2.5.0"
features {}
}
variable "rgName" {
type = string
}
variable "rgLocation" {
type = string
}
variable "vmAdminUsername" {
type = string
}
variable "vmAdminPassword" {
type = string
}
variable "subnetId" {
type = string
}
variable "vmName" {
type = string
}
variable "vmSize" {
type = string
}
variable "nsgId" {
type = string
}
resource "azurerm_public_ip" "pip" {
name = "pip"
resource_group_name = var.rgName
location = var.rgLocation
allocation_method = "Static"
}
resource "azurerm_network_interface" "vnic" {
name = "vnic"
location = var.rgLocation
resource_group_name = var.rgName
ip_configuration {
name = "internal"
subnet_id = var.subnetId
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.pip.id
}
}
resource "azurerm_network_interface_security_group_association" "nsg-assoc" {
network_interface_id = azurerm_network_interface.vnic.id
network_security_group_id = var.nsgId
}
resource "azurerm_windows_virtual_machine" "vm" {
name = var.vmName
resource_group_name = var.rgName
location = var.rgLocation
size = var.vmSize
admin_username = var.vmAdminUsername
admin_password = var.vmAdminPassword
network_interface_ids = [azurerm_network_interface.vnic.id]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}
output "VM_IP" {
value = azurerm_public_ip.pip.ip_address
}