Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordering network_interfaces on servers re-assignes IPs #650

Open
Xartos opened this issue Oct 3, 2024 · 3 comments
Open

Reordering network_interfaces on servers re-assignes IPs #650

Xartos opened this issue Oct 3, 2024 · 3 comments

Comments

@Xartos
Copy link

Xartos commented Oct 3, 2024

The problem

When reordering network interfaces blocks on a server it always recreates the interfaces and thus gives them a new IP.

For example if I have this in on a server:

network_interface {
  type    = "public"
}

network_interface {
  type    = "private"
  network = upcloud_network.private.id
}

Then I rearrange it to look like this:

network_interface {
  type    = "private"
  network = upcloud_network.private.id
}

network_interface {
  type    = "public"
}

When I then run plan I get the following change

      ~ network_interface {
          ~ network             = "<redacted>" -> "<redacted>"
          ~ type                = "public" -> "private"
            # (6 unchanged attributes hidden)
        }
      ~ network_interface {
          ~ type                = "private" -> "public"
            # (7 unchanged attributes hidden)
        }

And after running apply, both those NICs are recreated and get new IPs

Expected behaviour

I'd expect that the order shouldn't matter, but more importantly, the NICs should keep their addresses after they are reordered.

@Xartos
Copy link
Author

Xartos commented Oct 3, 2024

Another alternative would be that it's very clear that these nics are getting new addresses. And in that case I guess this one gets very related to this issue #646

@kangasta
Copy link
Contributor

kangasta commented Oct 7, 2024

The definition order is currently used as is in the API requests as the network_interface blocks are implemented as list. This is currently only documented through the data type after the field name in the resource docs. So, we could at least improve that description to better communicate how these blocks relate to the cloud resource and API requests, as you suggested in the latest comment.

Changing the list into a set or using list nested attribute instead of blocks to make the list behavior more visible in the Terraform configuration side would both be breaking changes.

@kangasta
Copy link
Contributor

kangasta commented Oct 17, 2024

Actually, I might be confusing this with some other field as there seems to be more complex handling for the network_interface blocks, so we could look into improving the handling as well 🤔 However, the data type of network_interface is list, so the order will have significance because of that even if can otherwise improve the logic.

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

No branches or pull requests

2 participants