-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmss.tf
120 lines (98 loc) · 3.67 KB
/
vmss.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
# VMSS
#https://www.terraform.io/docs/providers/azurerm/r/linux_virtual_machine_scale_set.html
resource "azurerm_linux_virtual_machine_scale_set" "tfrg" {
name = "${var.resource.prefix}webvm"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
upgrade_mode = "Automatic"
/*automatic_os_upgrade_policy = {
disable_automatic_rollback = true
enable_automatic_os_upgrade = false
}*/
overprovision = false
sku = var.vm.size
instances = var.vm.webcount
computer_name_prefix = "${var.resource.prefix}webvm"
admin_username = var.vm.admin_username
admin_password = var.vm.admin_password
disable_password_authentication = false
custom_data = base64encode( file("../script/cloud-init.txt") )
os_disk {
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
//disk_size_gb = 128
}
//source_image_id = var.vm.osimageuri
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
network_interface {
name = "networkinterface"
primary = true
network_security_group_id = azurerm_network_security_group.tfwebnsg.id
ip_configuration {
name = "ipconfig"
primary = true
subnet_id = azurerm_subnet.tfwebvnet.id
load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.vmss.id]
load_balancer_inbound_nat_rules_ids = [azurerm_lb_nat_pool.vmss.id]
}
}
}
# Public LB
resource "azurerm_public_ip" "vmss" {
name = "vmss-pip"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_lb" "vmss" {
name = "vmss-lb"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
sku = "Standard"
frontend_ip_configuration {
name = "vmss-ipconfig"
public_ip_address_id = azurerm_public_ip.vmss.id
}
}
resource "azurerm_lb_rule" "vmss" {
resource_group_name = azurerm_resource_group.tfrg.name
loadbalancer_id = azurerm_lb.vmss.id
name = "vmss-lbrule"
protocol = "Tcp"
frontend_port = 80
backend_port = 80
frontend_ip_configuration_name = "vmss-ipconfig"
backend_address_pool_id = azurerm_lb_backend_address_pool.vmss.id
probe_id = azurerm_lb_probe.vmss.id
}
resource "azurerm_lb_backend_address_pool" "vmss" {
resource_group_name = azurerm_resource_group.tfrg.name
loadbalancer_id = azurerm_lb.vmss.id
name = "vmss-bepool"
}
resource "azurerm_lb_nat_pool" "vmss" {
resource_group_name = azurerm_resource_group.tfrg.name
name = "SSH"
loadbalancer_id = azurerm_lb.vmss.id
protocol = "Tcp"
frontend_port_start = 50000
frontend_port_end = 50119
backend_port = 22
frontend_ip_configuration_name = "vmss-ipconfig"
}
resource "azurerm_lb_probe" "vmss" {
resource_group_name = azurerm_resource_group.tfrg.name
loadbalancer_id = azurerm_lb.vmss.id
name = "healthprobe"
protocol = "Tcp"
port = 80
}
output "vmss_ip_address" {
value = azurerm_public_ip.vmss.ip_address
}