-
-
Save thetechnick/12b33e4edfc96e4ccc9800afef2be7c5 to your computer and use it in GitHub Desktop.
{ | |
"ignition": { | |
"version": "2.0.0", | |
"config": {} | |
}, | |
"storage": { | |
}, | |
"systemd": {}, | |
"networkd": {}, | |
"passwd": { | |
"users": [ | |
{ | |
"name": "core", | |
"sshAuthorizedKeys": [ | |
"<your public key>" | |
] | |
} | |
] | |
} | |
} |
#!/usr/bin/env sh | |
set -e | |
wget https://raw.github.com/coreos/init/master/bin/coreos-install | |
chmod +x coreos-install | |
./coreos-install -d /dev/sda -i /root/ignition.json | |
reboot |
provider "hcloud" { | |
token = "<token>" | |
} | |
resource "hcloud_ssh_key" "notebook" { | |
name = "nschieder@notebook" | |
public_key = "${file("~/.ssh/id_ed25519.pub")}" | |
} | |
resource "hcloud_server" "master" { | |
name = "master" | |
image = "debian-9" | |
server_type = "cx11" | |
ssh_keys = ["${hcloud_ssh_key.notebook.id}"] | |
datacenter = "fsn1-dc8" | |
rescue = "linux64" | |
connection { | |
host = "${hcloud_server.master.ipv4_address}" | |
timeout = "1m" | |
agent = false | |
private_key = "${file("~/.ssh/id_ed25519")}" | |
} | |
provisioner "file" { | |
source = "ignition.json" | |
destination = "/root/ignition.json" | |
} | |
provisioner "remote-exec" { | |
script = "install.sh" | |
} | |
provisioner "remote-exec" { | |
connection { | |
host = "${hcloud_server.master.ipv4_address}" | |
timeout = "1m" | |
agent = false | |
private_key = "${file("~/.ssh/id_ed25519")}" | |
user = "core" | |
} | |
inline = "sudo hostnamectl set-hostname ${hcloud_server.master.name}" | |
} | |
} | |
resource "hcloud_server" "node1" { | |
name = "node1" | |
image = "debian-9" | |
server_type = "cx11" | |
ssh_keys = ["${hcloud_ssh_key.notebook.id}"] | |
datacenter = "fsn1-dc8" | |
rescue = "linux64" | |
connection { | |
host = "${hcloud_server.node1.ipv4_address}" | |
timeout = "1m" | |
agent = false | |
private_key = "${file("~/.ssh/id_ed25519")}" | |
} | |
provisioner "file" { | |
source = "ignition.json" | |
destination = "/root/ignition.json" | |
} | |
provisioner "remote-exec" { | |
script = "install.sh" | |
} | |
provisioner "remote-exec" { | |
connection { | |
host = "${hcloud_server.node1.ipv4_address}" | |
timeout = "1m" | |
agent = false | |
private_key = "${file("~/.ssh/id_ed25519")}" | |
user = "core" | |
} | |
inline = "sudo hostnamectl set-hostname ${hcloud_server.node1.name}" | |
} | |
} |
Hi @mxinden, sorry I have not seen your comment, just updated the config.
@thetechnick Hey there, does this really work? From coreos docs:
The script is self-contained and located on GitHub here and can be run from any Linux distribution. You cannot normally install Container Linux to the same device that is currently booted. However, the Container Linux ISO or any Linux liveCD will allow Container Linux to install to a non-active device.
where by script they refer to coreos-install
script
@thetechnick my apologies I didn't notice the rescue
var being set, all good.
@thetechnick How do you deal with attached volumes? Afaik the volume ID has to be referenced in the ignition.json, but a volume (or volume attachment) requires the server ID, which will only be available once the hcloud_server is provisioned, during which ignition.json is already consumed.
Also, because of the reboot at the end of the install script no exit code is returned, which causes tf to report an error.
@mootari Well I created these scripts before there was any Blockstorage support at Hetzner.
Currently I work exclusively with Kubernetes, so the Container Storage Interface takes care of volume attachment and management.
It should be quite straightforward to build something with the Terraform null and template resource, but I have no use for this right now.
@thetechnick Understood, thanks for offering some context (and thanks for this gist!). My current solution also uses null_resource
, although properly tainting an existing server resource and applying changes is still a pain. Once I figure that part out I'll link a gist to it here.
@thetechnick would you mind changing
hcloud_sshkey
tohcloud_ssh_key
? (See docs)