forked from Nouma2016/azure-webserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
130 lines (111 loc) · 3.38 KB
/
main.tf
File metadata and controls
130 lines (111 loc) · 3.38 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
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
121
122
123
124
125
126
127
128
129
130
resource "azurerm_resource_group" "webserver" {
name = "nginx-server-fabio"
location = var.location
}
resource "azurerm_network_interface_security_group_association" "nsgnic" {
network_interface_id = azurerm_network_interface.webserver.id
network_security_group_id = azurerm_network_security_group.allowedports.id
}
resource "azurerm_network_security_group" "allowedports" {
name = "allowedports"
resource_group_name = azurerm_resource_group.webserver.name
location = azurerm_resource_group.webserver.location
security_rule {
name = "http"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "https"
priority = 200
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "custom"
priority = 400
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "8080"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "ssh"
priority = 300
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
resource "azurerm_public_ip" "webserver_public_ip" {
name = "webserver_public_ip"
location = var.location
resource_group_name = azurerm_resource_group.webserver.name
allocation_method = "Dynamic"
tags = {
environment = var.environment
costcenter = "it"
}
depends_on = [azurerm_resource_group.webserver]
}
resource "azurerm_network_interface" "webserver" {
name = "nginx-interface"
location = azurerm_resource_group.webserver.location
resource_group_name = azurerm_resource_group.webserver.name
ip_configuration {
name = "internal"
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.webserver-subnet.id
public_ip_address_id = azurerm_public_ip.webserver_public_ip.id
}
depends_on = [azurerm_resource_group.webserver]
}
resource "azurerm_linux_virtual_machine" "nginx" {
size = var.instance_size
name = "nginx-webserver"
resource_group_name = azurerm_resource_group.webserver.name
location = azurerm_resource_group.webserver.location
custom_data = base64encode(file("init-script.sh"))
network_interface_ids = [
azurerm_network_interface.webserver.id,
]
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
computer_name = "nginx"
admin_username = "fabio"
admin_password = "Azerty-123"
disable_password_authentication = false
os_disk {
name = "nginxdisk01"
caching = "ReadWrite"
#create_option = "FromImage"
storage_account_type = "Standard_LRS"
}
tags = {
environment = var.environment
costcenter = "it"
}
depends_on = [azurerm_resource_group.webserver]
}