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

oxide_instance: allow in-place external_ips modification #381

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sudomateo
Copy link
Collaborator

Closes #378.

This patch updates the oxide_instance resource to support in-place modifications to its external_ips attribute. That is, the instance will no longer be destroyed and recreated when external_ips is modified. Instead, the instance will be stopped, external IPs will be detachd and/or attached, and the instance will be started.

This patch also updates the Read method to refresh the external IPs attached to the instance. Previously, since the external IPs required a resource replacement there was no need to refresh them.

There are 2 types of external IPs, ephemeral and floating. There can be at most 1 ephemeral external IP attached to an instance and any number of floating external IPs. That means in order to modify ephemeral external IPs the external IPs must be detached first and then attached.

This patch needs the following work before it can be merged.

  • Add tests for the new external_ips modification logic.
  • Add validation logic to external_ips to enforce at most 1 ephemeral external IP. This was previously "validated" during instance creation but is not updated during instance update.

Here's the error that's returned when an instance is created with more than 1 ephemeral external IP.

oxide_instance.foo: Creating...
╷
│ Error: Error creating instance
│
│   with oxide_instance.foo,
│   on main.tf line 24, in resource "oxide_instance" "foo":
│   24: resource "oxide_instance" "foo" {
│
│ API error: POST https://oxide.example.com/v1/instances?project=5476ccc9-464d-4dc4-bfc0-5154de1c986f
│ ----------- RESPONSE -----------
│ Status: 400 InvalidRequest
│ Message: An instance may not have more than 1 ephemeral IP address
│ RequestID: fc6144e5-fa76-4583-a024-2e49ce17140e
│ ------- RESPONSE HEADERS -------
│ Content-Type: [application/json]
│ X-Request-Id: [fc6144e5-fa76-4583-a024-2e49ce17140e]
│ Date: [Thu, 09 Jan 2025 03:28:48 GMT]
│ Content-Length: [166]
│
╵

Closes #378.

This patch updates the `oxide_instance` resource to support in-place
modifications to its `external_ips` attribute. That is, the instance
will no longer be destroyed and recreated when `external_ips` is
modified. Instead, the instance will be stopped, external IPs will be
detachd and/or attached, and the instance will be started.

This patch also updates the `Read` method to refresh the external IPs
attached to the instance. Previously, since the external IPs required a
resource replacement there was no need to refresh them.

There are 2 types of external IPs, ephemeral and floating. There can
be at most 1 ephemeral external IP attached to an instance and any
number of floating external IPs. That means in order to modify ephemeral
external IPs the external IPs must be detached first and then attached.

This patch needs the following work before it can be merged.
- [ ] Add tests for the new `external_ips` modification logic.
- [ ] Add validation logic to `external_ips` to enforce at most 1
ephemeral external IP. This was previously "validated" during instance
creation but is not updated during instance update.

Here's the error that's returned when an instance is created with more
than 1 ephemeral external IP.

```
oxide_instance.foo: Creating...
╷
│ Error: Error creating instance
│
│   with oxide_instance.foo,
│   on main.tf line 24, in resource "oxide_instance" "foo":
│   24: resource "oxide_instance" "foo" {
│
│ API error: POST https://oxide.example.com/v1/instances?project=5476ccc9-464d-4dc4-bfc0-5154de1c986f
│ ----------- RESPONSE -----------
│ Status: 400 InvalidRequest
│ Message: An instance may not have more than 1 ephemeral IP address
│ RequestID: fc6144e5-fa76-4583-a024-2e49ce17140e
│ ------- RESPONSE HEADERS -------
│ Content-Type: [application/json]
│ X-Request-Id: [fc6144e5-fa76-4583-a024-2e49ce17140e]
│ Date: [Thu, 09 Jan 2025 03:28:48 GMT]
│ Content-Length: [166]
│
╵
```
@sudomateo sudomateo force-pushed the sudomateo/external-ips-modification branch from c5e8592 to 1b14f69 Compare January 9, 2025 04:39
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.

Support in-place instance ephemeral and floating IP changes
1 participant