-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompute.tf
More file actions
74 lines (64 loc) · 1.94 KB
/
compute.tf
File metadata and controls
74 lines (64 loc) · 1.94 KB
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
resource "azurerm_linux_virtual_machine_scale_set" "web_vmss" {
name = "web-vmss"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = "Standard_B1s"
instances = 2
admin_username = "azureuser"
admin_ssh_key {
username = "azureuser"
public_key = file("~/.ssh/azure_terraform_key.pub")
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts"
version = "latest"
}
network_interface {
name = "webvmss-nic"
primary = true
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.web_subnet.id
load_balancer_backend_address_pool_ids = [
azurerm_lb_backend_address_pool.web_backend_pool.id
]
}
}
custom_data = base64encode(<<EOF
#cloud-config
package_update: true
packages:
- nginx
runcmd:
- systemctl enable nginx
- systemctl start nginx
- echo "<h1>Hello from VMSS instance $(hostname)</h1>" > /var/www/html/index.html
EOF
)
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
}
resource "azurerm_virtual_machine_scale_set_extension" "node_app" {
name = "nodejs-app"
virtual_machine_scale_set_id = azurerm_linux_virtual_machine_scale_set.web_vmss.id
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.1"
settings = jsonencode({
fileUris = [
"https://raw.githubusercontent.com/Poison-Iveey/terraform-web-deployment/main/scripts/install_node_app.sh"
]
commandToExecute = "bash install_node_app.sh"
})
protected_settings = jsonencode({
DB_HOST = var.db_host
DB_USER = var.db_user
DB_PASSWORD = var.db_password
DB_NAME = var.db_name
})
}