Use the hyperv_machine_instance data source
masterThe hyperv_machine_instance data source allows you to retrieve information about an existing Hyper-V virtual machine instance. This is useful for inspecting the configuration, state, or properties of a VM that was created outside of the current Terraform workspace or by a different resource.
terraform {
required_providers {
hyperv = {
source = "taliesins/hyperv"
version = ">= 1.0.3"
}
}
}
provider "hyperv" {}
# Example: Fetching an existing machine named 'WebServer'
data "hyperv_machine_instance" "default" {
name = "WebServer"
}
output "vm_details" {
value = data.hyperv_machine_instance.default
}