Search code examples
apiterraformhttp-status-code-401winrmhypervisor

How can I change the Authentication method in connections between WinRm and Terraform with hyperv provider?


I'm trying to use an hyperv provider for create some virtual machines but I need to define some parameters for the HyperV API. The problem is that WinRm (that is the tool that try to connect with the host) can't access with my credentials using the Basic Auth. However, If I use the Negotiate Auth, it returns a successfully connection. So, I don't know how can I define a parameter in Terraform for that. Here is my provider config's code in Terraform:

provider "hyperv" {
  user     = myusername
  password = mypassword
  host     = myhost
  port     = 5985
  https    = false
  insecure = true
  timeout  = "60s"
}

My winrm/config/client:

NetworkDelayms = 5000
    URLPrefix = wsman
    AllowUnencrypted = true
    Auth
        Basic = true
        Digest = true
        Kerberos = true
        Negotiate = true
        Certificate = true
        CredSSP = true
    DefaultPorts
        HTTP = 5985
        HTTPS = 5986
    TrustedHosts = *

My winrm/config/service:

MaxConcurrentOperations = 4294967295
MaxConcurrentOperationsPerUser = 1500
EnumerationTimeoutms = 240000
MaxConnections = 300
MaxPacketRetrievalTimeSeconds = 120
AllowUnencrypted = true
Auth
    Basic = true
    Kerberos = true
    Negotiate = true
    Certificate = true
    CredSSP = true
    CbtHardeningLevel = Relaxed
DefaultPorts
    HTTP = 5985
    HTTPS = 5986
IPv4Filter = *
IPv6Filter = *
EnableCompatibilityHttpListener = true
EnableCompatibilityHttpsListener = true
CertificateThumbprint
AllowRemoteAccess = true

Solution

  • Hy again guys. If someone have the same problem I resolve it on that way:

    -I activate Administrador user from Local users.

    -Then, one have to run this command in a CMD:

    reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
    

    -Reboot the system

    -Then, run winrm quickconfig in a CMD, and then it would work.

    I hope it help you!