Skip to content

Conversation

MacherelR
Copy link
Contributor

@MacherelR MacherelR commented Aug 22, 2025

Contributor's Note

  • I have added / updated documentation in /docs for any user-facing features or additions.
  • I have added / updated acceptance tests in /fwprovider/tests for any new or updated resources / data sources.
  • I have ran make example to verify that the change works as expected.

Based on the SDN Implementation discussions (#1995 and #817), I have added a custom resource allowing the reload of sdn configurations automatically everytime an SDN resource is created/updated.
Only remaining caveats:

  1. You need to explicitely mention every resource you want to watch inside the replace_triggered_by list, which can become a bit heavy in case of a huge network definition.
  2. When destroying resources (terraform destroy) the configuration isn't applied as the applier resource is also destroyed... Thought about calling the client.ApplyConfig method in the provider's Delete method but as the applier depends_on (safer) the resources, he will be deleted before and therefore that won't ensure the latest apply.

Proof of Work

Here's an example of use:

resource "proxmox_virtual_environment_sdn_zone_simple" "test_zone_1" {
  id = "tZone1"
  nodes= [data.proxmox_virtual_environment_nodes.example.names]
  mtu = 1496

  depends_on = [
    proxmox_virtual_environment_sdn_applier.finalizer
  ]
}

resource "proxmox_virtual_environment_sdn_zone_simple" "test_zone_2" {
  id = "tZone2"
  nodes= [data.proxmox_virtual_environment_nodes.example.names]
  mtu = 1496
  
  depends_on = [
    proxmox_virtual_environment_sdn_applier.finalizer
  ]
}

resource "proxmox_virtual_environment_sdn_applier" "applier" {
   lifecycle {
    replace_triggered_by = [
      proxmox_virtual_environment_sdn_zone_simple.test_zone_1,
      proxmox_virtual_environment_sdn_zone_simple.test_zone_2,
      ]
  }

  depends_on = [
    proxmox_virtual_environment_sdn_zone_simple.test_zone_1,
    proxmox_virtual_environment_sdn_zone_simple.test_zone_2,
  ]
}

resource "proxmox_virtual_environment_sdn_applier" "finalizer" {
}

As you can try it, everytime a resource of type zone will be modified, the applier will be replaced, triggering a reload on proxmox's SDN configs.

See more examples in the acceptance tests.

Now as discussed with @bpg, this might not be the most effective or perfectly rendered version, but I had very little time to work on it and won't be available for some time so, anyone, feel free to leave comments or, even better, collaborate and improve this work ! :)

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #0000 | Relates #0000

@MacherelR MacherelR force-pushed the feature/sdn_applier branch from 27267e2 to f6ce32e Compare August 22, 2025 12:23
@bpg
Copy link
Owner

bpg commented Aug 23, 2025

When destroying resources (terraform destroy) the configuration isn't applied as the applier resource is also destroyed... Thought about calling the client.ApplyConfig method in the provider's Delete method but as the applier depends_on (safer) the resources, he will be deleted before and therefore that won't ensure the latest apply.

Ah.. that's a good point, let me think about it...

@bpg
Copy link
Owner

bpg commented Aug 27, 2025

When destroying resources (terraform destroy) the configuration isn't applied as the applier resource is also destroyed... Thought about calling the client.ApplyConfig method in the provider's Delete method but as the applier depends_on (safer) the resources, he will be deleted before and therefore that won't ensure the latest apply.

Ah.. that's a good point, let me think about it...

We could probably introduce a "finalizer" resources, smth. like:

resource "proxmox_virtual_environment_sdn_finalizer" "cleanup" {
...
}

resource "proxmox_virtual_environment_sdn_zone_simple" "test_zone_1" {
  id = "tZone1"
  nodes = [data.proxmox_virtual_environment_nodes.example.names]
  
  depends_on = [proxmox_virtual_environment_sdn_finalizer.cleanup]
}

Copy link
Owner

@bpg bpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have some comments below. I also realized that we don't read the pending state of zones, so testing of the apply function in acceptance tests can't be done efficiently.

I'll work on changes to address all of this.

)

// ApplyConfig triggers a cluster-wide SDN apply via PUT /cluster/sdn.
// If the API returns a task UPID, it will be captured but ignored here.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably wait here for the task to complete

}

state := &model{
ID: types.StringValue(time.Now().UTC().Format(time.RFC3339)),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just use the unix timestamp in msec here

Comment on lines 90 to 97
var state model
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)

if resp.Diagnostics.HasError() {
return
}

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this code does anything 🤔

Comment on lines 123 to 131
func (r *Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
if req.ID == "" {
resp.Diagnostics.AddError("Invalid Import ID", "Expected a non-empty ID value.")
return
}

state := &model{ID: types.StringValue(req.ID)}
resp.Diagnostics.Append(resp.State.Set(ctx, state)...)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think import is needed for this resource

@bpg bpg changed the title feat: added custom resource to apply sdn configurations feat(sdn): added custom resource to apply sdn configurations Aug 30, 2025
@bpg
Copy link
Owner

bpg commented Aug 30, 2025

Well, this whole "pending" state is a bit of mess.

For example, after creating a new zone, but before applying it, the API returns the zone as:

{
    "data": {
        "state": "new",
        "zone": "zoneS",
        "pending": {
            "nodes": "pve",
            "mtu": 1496
        },
        "type": "simple",
        "digest": null
    }
}

then after applying:

{
    "data": {
        "mtu": 1496,
        "zone": "zoneS",
        "digest": null,
        "type": "simple",
        "nodes": "pve"
    }
}

bpg added 2 commits August 30, 2025 19:48
@bpg
Copy link
Owner

bpg commented Aug 30, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new experimental resource, proxmox_virtual_environment_sdn_applier, to trigger the application of SDN configurations. This is a valuable addition for managing SDN resources more effectively with Terraform. The changes also include updating existing SDN resources and data sources to expose pending and state information, which improves visibility into the configuration status. The implementation is solid, with comprehensive acceptance tests. I've found a minor inconsistency in the new resource's implementation and a couple of typos in the documentation, which I've detailed in the review comments.

bpg and others added 4 commits August 30, 2025 19:56
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Pavel Boldyrev <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Pavel Boldyrev <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Pavel Boldyrev <[email protected]>
Copy link
Owner

@bpg bpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, i think it is in a good shape now. Apply on zone create / update / delete works fine. So, LGTM! 🚀

@bpg bpg merged commit e13d7ef into bpg:main Aug 31, 2025
5 checks passed
@bpg bpg changed the title feat(sdn): added custom resource to apply sdn configurations feat(sdn): add custom resource to apply sdn_* configurations Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants