diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 2cb819b1f..d242633ab 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -223,14 +223,21 @@ func newConfig(raws ...interface{}) (*Config, []string, error) { return nil, nil, err } - err = setSshValues(&c) - if err != nil { - return nil, nil, err + // NOTE: if the user did not specify a communicator, then default to both + // SSH and WinRM. This is for backwards compatibility because the code did + // not specifically force the user to specify a value. + if c.Comm.Type == "" || strings.EqualFold(c.Comm.Type, "ssh") { + err = setSshValues(&c) + if err != nil { + return nil, nil, err + } } - err = setWinRMCertificate(&c) - if err != nil { - return nil, nil, err + if c.Comm.Type == "" || strings.EqualFold(c.Comm.Type, "winrm") { + err = setWinRMCertificate(&c) + if err != nil { + return nil, nil, err + } } var errs *packer.MultiError @@ -276,14 +283,14 @@ func setSshValues(c *Config) error { c.sshPrivateKey = sshKeyPair.PrivateKey() } - c.Comm.WinRMTransportDecorator = func(t *http.Transport) http.RoundTripper { - return &ntlmssp.Negotiator{RoundTripper: t} - } - return nil } func setWinRMCertificate(c *Config) error { + c.Comm.WinRMTransportDecorator = func(t *http.Transport) http.RoundTripper { + return &ntlmssp.Negotiator{RoundTripper: t} + } + cert, err := c.createCertificate() c.winrmCertificate = cert diff --git a/builder/azure/arm/config_test.go b/builder/azure/arm/config_test.go index 3d5a7756c..2708e9e2a 100644 --- a/builder/azure/arm/config_test.go +++ b/builder/azure/arm/config_test.go @@ -56,6 +56,7 @@ func TestConfigShouldBeAbleToOverrideDefaultedValues(t *testing.T) { builderValues["ssh_password"] = "override_password" builderValues["ssh_username"] = "override_username" builderValues["vm_size"] = "override_vm_size" + builderValues["communicator"] = "ssh" c, _, err := newConfig(builderValues, getPackerConfiguration()) @@ -123,6 +124,7 @@ func TestConfigInstantiatesCorrectAzureEnvironment(t *testing.T) { "storage_account": "ignore", "subscription_id": "ignore", "os_type": constants.Target_Linux, + "communicator": "none", } // user input is fun :) @@ -328,6 +330,22 @@ func TestConfigShouldSupportPackersConfigElements(t *testing.T) { } } +func TestWinRMConfigShouldSetRoundTripDecorator(t *testing.T) { + config := getArmBuilderConfiguration() + config["communicator"] = "winrm" + config["winrm_username"] = "username" + config["winrm_password"] = "password" + + c, _, err := newConfig(config, getPackerConfiguration()) + if err != nil { + t.Fatal(err) + } + + if c.Comm.WinRMTransportDecorator == nil { + t.Errorf("Expected WinRMTransportDecorator to be set, but it was nil") + } +} + func TestUserDeviceLoginIsEnabledForLinux(t *testing.T) { config := map[string]string{ "capture_name_prefix": "ignore", @@ -339,6 +357,7 @@ func TestUserDeviceLoginIsEnabledForLinux(t *testing.T) { "storage_account": "ignore", "subscription_id": "ignore", "os_type": constants.Target_Linux, + "communicator": "none", } _, _, err := newConfig(config, getPackerConfiguration()) @@ -358,6 +377,7 @@ func TestUseDeviceLoginIsDisabledForWindows(t *testing.T) { "storage_account": "ignore", "subscription_id": "ignore", "os_type": constants.Target_Windows, + "communicator": "none", } _, _, err := newConfig(config, getPackerConfiguration()) @@ -387,6 +407,7 @@ func getArmBuilderConfiguration() map[string]string { m[v] = fmt.Sprintf("%s00", v) } + m["communicator"] = "none" m["os_type"] = constants.Target_Linux return m }