Terraform

If you are in an environment where resources are provisioned using Terraform, you can use the provisioned Terraform module to generate a Solidblocks cloud-init based user data script.

main.tf



resource "hcloud_volume" "example" {
  name     = "example"
  size     = 16
  format   = "ext4"
  location = var.location
}

resource "hcloud_volume_attachment" "example" {
  server_id = hcloud_server.example.id
  volume_id = hcloud_volume.example.id
}

module "example" {
  source  = "github.com/pellepelster/terraform-null-solidblocks-cloud-init?ref=0.3.1"

  storage = [
    { linux_device = hcloud_volume.example.linux_device, mount_path = "/data1" },
  ]

  acme_ssl = {
    path         = "/data1/ssl"
    email        = "contact@blcks.de"
    domains      = ["example.blcks.de"]
    acme_server  = "https://acme-staging-v02.api.letsencrypt.org/directory"
    dns_provider = "hetzner"
    variables = {
      HETZNER_API_KEY : var.hetzner_dns_api_token
      HETZNER_HTTP_TIMEOUT : "30"
      HETZNER_PROPAGATION_TIMEOUT : "300"
    }
  }
}

resource "hcloud_server" "example" {
  name        = "test"
  image       = "debian-11"
  server_type = "cx22"
  location    = var.location
  ssh_keys    = [hcloud_ssh_key.ssh_key.id]
  user_data   = <<EOT
${module.example.user_data}

# do something with the generated certificate
ls -lsa /data1/ssl/certificates/example.blcks.de.crt
EOT
}

variables.tf



variable "hetzner_dns_api_token" {
  type = string
}

variable "location" {
  type    = string
  default = "nbg1"
}

versions.tf



variable "hetzner_dns_api_token" {
  type = string
}

variable "location" {
  type    = string
  default = "nbg1"
}