Skip to content

[Question]: Replacing servers one-by-one when using count #1179

@johnhamelink

Description

@johnhamelink

How might I use create_before_destroy to rotate out my servers one-by-one without losing them all in one go while I wait for the new servers to provision?

When I do this, I of course get a uniqueness error, because the new servers have the same name:

resource "hcloud_server" "app-nodejs-server" {
  name               = "${var.environment}-${var.app}-${var.service}-${count.index + 1}"
  count              = var.app-replicas

  lifecycle {
    create_before_destroy = true
  }
}

I'm using opentofu - could I somehow use for_each to do this? I'd appreciate some advice on this, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions