taliesins / terraform-provider-hyperv

HyperV provider for Terraform
Mozilla Public License 2.0
233 stars 79 forks source link

Error: error uploading shell script: http response error: 401 - invalid content type #33

Closed xwing3 closed 3 years ago

xwing3 commented 3 years ago

Terraform Version 0.12.25

Affected Resource(s) Please list the resources as a list, for example:

hyperv_network_switch

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

# Configure HyperV
provider "hyperv" {
  user            = "Administrator"
  password        = "pass"
  host            = "10.0.0.97"
  port            = 5985
  https           = false
  insecure        = false
  use_ntlm        = true
  tls_server_name = ""
  cacert_path     = ""
  cert_path       = ""
  key_path        = ""
  script_path     = "C:/Temp/terraform_%RAND%.cmd"
  timeout         = "30s"
}

resource "hyperv_network_switch" "dmz_network_switch" {
  name = "dmz"
}

Debug Output

  Use TF_LOG=TRACE to see Terraform's internal logs.
  ----
2020/10/01 13:10:21 [INFO] Terraform version: 0.12.25  
2020/10/01 13:10:21 [INFO] Go runtime version: go1.12.13
2020/10/01 13:10:21 [INFO] CLI args: []string{"/usr/local/bin/terraform", "apply"}
2020/10/01 13:10:21 [DEBUG] Attempting to open CLI config file: /home/user/.terraformrc
2020/10/01 13:10:21 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/10/01 13:10:21 [INFO] CLI command args: []string{"apply"}
2020/10/01 13:10:21 [WARN] Log levels other than TRACE are currently unreliable, and are supported only for backward compatibility.
  Use TF_LOG=TRACE to see Terraform's internal logs.
  ----
