forked from jpaulodefarias/wordpress-azure-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.tf
115 lines (97 loc) · 3.59 KB
/
web.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
resource "azurerm_virtual_network" "wordpress" {
name = "wordpress-vnet"
address_space = ["10.0.0.0/16"]
location = var.location
resource_group_name = azurerm_resource_group.wordpress.name
tags = var.tags
}
resource "azurerm_subnet" "wordpress" {
name = "wordpress-subnet"
resource_group_name = azurerm_resource_group.wordpress.name
virtual_network_name = azurerm_virtual_network.wordpress.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_public_ip" "wordpress" {
name = "wordpress-public-ip"
location = var.location
resource_group_name = azurerm_resource_group.wordpress.name
allocation_method = "Static"
domain_name_label = random_string.fqdn.result
tags = var.tags
}
resource "azurerm_lb" "wordpress" {
name = "wordpress-lb"
location = var.location
resource_group_name = azurerm_resource_group.wordpress.name
frontend_ip_configuration {
name = "PublicIPAddress"
public_ip_address_id = azurerm_public_ip.wordpress.id
}
tags = var.tags
}
resource "azurerm_lb_backend_address_pool" "bpepool" {
loadbalancer_id = azurerm_lb.wordpress.id
name = "BackEndAddressPool"
}
resource "azurerm_lb_probe" "wordpress" {
resource_group_name = azurerm_resource_group.wordpress.name
loadbalancer_id = azurerm_lb.wordpress.id
name = "ssh-running-probe"
port = var.application_port
}
resource "azurerm_lb_rule" "lbnatrule" {
resource_group_name = azurerm_resource_group.wordpress.name
loadbalancer_id = azurerm_lb.wordpress.id
name = "http"
protocol = "Tcp"
frontend_port = var.application_port
backend_port = var.application_port
backend_address_pool_id = azurerm_lb_backend_address_pool.bpepool.id
frontend_ip_configuration_name = "PublicIPAddress"
probe_id = azurerm_lb_probe.wordpress.id
}
resource "azurerm_linux_virtual_machine_scale_set" "wordpress" {
name = "vmscaleset"
location = var.location
resource_group_name = azurerm_resource_group.wordpress.name
sku = "Standard_DS1_v2"
instances = 2
admin_username = var.admin_username
admin_password = var.admin_password
disable_password_authentication = false
custom_data = data.template_cloudinit_config.config.rendered
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
network_interface {
name = "NetworkInterface"
primary = true
ip_configuration {
name = "IPConfiguration"
subnet_id = azurerm_subnet.wordpress.id
load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.bpepool.id]
primary = true
}
}
tags = var.tags
}
data "template_file" "script" {
template = file("web.conf")
}
data "template_cloudinit_config" "config" {
gzip = true
base64_encode = true
part {
filename = "web.conf"
content_type = "text/cloud-config"
content = data.template_file.script.rendered
}
depends_on = [azurerm_mysql_server.wordpress]
}