terraform: never replace a running server
hcloud replaces a server when user_data, image or ssh_keys change, and cloud-init only runs at first boot anyway. An edit to cloud-init, like adding a user, would therefore plan the destruction of a production machine. Ignore changes to those three attributes and set prevent_destroy on both servers, so cloud-init describes a rebuild and nothing else. Add user zerrtika to cloud-init to match the servers; the user was created on them by playbook 04. Assisted-by: Claude:fable-5-2
This commit is contained in:
parent
a79b110259
commit
e5322cbac2
4 changed files with 42 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Ops Server - CX22 (2 vCPU, 4GB RAM)
|
||||
# Ops Server (2 vCPU, 4GB RAM)
|
||||
resource "hcloud_server" "ops" {
|
||||
name = "asxpio-ops"
|
||||
image = "debian-13"
|
||||
|
|
@ -33,6 +33,13 @@ resource "hcloud_server" "ops" {
|
|||
|
||||
# Cloud-init for automated server setup
|
||||
user_data = file("${path.module}/cloud-init/ops.yaml")
|
||||
# cloud-init only runs at first boot, and hcloud replaces the server
|
||||
# when user_data, image or ssh_keys change. Never let an edit to those
|
||||
# destroy a running machine: changes there apply to a rebuild only.
|
||||
lifecycle {
|
||||
ignore_changes = [user_data, image, ssh_keys]
|
||||
prevent_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
# Services Server - CX43 (8 vCPU, 16GB RAM)
|
||||
|
|
@ -70,4 +77,11 @@ resource "hcloud_server" "services" {
|
|||
|
||||
# Cloud-init for automated server setup
|
||||
user_data = file("${path.module}/cloud-init/services.yaml")
|
||||
# cloud-init only runs at first boot, and hcloud replaces the server
|
||||
# when user_data, image or ssh_keys change. Never let an edit to those
|
||||
# destroy a running machine: changes there apply to a rebuild only.
|
||||
lifecycle {
|
||||
ignore_changes = [user_data, image, ssh_keys]
|
||||
prevent_destroy = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue