Initial commit
This commit is contained in:
commit
ac2201f72c
5 changed files with 121 additions and 0 deletions
79
main.tf
Normal file
79
main.tf
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
variable "hcloud_token" {
|
||||
type = string
|
||||
}
|
||||
|
||||
provider "hcloud" {
|
||||
token = var.hcloud_token
|
||||
}
|
||||
|
||||
data "hcloud_ssh_key" "vojtechmares" {
|
||||
name = "iam@vojtechmares.com"
|
||||
}
|
||||
|
||||
resource "hcloud_ssh_key" "ssh_key" {
|
||||
name = "ssh-key"
|
||||
public_key = var.ssh_public_key
|
||||
}
|
||||
|
||||
data "ct_config" "ignition" {
|
||||
content = file("templates/config.yaml")
|
||||
strict = true
|
||||
pretty_print = true
|
||||
}
|
||||
|
||||
resource "hcloud_server" "server" {
|
||||
name = "flatcar-linux--test"
|
||||
server_type = "cx11"
|
||||
|
||||
labels = {
|
||||
"os" = "flatcar-linux"
|
||||
}
|
||||
|
||||
location = "nbg1"
|
||||
|
||||
// Unused because of rescue mode, but required field
|
||||
image = "debian-11"
|
||||
rescue = "linux64"
|
||||
ssh_keys = [data.hcloud_ssh_key.vojtechmares.id]
|
||||
|
||||
connection {
|
||||
host = hcloud_server.test.ipv4_address
|
||||
timeout = "5m"
|
||||
user = "root"
|
||||
}
|
||||
|
||||
provisioner "file" {
|
||||
content = data.ct_config.ignition.rendered
|
||||
destination = "/root/ignition.json"
|
||||
}
|
||||
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"set -ex",
|
||||
"apt update -y",
|
||||
"apt install -y gawk",
|
||||
"curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://raw.githubusercontent.com/kinvolk/init/flatcar-master/bin/flatcar-install",
|
||||
"chmod +x flatcar-install",
|
||||
"./flatcar-install -s -i /root/ignition.json",
|
||||
"shutdown -r +1",
|
||||
]
|
||||
}
|
||||
|
||||
# Configure after installation
|
||||
provisioner "remote-exec" {
|
||||
connection {
|
||||
host = self.ipv4_address
|
||||
timeout = "3m"
|
||||
user = "core"
|
||||
}
|
||||
|
||||
inline = [
|
||||
"sudo hostnamectl set-hostname ${self.name}",
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
output "ip" {
|
||||
value = hcloud_server.server.ipv4_address
|
||||
}
|
||||
Reference in a new issue