diff --git a/communicator/winrm/provisioner.go b/communicator/winrm/provisioner.go index 94e0170e1..5cef1309d 100644 --- a/communicator/winrm/provisioner.go +++ b/communicator/winrm/provisioner.go @@ -19,6 +19,9 @@ const ( // DefaultPort is used if there is no port given DefaultPort = 5985 + // DefaultHTTPSPort is used if there is no port given and HTTPS is true + DefaultHTTPSPort = 5986 + // DefaultScriptPath is used as the path to copy the file to // for remote execution if not provided otherwise. DefaultScriptPath = "C:/Temp/terraform_%RAND%.cmd" @@ -80,7 +83,11 @@ func parseConnectionInfo(s *terraform.InstanceState) (*connectionInfo, error) { connInfo.Host = shared.IpFormat(connInfo.Host) if connInfo.Port == 0 { - connInfo.Port = DefaultPort + if connInfo.HTTPS { + connInfo.Port = DefaultHTTPSPort + } else { + connInfo.Port = DefaultPort + } } if connInfo.ScriptPath == "" { connInfo.ScriptPath = DefaultScriptPath diff --git a/communicator/winrm/provisioner_test.go b/communicator/winrm/provisioner_test.go index e2494657f..fbc45c34b 100644 --- a/communicator/winrm/provisioner_test.go +++ b/communicator/winrm/provisioner_test.go @@ -6,6 +6,31 @@ import ( "github.com/hashicorp/terraform/terraform" ) +func TestProvisioner_defaultHTTPSPort(t *testing.T) { + r := &terraform.InstanceState{ + Ephemeral: terraform.EphemeralState{ + ConnInfo: map[string]string{ + "type": "winrm", + "user": "Administrator", + "password": "supersecret", + "host": "127.0.0.1", + "https": "true", + }, + }, + } + + conf, err := parseConnectionInfo(r) + if err != nil { + t.Fatalf("err: %v", err) + } + if conf.Port != 5986 { + t.Fatalf("expected: %v: got: %v", 5986, conf) + } + if conf.HTTPS != true { + t.Fatalf("expected: %v: got: %v", true, conf) + } +} + func TestProvisioner_connInfo(t *testing.T) { r := &terraform.InstanceState{ Ephemeral: terraform.EphemeralState{