vcard4reseller/deploy/terraform/deploy.tf
Thomas Peterson c49ff37746 Deploy: Terraform-Code-Rollout auf App-Nodes (ohne Recreate)
terraform_data.app_deploy führt per remote-exec auf jedem App-Node ein Update
aus (git reset auf origin + deploy/update.sh: SPA bauen, composer, migrate(app-1),
cache:clear), getriggert über var.deploy_version (z. B. Git-SHA). Server werden
NICHT ersetzt: hcloud_server.app ignoriert user_data-Änderungen (cloud-init nur
Erstboot). Gemeinsames deploy/update.sh (cloud-init ruft es ebenfalls auf).
Fix: ${PRIV:-} in der .tftpl als $${PRIV:-} escaped (templatefile-Kollision).

Workflow: tofu apply -var deploy_version=$(git rev-parse --short HEAD)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 19:47:59 +02:00

30 lines
997 B
HCL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Code-Rollout auf die App-Nodes ohne Neu-Provisionierung.
# Bei Änderung von var.deploy_version (z. B. Git-SHA) führt `tofu apply` auf jedem
# App-Node ein Update aus: neuesten Code holen, SPA neu bauen, Composer/Autoloader
# auffrischen, Cache leeren Migrationen nur auf app-1. Server bleiben erhalten.
resource "terraform_data" "app_deploy" {
count = var.app_count
triggers_replace = [var.deploy_version]
depends_on = [hcloud_server.app]
connection {
type = "ssh"
host = hcloud_server.app[count.index].ipv4_address
user = "root"
private_key = file(pathexpand(var.ssh_private_key_path))
timeout = "5m"
}
provisioner "remote-exec" {
inline = [
"set -e",
"cd /opt/vcard4",
"git fetch --depth 1 origin ${var.repo_branch}",
"git reset --hard origin/${var.repo_branch}",
"DOMAIN='${var.domain}' RUN_MIGRATIONS='${count.index == 0 ? "true" : "false"}' bash /opt/vcard4/deploy/update.sh",
]
}
}