Initial commit
This commit is contained in:
commit
ac2201f72c
5 changed files with 121 additions and 0 deletions
13
.editorconfig
Normal file
13
.editorconfig
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
end_of_line = lf
|
||||||
|
max_line_length = null
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
.terraform
|
||||||
|
.terraform.lock.hcl
|
||||||
|
variables.auto.tfvars
|
||||||
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
|
||||||
|
}
|
||||||
14
templates/config.yaml
Normal file
14
templates/config.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
passwd:
|
||||||
|
users:
|
||||||
|
- name: core
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEUz21xFatGKfSwjeg/BOBus2Jn17o8xVthrMFAsDtRD iam@vojtechmares.com
|
||||||
|
|
||||||
|
systemd:
|
||||||
|
units:
|
||||||
|
# Using flatcar-linux-update-operator instead. See: https://github.com/flatcar-linux/flatcar-linux-update-operator#requirements for more information
|
||||||
|
- name: locksmithd.service
|
||||||
|
mask: true
|
||||||
|
- name: update-engine.service
|
||||||
|
enabled: true
|
||||||
12
versions.tf
Normal file
12
versions.tf
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
hcloud = {
|
||||||
|
source = "hetznercloud/hcloud"
|
||||||
|
version = "1.32.1"
|
||||||
|
}
|
||||||
|
ct = {
|
||||||
|
source = "poseidon/ct"
|
||||||
|
version = "0.9.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue