Skip to content

Conversation

@khmarochos
Copy link

Summary

Add support for custom port configuration in VNC graphics for libvirt domains. This feature allows users to specify a fixed port number for VNC connections instead of relying on automatic port assignment.

Changes

  • Add port parameter to graphics schema: Optional string parameter with numeric validation
  • Implement validation constraints: Port parameter can only be used with VNC graphics type and requires autoport = false
  • Update domain XML generation: Properly handles port configuration in libvirt XML, defaults to -1 when not specified
  • Add comprehensive tests: Covers both successful configuration and validation error cases

Usage Example

resource "libvirt_domain" "example" {
  name = "example-domain"
  graphics {
    type     = "vnc"
    autoport = false
    port     = "5900"
  }
}

Validation Rules

  • Port parameter is only valid when type = "vnc"
  • When port is specified, autoport must be false
  • Port value must be a valid numeric string
  • Configuration errors provide clear validation messages

Test Coverage

  • TestAccLibvirtDomain_GraphicsVNCPort: Tests successful VNC port configuration
  • TestAccLibvirtDomain_GraphicsVNCPortValidation: Tests validation scenarios including invalid type, autoport conflicts, and non-numeric values

Backward Compatibility

This change is fully backward compatible. Existing configurations continue to work unchanged, and the new port parameter is optional.

Kobzar added 2 commits July 9, 2025 11:00
Add support for custom port configuration in graphics blocks when using VNC type. The port parameter is validated to ensure it's only used with VNC graphics type and requires autoport to be false. When specified, the port value is set in the domain XML configuration, otherwise defaults to -1.

- Add port parameter to graphics schema with numeric validation
- Add CustomizeDiff validation for port parameter constraints
- Update setGraphics function to handle port configuration for VNC
- Add comprehensive tests for port functionality and validation
@khmarochos
Copy link
Author

The related feature request is #1182.

@dmacvicar dmacvicar changed the base branch from main to v0.8 November 8, 2025 00:12
@dmacvicar
Copy link
Owner

ℹ️ ℹ️ ℹ️ ℹ️ ℹ️ ℹ️

This contribution is relevant to the legacy version of the provider, which is now in the v0.8 branch of this repository.

Future development is based on a new provider, which is not compatible with this one, nor does share code.

As the new provider solves many issues with the legacy, and to make development in my free time more enjoyable, I have decided to close all PRs for the legacy provider, and to ask to check if the contribution would apply to the new one. This also to encourage trying the new version.

and check the documentation:

You are free to reopen the PR for v0.8, which is targetted now to the v0.8 branch. We may also start a discussion if we can assemble a team of maintainters for the legacy branch. My efforts will go into the new provider.

I ask you to check the new provider and re-evaluate this contribution. 🙏

@dmacvicar dmacvicar closed this Nov 8, 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