-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
74 lines (66 loc) · 1.98 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
70
71
72
73
74
#
# terraform-hcloud-routeros-router/main.tf - provide a hcloud_server-based RouterOS router.
#
# Creates a Hetzner server in rescue mode, installs a Mikrotek boot image
# and sets up a proper admin user
# -written by selfscrum. C 2020, MIT-Licence
#
#
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
}
}
required_version = ">= 0.13"
}
###
# the router machine
#
resource "hcloud_server" "router" {
name = format("%s-%s-router", var.system_stage, var.system_name)
image = "ubuntu-18.04" # doesn't matter since it will vanish anyway behind the router partition
server_type = var.router_type
location = var.location
ssh_keys = [ var.server_key ]
rescue = "linux64"
labels = {
"Name" = var.system_name
"Stage" = var.system_stage
"ROUTER" = true
}
# transfer the bootstrap script
provisioner "file" {
source = format ("%s/install_router.sh", path.module)
destination = "/tmp/install_router.sh"
connection {
type = "ssh"
user = "root"
private_key = var.private_key
host = self.ipv4_address
}
}
# run the bootstrap script
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/install_router.sh",
"/tmp/install_router.sh"
]
connection {
type = "ssh"
user = "root"
private_key = var.private_key
host = self.ipv4_address
}
}
# configure the router - set new user and remove admin
provisioner "local-exec" {
command = format("chmod +x %s/access_router.sh ; %s/access_router.sh %s %s %s",
path.module,
path.module,
self.ipv4_address,
var.router_user,
var.router_password
)
}
}