2020/10/01 13:10:21 [DEBUG] New state was assigned lineage "1e096b02-2dc4-a83e-c3c5-c874d7f3348f"
2020/10/01 13:10:21 [DEBUG] checking for provider in "."
2020/10/01 13:10:21 [WARN] found legacy provider "terraform-provider-hyperv"
2020/10/01 13:10:21 [DEBUG] checking for provider in "/usr/local/bin"
2020/10/01 13:10:21 [DEBUG] checking for provider in ".terraform/plugins/linux_amd64"
2020/10/01 13:10:21 [DEBUG] found valid plugin: "hyperv", "0.0.0", "/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv"
2020/10/01 13:10:21 [DEBUG] checking for provisioner in "."
2020/10/01 13:10:21 [DEBUG] checking for provisioner in "/usr/local/bin"
2020/10/01 13:10:21 [DEBUG] checking for provisioner in ".terraform/plugins/linux_amd64"
2020/10/01 13:10:21 [INFO] backend/local: starting Apply operation
2020-10-01T13:10:21.272+0300 [INFO]  plugin: configuring client automatic mTLS
2020-10-01T13:10:21.314+0300 [DEBUG] plugin: starting plugin: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv args=[/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv]
2020-10-01T13:10:21.315+0300 [DEBUG] plugin: plugin started: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4665
2020-10-01T13:10:21.315+0300 [DEBUG] plugin: waiting for RPC address: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv
2020-10-01T13:10:21.327+0300 [INFO]  plugin.terraform-provider-hyperv: configuring server automatic mTLS: timestamp=2020-10-01T13:10:21.327+0300
2020-10-01T13:10:21.371+0300 [DEBUG] plugin: using plugin: version=5
2020-10-01T13:10:21.371+0300 [DEBUG] plugin.terraform-provider-hyperv: plugin address: address=/tmp/plugin460686566 network=unix timestamp=2020-10-01T13:10:21.371+0300
2020-10-01T13:10:21.467+0300 [DEBUG] plugin: plugin process exited: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4665
2020-10-01T13:10:21.467+0300 [DEBUG] plugin: plugin exited
2020/10/01 13:10:21 [INFO] terraform: building graph: GraphTypeValidate
2020/10/01 13:10:21 [DEBUG] ProviderTransformer: "hyperv_network_switch.dmz_network_switch" (*terraform.NodeValidatableResource) needs provider.hyperv
2020/10/01 13:10:21 [DEBUG] ReferenceTransformer: "hyperv_network_switch.dmz_network_switch" references: []
2020/10/01 13:10:21 [DEBUG] ReferenceTransformer: "provider.hyperv" references: []
2020/10/01 13:10:21 [DEBUG] Starting graph walk: walkValidate
2020-10-01T13:10:21.469+0300 [INFO]  plugin: configuring client automatic mTLS
2020-10-01T13:10:21.510+0300 [DEBUG] plugin: starting plugin: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv args=[/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv]
2020-10-01T13:10:21.511+0300 [DEBUG] plugin: plugin started: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4690
2020-10-01T13:10:21.511+0300 [DEBUG] plugin: waiting for RPC address: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv
2020-10-01T13:10:21.524+0300 [INFO]  plugin.terraform-provider-hyperv: configuring server automatic mTLS: timestamp=2020-10-01T13:10:21.524+0300
2020-10-01T13:10:21.567+0300 [DEBUG] plugin.terraform-provider-hyperv: plugin address: network=unix address=/tmp/plugin692826279 timestamp=2020-10-01T13:10:21.567+0300
2020-10-01T13:10:21.567+0300 [DEBUG] plugin: using plugin: version=5
2020-10-01T13:10:21.652+0300 [DEBUG] plugin: plugin process exited: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4690
2020-10-01T13:10:21.652+0300 [DEBUG] plugin: plugin exited
2020/10/01 13:10:21 [INFO] backend/local: apply calling Refresh
2020/10/01 13:10:21 [INFO] terraform: building graph: GraphTypeRefresh
2020/10/01 13:10:21 [DEBUG] pruning unused provider.hyperv
2020/10/01 13:10:21 [DEBUG] Starting graph walk: walkRefresh
2020/10/01 13:10:21 [INFO] backend/local: apply calling Plan
2020/10/01 13:10:21 [INFO] terraform: building graph: GraphTypePlan
2020/10/01 13:10:21 [DEBUG] ProviderTransformer: "hyperv_network_switch.dmz_network_switch" (*terraform.NodePlannableResource) needs provider.hyperv
2020/10/01 13:10:21 [DEBUG] ReferenceTransformer: "hyperv_network_switch.dmz_network_switch" references: []
2020/10/01 13:10:21 [DEBUG] ReferenceTransformer: "provider.hyperv" references: []
2020/10/01 13:10:21 [DEBUG] Starting graph walk: walkPlan
2020-10-01T13:10:21.654+0300 [INFO]  plugin: configuring client automatic mTLS
2020-10-01T13:10:21.694+0300 [DEBUG] plugin: starting plugin: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv args=[/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv]
2020-10-01T13:10:21.694+0300 [DEBUG] plugin: plugin started: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4699
2020-10-01T13:10:21.694+0300 [DEBUG] plugin: waiting for RPC address: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv
2020-10-01T13:10:21.705+0300 [INFO]  plugin.terraform-provider-hyperv: configuring server automatic mTLS: timestamp=2020-10-01T13:10:21.704+0300
2020-10-01T13:10:21.748+0300 [DEBUG] plugin.terraform-provider-hyperv: plugin address: address=/tmp/plugin609953007 network=unix timestamp=2020-10-01T13:10:21.748+0300
2020-10-01T13:10:21.748+0300 [DEBUG] plugin: using plugin: version=5
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv: 2020/10/01 13:10:21 [INFO][hyperv] HyperV HypervClient configured for HyperV API operations using:
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Host: 10.0.0.97
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Port: 5985
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   User: Administator
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Password: true
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   HTTPS: false
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Insecure: false
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   NTLM: true
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   TLSServerName: 
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   CACert: false
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Cert: false
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Key: false
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   ScriptPath: C:/Temp/terraform_%RAND%.cmd
2020-10-01T13:10:21.864+0300 [DEBUG] plugin.terraform-provider-hyperv:   Timeout: 30s
2020/10/01 13:10:21 [DEBUG] Resource instance state not found for node "hyperv_network_switch.dmz_network_switch", instance hyperv_network_switch.dmz_network_switch
2020/10/01 13:10:21 [DEBUG] ReferenceTransformer: "hyperv_network_switch.dmz_network_switch" references: []
2020/10/01 13:10:21 [WARN] Provider "registry.terraform.io/-/hyperv" produced an invalid plan for hyperv_network_switch.dmz_network_switch, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .default_queue_vmmq_enabled: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .enable_embedded_teaming: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .enable_iov: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .default_flow_minimum_bandwidth_absolute: planned value cty.NumberIntVal(0) does not match config value cty.NullVal(cty.Number)
      - .default_queue_vrss_enabled: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .switch_type: planned value cty.StringVal("Internal") does not match config value cty.NullVal(cty.String)
      - .allow_management_os: planned value cty.True does not match config value cty.NullVal(cty.Bool)
      - .default_flow_minimum_bandwidth_weight: planned value cty.NumberIntVal(0) does not match config value cty.NullVal(cty.Number)
      - .enable_packet_direct: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .default_queue_vmmq_queue_pairs: planned value cty.NumberIntVal(16) does not match config value cty.NullVal(cty.Number)
      - .minimum_bandwidth_mode: planned value cty.StringVal("None") does not match config value cty.NullVal(cty.String)
