-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm.tf
108 lines (83 loc) · 2.9 KB
/
vm.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
resource "azurerm_resource_group" "vmrg" {
name = var.resource_group_name
location = var.location
}
resource "azurerm_virtual_network" "main" {
name = var.virtual_network_name
address_space = ["10.0.0.0/16"]
location = var.location
resource_group_name = var.resource_group_name
depends_on = [azurerm_resource_group.vmrg]
}
resource "azurerm_subnet" "internal" {
name = var.subnet_name
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.2.0/24"]
depends_on = [azurerm_resource_group.vmrg]
}
resource "azurerm_network_interface" "main" {
name = var.network_interface_name
location = var.location
resource_group_name = var.resource_group_name
depends_on = [azurerm_resource_group.vmrg]
ip_configuration {
name = var.ip_config
subnet_id = azurerm_subnet.internal.id
private_ip_address_allocation = var.address_allocation
public_ip_address_id = azurerm_public_ip.public_ip.id
}
}
resource "azurerm_virtual_machine" "main" {
name = var.vm_name
location = var.location
resource_group_name = var.resource_group_name
network_interface_ids = [azurerm_network_interface.main.id]
vm_size = var.vm_size
depends_on = [azurerm_resource_group.vmrg]
storage_image_reference {
publisher = var.publisher
offer = var.offer
sku = var.sku
version = var.image_version
}
storage_os_disk {
name = var.os_disk_name
caching = var.caching_disk
create_option = var.create_option
managed_disk_type = var.managed_disk_type
}
os_profile {
computer_name = var.computer_name
admin_username = var.admin_username
admin_password = var.admin_password
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = var.environment
}
}
resource "azurerm_public_ip" "public_ip" {
name = var.public_ip
location = var.location
resource_group_name = var.resource_group_name
allocation_method = var.allocation_method
depends_on = [azurerm_resource_group.vmrg]
}
resource "azurerm_managed_disk" "data_disk" {
name = var.managed_disk
location = var.location
resource_group_name = var.resource_group_name
storage_account_type = var.managed_disk_type
create_option = var.create_option_disk
disk_size_gb = var.disk_size_gb
depends_on = [azurerm_resource_group.vmrg]
}
resource "azurerm_virtual_machine_data_disk_attachment" "vm-data-disk-attach" {
managed_disk_id = azurerm_managed_disk.data_disk.id
virtual_machine_id = azurerm_virtual_machine.main.id
lun = var.lun
caching = var.caching_disk
}