hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.02k stars 4.42k forks source link

provider_config disk options are ignored for Hyper-V #13279

Open afaonline opened 8 months ago

afaonline commented 8 months ago

Console output

vargrant up --provider hyperv

Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
Guest 'default' using provider 'hyperv' has provider specific config options for a provider other than 'hyperv'. These provider config options will be ignored for this guest

Expected behavior

I expect a Fixed primary disk to be created

Actual behavior

I tried to set "provider_config" for Hyper-V to make primary disk fixed, but it seems that Vagrant ignores the setting. Looks like it cannot extract the name of provider from disk configuration. I tried both ways to define the config:

  config.vm.disk :disk, size: "130GB", primary: true, provider_config: { "hyperv__Fixed" => true }

and

  config.vm.disk :disk, size: "130GB", primary: true, provider_config: { "hyperv" => {"Fixed" => true} }

In both cases I see "These provider config options will be ignored" in log, and disk is still Dynamic.

Vagrant version

Vagrant 2.4.0

Host operating system

Microsoft Hyper-V Server

Guest operating system

Windows 10

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "w10hyperv_rus"
  config.vm.box_version = "1.17"
  config.vm.communicator = "winrm"
  config.vm.disk :disk, size: "130GB", primary: true, provider_config: { "hyperv__Fixed" => true }
end
yshingai commented 5 months ago

vagrant/embedded/gems/gems/vagrant-2.4.0/plugins/kernel_v2/config/disk.rb に間違いがある There is a mistake in

--- /opt/vagrant/embedded/gems/gems/vagrant-2.4.0/plugins/kernel_v2/config/disk.rb  2023-10-17 01:58:26
+++ patch/disk.rb   2024-01-16 10:11:46
@@ -104,7 +104,7 @@

         current = @provider_config.merge(current) if !@provider_config.empty?
         if current
-          @provider_config = current
+          @provider_config = current[:provider_config]
         else
           @provider_config = {}
         end
samush commented 5 months ago

@yshingai thanks for your tip, also i was able to create hyperv vm with provider_config options after fixing args here: should be **

machine.provider.driver.create_disk(disk_file, disk_config.size, **disk_provider_config)
.....
machine.provider.driver.attach_disk(disk_file, **disk_provider_config)