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.

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.

1 participant