feat: add datasource for virtual machines#498
Conversation
|
Thanks @castorsky. I’ll review this week. |
|
I'll pick this one up from Lucas. For now, I've placed this into the v2.1.0 milestone so that we can release v2.0.0 items that have breaking changes first. |
4dc2048 to
b62df9c
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR implements a new vSphere virtual machine data source that searches for VMs in a vSphere cluster based on various filters and returns the name of a single matching virtual machine. The data source is designed to integrate with the vSphere Clone builder by providing a straightforward way to select templates without requiring users to manipulate lists in locals.
Key changes:
- Added a new virtual machine data source with comprehensive filtering capabilities
- Implemented test coverage using vSphere simulator
- Added complete documentation and examples
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| main.go | Registers the new virtual machine data source |
| datasource/virtualmachine/data.go | Core data source implementation with configuration and execution logic |
| datasource/virtualmachine/filters.go | Filtering functions for name, regex, template, host, and tag matching |
| datasource/virtualmachine/data_test.go | Comprehensive test suite using vSphere simulator |
| datasource/common/driver/driver.go | Shared vCenter connection driver for data sources |
| datasource/common/testing/ | Testing utilities for vSphere simulator setup |
| docs/ | Documentation files and partials for the new data source |
| .web-docs/ | Web documentation components and metadata |
| builder/vsphere/driver/vm.go | Removed unnecessary blank line |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
docs-partials/datasource/virtualmachine/Config-not-required.mdx
Outdated
Show resolved
Hide resolved
7e725a5 to
9cbac1d
Compare
|
Hi @castorsky 👋🏻 - Apologies for the long delay! I've picked this one back up (finally). I've squashed the previous commits and have added a follow-up commit that refactors the implementation and unifies the driver usage. More updates to come! Ryan Johnson, VMware by Broadcom |
26a5edf to
eeaccac
Compare
Signed-off-by: Castor Sky <csky57@gmail.com>
343b11c to
388878a
Compare
Refactors the implementation and unifies the driver usage. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
388878a to
d5d1e04
Compare
tenthirtyam
left a comment
There was a problem hiding this comment.
LGTM 🥳
I've performed end-to-end testing using the examples below:
Filter by Tags and Get Latest
data "vsphere-virtualmachine" "example" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc01"
latest = true
tag {
category = "color"
name = "blue"
}
tag {
category = "shape"
name = "circle"
}
}
locals {
vm_name = data.vsphere-virtualmachine.example.vm_name
}
source "null" "example" {
communicator = "none"
}
build {
sources = [
"source.null.example"
]
provisioner "shell-local" {
inline = [
"echo vm_name: ${local.vm_name}",
]
}
}Filter by Name with Glob Pattern
data "vsphere-virtualmachine" "example" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc01"
name = "linux-debian-13-*"
latest = true
}
locals {
vm_result = data.vsphere-virtualmachine.example.vm_name
}
source "null" "example" {
communicator = "none"
}
build {
sources = [
"source.null.example"
]
provisioner "shell-local" {
inline = [
"echo vm_name: ${local.vm_result}",
]
}
}Filter by Name with Regular Expression
data "vsphere-virtualmachine" "example" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc01"
name_regex = "^linux-debian-[0-9]+-.+$"
latest = true
}
locals {
vm_result = data.vsphere-virtualmachine.example.vm_name
}Filter for VM Templates Only
data "vsphere-virtualmachine" "example" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc01"
name = "linux-debian-13-*"
template = true
}
locals {
vm_result = data.vsphere-virtualmachine.example.vm_name
}
source "null" "example" {
communicator = "none"
}
build {
sources = [
"source.null.example"
]
provisioner "shell-local" {
inline = [
"echo vm_name: ${local.vm_result}",
]
}
}Filter by ESX Host
data "vsphere-virtualmachine" "example" {
vcenter_server = "vc01.example.com"
username = "administrator@vsphere.local"
password = "VMware1!"
datacenter = "dc01"
host = "esxi-01.example.com"
name = "linux-debian-13-*"
latest = true
}
locals {
vm_result = data.vsphere-virtualmachine.example.vm_name
}
source "null" "example" {
communicator = "none"
}
build {
sources = [
"source.null.example"
]
provisioner "shell-local" {
inline = [
"echo vm_name: ${local.vm_result}",
]
}
}|
Now pending approval and merge by @kp2099. |
|
I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
I have implemented one of datasources which was requested in #196.
This datasource searches the vSphere cluster for some VMs that matches specified filters and returns VM name for one (and only one) machine. I have chosen such behavior because it will be straightforward for vsphere-clone builder - there will be no need for user to manipulate lists in locals.
I have included some tests and documentation for datasource.
By strange coincidence issues for vSphere and Proxmox datasources share the same ID. =)
Partially closes #196