Fix winrm default ssl port (#19540)

* Update provisioner.go

Changed the default port used for winrm when https is specified
This commit is contained in:
Eamon Hetherton 2018-12-13 03:49:02 +04:30 committed by James Bardin
parent 541143ddce
commit d1c301bc2d
2 changed files with 33 additions and 1 deletions

View File

@ -19,6 +19,9 @@ const (
// DefaultPort is used if there is no port given // DefaultPort is used if there is no port given
DefaultPort = 5985 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 // DefaultScriptPath is used as the path to copy the file to
// for remote execution if not provided otherwise. // for remote execution if not provided otherwise.
DefaultScriptPath = "C:/Temp/terraform_%RAND%.cmd" DefaultScriptPath = "C:/Temp/terraform_%RAND%.cmd"
@ -80,7 +83,11 @@ func parseConnectionInfo(s *terraform.InstanceState) (*connectionInfo, error) {
connInfo.Host = shared.IpFormat(connInfo.Host) connInfo.Host = shared.IpFormat(connInfo.Host)
if connInfo.Port == 0 { if connInfo.Port == 0 {
connInfo.Port = DefaultPort if connInfo.HTTPS {
connInfo.Port = DefaultHTTPSPort
} else {
connInfo.Port = DefaultPort
}
} }
if connInfo.ScriptPath == "" { if connInfo.ScriptPath == "" {
connInfo.ScriptPath = DefaultScriptPath connInfo.ScriptPath = DefaultScriptPath

View File

@ -6,6 +6,31 @@ import (
"github.com/hashicorp/terraform/terraform" "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) { func TestProvisioner_connInfo(t *testing.T) {
r := &terraform.InstanceState{ r := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{ Ephemeral: terraform.EphemeralState{