-
Notifications
You must be signed in to change notification settings - Fork 0
/
CentOSVM.tf
86 lines (72 loc) · 2.47 KB
/
CentOSVM.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
resource "azurerm_public_ip" "centosPublicIP" {
name = "${var.suffix}${var.centosVMName}"
location = azurerm_resource_group.mainRG.location
resource_group_name = azurerm_resource_group.mainRG.name
allocation_method = var.publicIPAllocation
tags = var.tags
}
resource "azurerm_network_interface" "centosNI" {
name = "${var.suffix}${var.centosVMName}"
location = azurerm_resource_group.mainRG.location
resource_group_name = azurerm_resource_group.mainRG.name
ip_configuration {
name = "centosconfiguration"
subnet_id = azurerm_subnet.frontend2.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.centosPublicIP.id
}
tags = var.tags
}
resource "azurerm_network_interface_security_group_association" "centosSG" {
network_interface_id = azurerm_network_interface.centosNI.id
network_security_group_id = azurerm_network_security_group.sshNSG.id
}
resource "azurerm_linux_virtual_machine" "centosVM" {
name = "${var.suffix}${var.centosVMName}"
resource_group_name = azurerm_resource_group.mainRG.name
location = azurerm_resource_group.mainRG.location
size = var.vmSize
admin_username = var.vmUserName
# encryption_at_host_enabled = true
network_interface_ids = [azurerm_network_interface.centosNI.id, ]
admin_ssh_key {
username = var.vmUserName
public_key = file(var.sshKeyPath)
}
os_disk {
name = "${var.suffix}${var.centosVMName}OSDisk"
caching = "ReadWrite"
storage_account_type = var.osDisk
}
source_image_reference {
publisher = "OpenLogic"
offer = "CentOS"
sku = var.centossku
version = "latest"
}
boot_diagnostics {
storage_account_uri = azurerm_storage_account.mainSA.primary_blob_endpoint
}
# from file
custom_data = filebase64("cloud-init.yaml")
# from variable
#custom_data = base64encode(local.custom_data)
# in-line
/* custom_data = base64encode(<<CUSTOM_DATA
#cloud-config
package_upgrade: true
packages:
- httpd
- java-1.8.0-openjdk-devel
- git
write_files:
- content: <!doctype html><html><body><h1>Hello CentOS 2019 from Azure!</h1></body></html>
path: /var/www/html/index.html
runcmd:
- [ systemctl, enable, httpd.service ]
- [ systemctl, start, httpd.service ]
CUSTOM_DATA
)
*/
tags = var.tags
}