forked from svalabs/hf-tf-module-hcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
64 lines (56 loc) · 1.57 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
variable "hcloud_token" {}
variable "public_key" {}
variable "image" {}
variable "name" {}
variable "server_type" {}
variable "location" {}
variable "cloud-config" {}
variable "runcmd" {
default = "echo ' '"
}
variable "ide" {
default = false
}
data "template_file" "cloud-config" {
template = "${file("${path.module}/cloud-config.cfg")}"
vars = {
runcmd = "${var.runcmd}"
}
}
data "template_file" "cloud-config-ide" {
template = "${file("${path.module}/cloud-config-ide.cfg")}"
vars = {
runcmd = "${var.runcmd}"
}
}
#Configure the Hetzner Cloud Provider
provider "hcloud" {
version = "= 1.10"
token = "${var.hcloud_token}"
}
# Create a new SSH key
resource "hcloud_ssh_key" "key" {
name = "${var.name}-key"
public_key = "${var.public_key}"
}
# Create a new server running debian
resource "hcloud_server" "node1" {
name = "${var.name}"
image = "${var.image}"
location = "${var.location}"
server_type = "${var.server_type}"
ssh_keys = ["${var.name}-key","ebartz"]
#user_data = "${var.ide ? "#cloud-config\nruncmd:\n- echo 'IDE true' > /root/ide-true.txt\n" : "#cloud-config\nruncmd:\n- ${var.runcmd}\n"}"
#user_data = "templatefile('cloud-config.cfg', {runcmd = ${var.runcmd}})"
#user_data = "${var.ide ? "${data.template_file.cloud-config-ide.rendered}" : "${data.template_file.cloud-config.rendered}"}"
user_data = "${var.cloud-config}"
}
output "private_ip" {
value = "${hcloud_server.node1.ipv4_address}"
}
output "public_ip" {
value = "${hcloud_server.node1.ipv4_address}"
}
output "hostname" {
value = "${hcloud_server.node1.name}"
}