taliesins / terraform-provider-hyperv

HyperV provider for Terraform
Mozilla Public License 2.0
234 stars 80 forks source link

Errors when using a .zip as the source for a new hyperv-vhd resource #209

Closed chazragg closed 8 months ago

chazragg commented 11 months ago

Hey, I am currently using Packer with the hyper-v build to produce a base rocky-9 image along with the compression post-process to produce a .zip of the artifact. I am then trying to use this .zip as the source for my VHD in Terraform but I am constantly met with errors. any help will be appreciated

Terraform Version

Terraform v1.5.7 on linux_amd64

Affected Resource(s)

Terraform Configuration Files

resource "hyperv_vhd" "base-os" {
  source = "D:\\Projects\\Infrastructure\\packer\\Rocky-linux-9.2\\Virtual Hard Disks.zip"
  path   = "D:\\hyper-v\\rocky\\"

}

Expected Behavior

The zip should be extracted into the directory portion of the path

Actual Behavior

i get the following error

Get-VHD : 'D:\hyper-v\rocky' is not an existing virtual hard disk file.
At C:\Users\chaz_\AppData\Local\Temp\shell-terraform-2XmLLK3GNqwEEu8LpuuzZlX20jw.ps1:7 char:15
+     $vhdObject = Get-VHD -path $path | %{ @{
+                  ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-VHD], VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.Vhd.PowerShell.Cmdlets.GetVHD
╷
│ Error: run command operation returned code=1
│ stderr:
│ 
│ stdOut:
│ Get-VHD : 'D:\hyper-v\rocky' is not an existing virtual hard disk file.
│ At C:\Users\chaz_\AppData\Local\Temp\shell-terraform-2XmLLK3GNqwEEu8LpuuzZlX20jw.ps1:7 char:15
│ +     $vhdObject = Get-VHD -path $path | %{ @{
│ +                  ~~~~~~~~~~~~~~~~~~~
│     + CategoryInfo          : InvalidArgument: (:) [Get-VHD], VirtualizationException
│     + FullyQualifiedErrorId : InvalidParameter,Microsoft.Vhd.PowerShell.Cmdlets.GetVHD
│ 
│   with hyperv_vhd.base-os,
│   on main.tf line 25, in resource "hyperv_vhd" "base-os":
│   25: resource "hyperv_vhd" "base-os" {
│ 
╵

Steps to Reproduce

  1. terraform apply

Important Factoids

1) i had to modify the packer compress output as it seems to place the Virtual Hard Disk and Virtual Machine inside another folder within the zip, my modification was simply moving these folders to the root otherwise nothing extracts correct. Maybe this could be a feature request to make it inline with Packer?

Packer Compressed output image

Modified Output image

2) with the modified zip I am able to see the extracted Virtual Hard Disk folder in the correct path but then it seems to fail accessing the directory as if it is the VHDX file. if I add a filename to the end of the path D:\\hyper-v\\rocky\\rocky-linux-9.vhdx it does not seem to extract it correctly and instead, the .vhdx file is just a direct copy of everything inside the zip i.e. both the Virtual Hard Disk and Virtual Machine folders

With "D:\\hyper-v\\rocky\\" as the path image

With "D:\\hyper-v\\rocky\\rocky-linux-9.vhdx" as the path image

taliesins commented 8 months ago

Should be fixed by #236