taliesins / terraform-provider-hyperv

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

fix: Enable switch rename #239

Closed taliesins closed 6 months ago

taliesins commented 6 months ago

Allow switch to be renamed

taliesins commented 6 months ago

@MarkusRannare not sure why you included these checks. Perhaps you can tell me how to reproduce problem. I suspect its a particular combination that is preventing a change to an attribute.

    if len(netAdapterNames) > 1 {
        return fmt.Errorf("[ERROR][hyperv] Can't update a switch with multiple net adapaters names (%v)", netAdapterNames)
    }
if ($vmSwitch.NetAdapterNames.length -gt 0) {
    $NetAdapterNames = [string]$vmSwitch.NetAdapterNames[0]
}

I ran into this problem with some attributes and I added this (is there another attribute we need here):

if ($NetAdapterNames) {
    $SetVmSwitchArgs.AllowManagementOS=$vmSwitch.AllowManagementOS
    $SetVmSwitchArgs.NetAdapterName=$NetAdapterNames
    #Updates not supported on:
    #-EnableEmbeddedTeaming $vmSwitch.EmbeddedTeamingEnabled
    #-EnableIov $vmSwitch.IovEnabled
    #-EnablePacketDirect $vmSwitch.PacketDirectEnabled
    #-MinimumBandwidthMode $minimumBandwidthMode
} else {
    $SetVmSwitchArgs.SwitchType=$switchType
    #Updates not supported on:
    #-EnableEmbeddedTeaming $vmSwitch.EmbeddedTeamingEnabled
    #-EnableIov $vmSwitch.IovEnabled
    #-EnablePacketDirect $vmSwitch.PacketDirectEnabled
    #-MinimumBandwidthMode $minimumBandwidthMode

    #not used unless interface is specified
    #-AllowManagementOS $vmSwitch.AllowManagementOS
}