2020-10-01T13:10:21.874+0300 [DEBUG] plugin: plugin process exited: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4699
2020-10-01T13:10:21.874+0300 [DEBUG] plugin: plugin exited

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # hyperv_network_switch.dmz_network_switch will be created
  + resource "hyperv_network_switch" "dmz_network_switch" {
2020/10/01 13:10:21 [DEBUG] command: asking for input: "Do you want to perform these actions?"
      + allow_management_os                     = true
      + default_flow_minimum_bandwidth_absolute = 0
      + default_flow_minimum_bandwidth_weight   = 0
      + default_queue_vmmq_enabled              = false
      + default_queue_vmmq_queue_pairs          = 16
      + default_queue_vrss_enabled              = false
      + enable_embedded_teaming                 = false
      + enable_iov                              = false
      + enable_packet_direct                    = false
      + id                                      = (known after apply)
      + minimum_bandwidth_mode                  = "None"
      + name                                    = "dmz"
      + switch_type                             = "Internal"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

2020/10/01 13:10:23 [INFO] backend/local: apply calling Apply
2020/10/01 13:10:23 [INFO] terraform: building graph: GraphTypeApply
2020/10/01 13:10:23 [DEBUG] Resource state not found for node "hyperv_network_switch.dmz_network_switch", instance hyperv_network_switch.dmz_network_switch
2020/10/01 13:10:23 [DEBUG] ProviderTransformer: "hyperv_network_switch.dmz_network_switch (prepare state)" (*terraform.NodeApplyableResource) needs provider.hyperv
2020/10/01 13:10:23 [DEBUG] ProviderTransformer: "hyperv_network_switch.dmz_network_switch" (*terraform.NodeApplyableResourceInstance) needs provider.hyperv
2020/10/01 13:10:23 [DEBUG] ReferenceTransformer: "hyperv_network_switch.dmz_network_switch (prepare state)" references: []
2020/10/01 13:10:23 [DEBUG] ReferenceTransformer: "hyperv_network_switch.dmz_network_switch" references: []
2020/10/01 13:10:23 [DEBUG] ReferenceTransformer: "provider.hyperv" references: []
2020/10/01 13:10:23 [DEBUG] Starting graph walk: walkApply
2020-10-01T13:10:23.370+0300 [INFO]  plugin: configuring client automatic mTLS
2020-10-01T13:10:23.423+0300 [DEBUG] plugin: starting plugin: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv args=[/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv]
2020-10-01T13:10:23.423+0300 [DEBUG] plugin: plugin started: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4711
2020-10-01T13:10:23.424+0300 [DEBUG] plugin: waiting for RPC address: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv
2020-10-01T13:10:23.435+0300 [INFO]  plugin.terraform-provider-hyperv: configuring server automatic mTLS: timestamp=2020-10-01T13:10:23.434+0300
2020-10-01T13:10:23.476+0300 [DEBUG] plugin.terraform-provider-hyperv: plugin address: address=/tmp/plugin032592918 network=unix timestamp=2020-10-01T13:10:23.476+0300
2020-10-01T13:10:23.476+0300 [DEBUG] plugin: using plugin: version=5
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv: 2020/10/01 13:10:23 [INFO][hyperv] HyperV HypervClient configured for HyperV API operations using:
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Host: 10.0.0.97
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Port: 5985
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   User: Administator
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Password: true
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   HTTPS: false
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Insecure: false
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   NTLM: true
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   TLSServerName: 
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   CACert: false
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Cert: false
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Key: false
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   ScriptPath: C:/Temp/terraform_%RAND%.cmd
2020-10-01T13:10:23.571+0300 [DEBUG] plugin.terraform-provider-hyperv:   Timeout: 30s
2020/10/01 13:10:23 [WARN] Provider "registry.terraform.io/-/hyperv" produced an invalid plan for hyperv_network_switch.dmz_network_switch, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .default_flow_minimum_bandwidth_weight: planned value cty.NumberIntVal(0) does not match config value cty.NullVal(cty.Number)
      - .enable_packet_direct: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .allow_management_os: planned value cty.True does not match config value cty.NullVal(cty.Bool)
      - .minimum_bandwidth_mode: planned value cty.StringVal("None") does not match config value cty.NullVal(cty.String)
      - .default_queue_vmmq_queue_pairs: planned value cty.NumberIntVal(16) does not match config value cty.NullVal(cty.Number)
      - .enable_embedded_teaming: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .enable_iov: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .default_queue_vmmq_enabled: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .default_queue_vrss_enabled: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .switch_type: planned value cty.StringVal("Internal") does not match config value cty.NullVal(cty.String)
      - .default_flow_minimum_bandwidth_absolute: planned value cty.NumberIntVal(0) does not match config value cty.NullVal(cty.Number)
hyperv_network_switch.dmz_network_switch: Creating...
2020/10/01 13:10:23 [DEBUG] hyperv_network_switch.dmz_network_switch: applying the planned Create change
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 2020/10/01 13:10:23 [INFO][hyperv][create] creating hyperv switch: &schema.ResourceData{schema:map[string]*schema.Schema{"allow_management_os":(*schema.Schema)(0xc0002ca640), "default_flow_minimum_bandwidth_absolute":(*schema.Schema)(0xc0002cb040), "default_flow_minimum_bandwidth_weight":(*schema.Schema)(0xc0002cb180), "default_queue_vmmq_enabled":(*schema.Schema)(0xc0002cb2c0), "default_queue_vmmq_queue_pairs":(*schema.Schema)(0xc0002cb400), "default_queue_vrss_enabled":(*schema.Schema)(0xc0002cb540), "enable_embedded_teaming":(*schema.Schema)(0xc0002ca780), "enable_iov":(*schema.Schema)(0xc0002ca8c0), "enable_packet_direct":(*schema.Schema)(0xc0002caa00), "minimum_bandwidth_mode":(*schema.Schema)(0xc0002cab40), "name":(*schema.Schema)(0xc0002ca3c0), "net_adapter_names":(*schema.Schema)(0xc0002caf00), "notes":(*schema.Schema)(0xc0002ca500), "switch_type":(*schema.Schema)(0xc0002cac80)}, config:(*terraform.ResourceConfig)(nil), state:(*terraform.InstanceState)(0xc0003d8460), diff:(*terraform.InstanceDiff)(0xc000578f80), meta:map[string]interface {}(nil), timeouts:(*schema.ResourceTimeout)(0xc000711bc0), providerMeta:cty.Value{ty:cty.Type{typeImpl:cty.typeImpl(nil)}, v:interface {}(nil)}, multiReader:(*schema.MultiLevelFieldReader)(nil), setWriter:(*schema.MapFieldWriter)(nil), newState:(*terraform.InstanceState)(nil), partial:false, once:sync.Once{done:0x0, m:sync.Mutex{state:0, sema:0x0}}, isNew:true, panicOnError:false}
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 2020/10/01 13:10:23 [DEBUG] Running fire and forget script:
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $ErrorActionPreference = 'Stop'
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: Import-Module Hyper-V
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $vmSwitch = '{"Name":"dmz","Notes":"","AllowManagementOS":true,"EmbeddedTeamingEnabled":false,"IovEnabled":false,"PacketDirectEnabled":false,"BandwidthReservationMode":3,"SwitchType":1,"NetAdapterNames":[],"DefaultFlowMinimumBandwidthAbsolute":0,"DefaultFlowMinimumBandwidthWeight":0,"DefaultQueueVmmqEnabled":false,"DefaultQueueVmmqQueuePairs":16,"DefaultQueueVrssEnabled":false}' | ConvertFrom-Json
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $minimumBandwidthMode = [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]$vmSwitch.BandwidthReservationMode
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $switchType = [Microsoft.HyperV.PowerShell.VMSwitchType]$vmSwitch.SwitchType
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NetAdapterNames = @($vmSwitch.NetAdapterNames)
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: #when EnablePacketDirect=true it seems to throw an exception if EnableIov=true or EnableEmbeddedTeaming=true
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $switchObject = Get-VMSwitch -Name "$($vmSwitch.Name)*" | ?{$_.Name -eq $vmSwitch.Name}
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: if ($switchObject){
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  throw "Switch already exists - $($vmSwitch.Name)"
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: }
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NewVmSwitchArgs = @{}
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NewVmSwitchArgs.Name=$vmSwitch.Name
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NewVmSwitchArgs.MinimumBandwidthMode=$minimumBandwidthMode
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NewVmSwitchArgs.EnableEmbeddedTeaming=$vmSwitch.EmbeddedTeamingEnabled
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NewVmSwitchArgs.EnableIov=$vmSwitch.IovEnabled
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $NewVmSwitchArgs.EnablePacketDirect=$vmSwitch.PacketDirectEnabled
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: if ($NetAdapterNames) {
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  $NewVmSwitchArgs.AllowManagementOS=$vmSwitch.AllowManagementOS
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  $NewVmSwitchArgs.NetAdapterName=$NetAdapterNames
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: } else {
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  $NewVmSwitchArgs.SwitchType=$switchType
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  #not used unless interface is specified
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  #-AllowManagementOS $vmSwitch.AllowManagementOS
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: }
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: New-VMSwitch @NewVmSwitchArgs
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $switchObject = Get-VMSwitch -Name "$($vmSwitch.Name)" | ?{$_.Name -eq $vmSwitch.Name}
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: if (!$switchObject){
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  throw "Switch does not exist - $($vmSwitch.Name)"
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: }
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $SetVmSwitchArgs = @{}
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $SetVmSwitchArgs.Name=$vmSwitch.Name
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $SetVmSwitchArgs.Notes=$vmSwitch.Notes
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: if (($minimumBandwidthMode -eq [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]::Absolute) -and $switchObject.DefaultFlowMinimumBandwidthAbsolute -ne $vmSwitch.DefaultFlowMinimumBandwidthAbsolute) {
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  $SetVmSwitchArgs.DefaultFlowMinimumBandwidthAbsolute=$vmSwitch.DefaultFlowMinimumBandwidthAbsolute
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: }
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: if ((($minimumBandwidthMode -eq [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]::Weight) -or (($minimumBandwidthMode -eq [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]::Default) -and (-not ($vmSwitch.IovEnabled)))) -and $switchObject.DefaultFlowMinimumBandwidthWeight -ne $vmSwitch.DefaultFlowMinimumBandwidthWeight) {
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv:  $SetVmSwitchArgs.DefaultFlowMinimumBandwidthWeight=$vmSwitch.DefaultFlowMinimumBandwidthWeight
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: }
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $SetVmSwitchArgs.DefaultQueueVmmqEnabled=$vmSwitch.DefaultQueueVmmqEnabled
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $SetVmSwitchArgs.DefaultQueueVmmqQueuePairs=$vmSwitch.DefaultQueueVmmqQueuePairs
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: $SetVmSwitchArgs.DefaultQueueVrssEnabled=$vmSwitch.DefaultQueueVrssEnabled
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: Set-VMSwitch @SetVmSwitchArgs
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 
2020-10-01T13:10:23.575+0300 [DEBUG] plugin.terraform-provider-hyperv: 2020/10/01 13:10:23 [DEBUG] Uploading shell wrapper for command from [/tmp/shell-terraform-1iGw1pVq8Nol0AbCYzJlykmjlqh.ps1756890237] to [$env:TEMP\shell-terraform-1iGw1pVq8Nol0AbCYzJlykmjlqh.ps1] 
2020/10/01 13:10:24 [DEBUG] hyperv_network_switch.dmz_network_switch: apply errored, but we're indicating that via the Error pointer rather than returning it: error uploading shell script: http response error: 401 - invalid content type
2020/10/01 13:10:24 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: error uploading shell script: http response error: 401 - invalid content type
2020/10/01 13:10:24 [ERROR] <root>: eval: *terraform.EvalSequence, err: error uploading shell script: http response error: 401 - invalid content type

Error: error uploading shell script: http response error: 401 - invalid content type

2020-10-01T13:10:24.364+0300 [DEBUG] plugin: plugin process exited: path=/home/user/Desktop/terraform-hyperv/terraform-provider-hyperv pid=4711
2020-10-01T13:10:24.364+0300 [DEBUG] plugin: plugin exited 

Server winrm config output


Config
    MaxEnvelopeSizekb = 500
    MaxTimeoutms = 1800000
    MaxBatchItems = 32000
    MaxProviderRequests = 4294967295
    Client
        NetworkDelayms = 5000
        URLPrefix = wsman
        AllowUnencrypted = true
        Auth
            Basic = true
            Digest = true
            Kerberos = true
            Negotiate = true
            Certificate = false
            CredSSP = false
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        TrustedHosts = *
    Service
        RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
        MaxConcurrentOperations = 4294967295
        MaxConcurrentOperationsPerUser = 1500
        EnumerationTimeoutms = 240000
        MaxConnections = 300
        MaxPacketRetrievalTimeSeconds = 120
        AllowUnencrypted = true
        Auth
            Basic = true
            Kerberos = true
            Negotiate = true
            Certificate = false
            CredSSP = false
            CbtHardeningLevel = Relaxed
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        IPv4Filter = *
        IPv6Filter = *
        EnableCompatibilityHttpListener = false
        EnableCompatibilityHttpsListener = false
        CertificateThumbprint
        AllowRemoteAccess = true
    Winrs
        AllowRemoteShellAccess = true
        IdleTimeout = 7200000
        MaxConcurrentUsers = 2147483647
        MaxShellRunTime = 2147483647
        MaxProcessesPerShell = 2147483647
        MaxMemoryPerShellMB = 1024
        MaxShellsPerUser = 2147483647```
xwing3 commented 3 years ago

I have tried executing the script generated by the provider with pywinrm and it works, above error still occurs when using terraform, code below:

import winrm

ps_script = """$ErrorActionPreference = 'Stop'
Get-Vm | Out-Null
$vmSwitch = '{"Name":"dmx","Notes":"","AllowManagementOS":true,"EmbeddedTeamingEnabled":false,"IovEnabled":false,"PacketDirectEnabled":false,"BandwidthReservationMode":3,"SwitchType":1,"NetAdapterNames":[],"DefaultFlowMinimumBandwidthAbsolute":0,"DefaultFlowMinimumBandwidthWeight":0,"DefaultQueueVmmqEnabled":false,"DefaultQueueVmmqQueuePairs":16,"DefaultQueueVrssEnabled":false}' | ConvertFrom-Json
$minimumBandwidthMode = [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]$vmSwitch.BandwidthReservationMode
$switchType = [Microsoft.HyperV.PowerShell.VMSwitchType]$vmSwitch.SwitchType
$NetAdapterNames = @($vmSwitch.NetAdapterNames)
#when EnablePacketDirect=true it seems to throw an exception if EnableIov=true or EnableEmbeddedTeaming=true

$switchObject = Get-VMSwitch | ?{$_.Name -eq $vmSwitch.Name}

if ($switchObject){
throw "Switch already exists - $($vmSwitch.Name)"
}

$NewVmSwitchArgs = @{}
$NewVmSwitchArgs.Name=$vmSwitch.Name
$NewVmSwitchArgs.MinimumBandwidthMode=$minimumBandwidthMode
$NewVmSwitchArgs.EnableEmbeddedTeaming=$vmSwitch.EmbeddedTeamingEnabled
$NewVmSwitchArgs.EnableIov=$vmSwitch.IovEnabled
$NewVmSwitchArgs.EnablePacketDirect=$vmSwitch.PacketDirectEnabled

if ($NetAdapterNames) {
$NewVmSwitchArgs.AllowManagementOS=$vmSwitch.AllowManagementOS
$NewVmSwitchArgs.NetAdapterName=$NetAdapterNames
} else {
$NewVmSwitchArgs.SwitchType=$switchType
#not used unless interface is specified
#-AllowManagementOS $vmSwitch.AllowManagementOS
}
New-VMSwitch @NewVmSwitchArgs

$switchObject = Get-VMSwitch | ?{$_.Name -eq $vmSwitch.Name}

if (!$switchObject){
throw "Switch does not exist - $($vmSwitch.Name)"
}

$SetVmSwitchArgs = @{}
$SetVmSwitchArgs.Name=$vmSwitch.Name
$SetVmSwitchArgs.Notes=$vmSwitch.Notes
if (($minimumBandwidthMode -eq [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]::Absolute) -and $switchObject.DefaultFlowMinimumBandwidthAbsolute -ne $vmSwitch.DefaultFlowMinimumBandwidthAbsolute) {
$SetVmSwitchArgs.DefaultFlowMinimumBandwidthAbsolute=$vmSwitch.DefaultFlowMinimumBandwidthAbsolute
}
if ((($minimumBandwidthMode -eq [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]::Weight) -or (($minimumBandwidthMode -eq [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode]::Default) -and (-not ($vmSwitch.IovEnabled)))) -and $switchObject.DefaultFlowMinimumBandwidthWeight -ne $vmSwitch.DefaultFlowMinimumBandwidthWeight) {
$SetVmSwitchArgs.DefaultFlowMinimumBandwidthWeight=$vmSwitch.DefaultFlowMinimumBandwidthWeight
}
$SetVmSwitchArgs.DefaultQueueVmmqEnabled=$vmSwitch.DefaultQueueVmmqEnabled
$SetVmSwitchArgs.DefaultQueueVmmqQueuePairs=$vmSwitch.DefaultQueueVmmqQueuePairs
$SetVmSwitchArgs.DefaultQueueVrssEnabled=$vmSwitch.DefaultQueueVrssEnabled

Set-VMSwitch @SetVmSwitchArgs """

s = winrm.Session('http://10.0.0.97:5985/wsman', auth=('Administrator', 'pass'))
r = s.run_ps(ps_script)
print(r)