Add hetzner storage box to terraform and immich

This commit is contained in:
Tobias Reisinger 2025-12-11 16:31:16 +01:00
parent 400b342ec4
commit 0a6ac9b168
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
13 changed files with 210 additions and 77 deletions

View file

@ -97,3 +97,57 @@ resource "hcloud_firewall" "nodes_services" {
}
}
}
#########################
### Storage Box Setup ###
#########################
resource "random_password" "hcloud_storage_box_password" {
length = 32
override_special = "-_+="
min_lower = 4
min_numeric = 4
min_special = 4
min_upper = 4
}
resource "hcloud_storage_box" "box01" {
name = "box01"
storage_box_type = "bx11"
location = "fsn1"
password = random_password.hcloud_storage_box_password.result
access_settings = {
reachable_externally = true
samba_enabled = false
ssh_enabled = false
webdav_enabled = false
zfs_enabled = true
}
delete_protection = true
}
resource "random_password" "hcloud_storage_box_sub_passwords" {
for_each = local.services_storage_box
length = 32
override_special = "-_+"
min_lower = 4
min_numeric = 4
min_special = 4
min_upper = 4
}
resource "hcloud_storage_box_subaccount" "service_accounts" {
for_each = local.services_storage_box
storage_box_id = hcloud_storage_box.box01.id
home_directory = "${each.key}/"
password = random_password.hcloud_storage_box_sub_passwords[each.key].result
access_settings = {
reachable_externally = true
webdav_enabled = true
}
description = each.key
}

View file

@ -6,7 +6,7 @@ terraform {
}
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.45.0"
version = "~> 1.57.0"
}
healthchecksio = {
source = "kristofferahl/healthchecksio"
@ -33,4 +33,6 @@ locals {
buckets_s3 = merge([for key, val in local.services_s3 : {for bucket in val : bucket => key}]...)
hetzner_hosts = {for key, val in var.hosts : key => val if val.provider == "hetzner"}
services_storage_box = {for key, val in var.services : key => val if val.storage_box}
}

View file

@ -27,6 +27,17 @@ output "hosts" {
}
}
output "hcloud_storage_box_accounts" {
value = {
for key, value in hcloud_storage_box_subaccount.service_accounts : key => {
host = value.server
user = value.username
pass = value.password
}
}
sensitive = true
}
output "healthchecksio" {
value = {
backup = {

View file

@ -38,6 +38,7 @@ variable "services" {
s3 = optional(string)
s3_buckets = optional(list(string))
database = bool
storage_box = optional(bool, false)
}))
}