-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
69 lines (61 loc) · 1.58 KB
/
main.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
provider "profitbricks" {
}
resource "profitbricks_datacenter" "vdc" {
name = "terraform-dc"
location = "de/fra"
}
resource "profitbricks_lan" "webserver_lan" {
datacenter_id = profitbricks_datacenter.vdc.id
public = true
name = "public"
}
resource "profitbricks_ipblock" "webserver_ip" {
location = profitbricks_datacenter.vdc.location
size = var.vm_count
}
resource "profitbricks_server" "webserver" {
count = var.vm_count
name = "webserver"
datacenter_id = profitbricks_datacenter.vdc.id
cores = 1
ram = 1024
availability_zone = "AUTO"
volume {
name = "system"
size = 15
disk_type = "HDD"
}
image_name = var.os_image
image_password = "StrengGeheim"
ssh_key_path = var.public_key_path
nic {
lan = profitbricks_lan.webserver_lan.id
dhcp = true
ip = profitbricks_ipblock.webserver_ip.ips[count.index]
firewall {
protocol = "TCP"
name = "SSH"
port_range_start = 22
port_range_end = 22
}
}
provisioner "remote-exec" {
inline = [
"while fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do sleep 1; done",
"apt-get update && apt-get -y install nginx"
]
connection {
type = "ssh"
private_key = file(var.private_key_path)
user = "root"
timeout = "4m"
host = self.primary_ip
}
}
}
output "server_info" {
value = profitbricks_server.webserver
}
output "ips" {
value = join(" ", profitbricks_ipblock.webserver_ip.ips)
}