Skip to content

feat(server): allow rebuilding with image and/or user-data#1349

Open
svanrossem wants to merge 4 commits into
hetznercloud:mainfrom
svanrossem:allow-rebuilding-with-image-or-user-data
Open

feat(server): allow rebuilding with image and/or user-data#1349
svanrossem wants to merge 4 commits into
hetznercloud:mainfrom
svanrossem:allow-rebuilding-with-image-or-user-data

Conversation

@svanrossem

Copy link
Copy Markdown

Due to current capacity constraints in several locations, this change adds support for rebuilding an existing node with a new image, ISO, or updated user-data. This provides a practical alternative when provisioning a new node in the desired location is not possible.

With the hcloud-go dependency updated to v2.36.0 (including the changes from hcloud-go PR #813), rebuild functionality is now available and can be leveraged by the provider.

I'm also thinking about a rebuild-argument for rebuilding an existing node without updating the image/ISO or user-data?

@venkatamutyala

Copy link
Copy Markdown

A rebuild argument would be very helpful. This would be very useful for situations where there isn't an image change but people want to start over. Some usecases would be to re-apply an immutable setup or when an ansible playbook requires a clean deployment

@apricote apricote self-assigned this Feb 20, 2026
@apricote

Copy link
Copy Markdown
Member

I am hesitant to accept the pull request in the current form. Please take a look at my concerns in #1348 (comment)

@svanrossem svanrossem force-pushed the allow-rebuilding-with-image-or-user-data branch from b678177 to d1cfefa Compare February 23, 2026 08:53
@svanrossem svanrossem marked this pull request as ready for review March 5, 2026 12:47
@svanrossem svanrossem requested a review from a team as a code owner March 5, 2026 12:47
@svanrossem

Copy link
Copy Markdown
Author
resource "cloudinit_config" "foobar" {
  gzip          = false
  base64_encode = false

  part {
    filename     = "hello-script.sh"
    content_type = "text/x-shellscript"

    content = file("${path.module}/hello-script.sh")
  }

  lifecycle {
    action_trigger {
      events  = [after_create]
      actions = [action.hcloud_server_rebuild.rebuild]
    }
  }
}

resource "hcloud_server" "foo" {
  name        = "foo"
  image       = "fedora-43"
  server_type = "cx23"
  location    = "fsn1"
  user_data   = cloudinit_config.foobar.rendered
  rebuild_when_necessary = true

  public_net {
    ipv4_enabled = false
    ipv6_enabled = true
  }

  lifecycle {
    ignore_changes = [user_data]
  }
}

/* $ terraform apply -invoke action.hcloud_server_rebuild.rebuild */
action "hcloud_server_rebuild" "rebuild" {
  config {
    server_id = hcloud_server.foo.id
    
    image     = hcloud_server.foo.image
    user_data = hcloud_server.foo.user_data
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants