-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdeployVM.tf
149 lines (128 loc) · 3.78 KB
/
deployVM.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
terraform {
backend "azurerm" {
resource_group_name = "DevOpsConfig"
storage_account_name = "saTerraform"
container_name = "terraform"
key = "terraform.tfstate"
}
}
provider "azurerm" {
features { }
}
variable "RG" {
default = "RG4"
}
variable "VM" {
default = "VM1"
}
variable "VNET_ADDRESS" {
default = "10.10.0.0/16"
}
variable "SUBNET_ADDRESS" {
default = "10.10.0.0/24"
}
data "azurerm_key_vault" "keyvault" {
name = "kvHRSConfig"
resource_group_name = "DevOpsConfig"
}
data "azurerm_key_vault_secret" "adminpwd" {
name = "adminpwd"
key_vault_id = data.azurerm_key_vault.keyvault.id
}
resource "azurerm_resource_group" "RG" {
name = var.RG
location = "West Europe"
}
resource "azurerm_virtual_network" "VNet" {
name = "VNet1"
address_space = [ var.VNET_ADDRESS ]
location = azurerm_resource_group.RG.location
resource_group_name = azurerm_resource_group.RG.name
}
resource "azurerm_subnet" "Subnet1" {
name = "FESubnet"
address_prefixes = [ var.SUBNET_ADDRESS ]
resource_group_name = azurerm_resource_group.RG.name
virtual_network_name = azurerm_virtual_network.VNet.name
}
resource "azurerm_public_ip" "Pip1" {
name = "PipVM1"
resource_group_name = azurerm_resource_group.RG.name
location = azurerm_resource_group.RG.location
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_network_security_group" "NSG1" {
name = "NsgVM1"
resource_group_name = azurerm_resource_group.RG.name
location = azurerm_resource_group.RG.location
}
resource "azurerm_network_security_rule" "RDP" {
name = "AllowRDP"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
network_security_group_name = azurerm_network_security_group.NSG1.name
resource_group_name = azurerm_resource_group.RG.name
}
resource "azurerm_network_security_rule" "HTTP" {
name = "AllowHTTP"
priority = 101
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
network_security_group_name = azurerm_network_security_group.NSG1.name
resource_group_name = azurerm_resource_group.RG.name
}
resource "azurerm_network_interface" "NIC1" {
name = "NicVM1"
resource_group_name = azurerm_resource_group.RG.name
location = azurerm_resource_group.RG.location
ip_configuration {
name = "ipconfigVM1"
subnet_id = azurerm_subnet.Subnet1.id
private_ip_address_allocation = "dynamic"
public_ip_address_id = azurerm_public_ip.Pip1.id
}
}
resource "azurerm_network_interface_security_group_association" "NsgToNic" {
network_interface_id = azurerm_network_interface.NIC1.id
network_security_group_id = azurerm_network_security_group.NSG1.id
}
resource "azurerm_virtual_machine" "VM1" {
name = var.VM
resource_group_name = azurerm_resource_group.RG.name
location = azurerm_resource_group.RG.location
network_interface_ids = [ azurerm_network_interface.NIC1.id ]
vm_size = "Standard_D2S_v3"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
storage_os_disk {
name = "osdiskVM1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
os_profile {
computer_name = "VM1"
admin_username = "u2uadmin"
admin_password = data.azurerm_key_vault_secret.adminpwd.value
}
os_profile_windows_config {
provision_vm_agent = true
}
}