diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 198dc33a8..5f74f5f70 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -675,27 +675,40 @@ func setRuntimeValues(c *Config) { } func setUserNamePassword(c *Config) error { + // Set default credentials generated by the builder + c.UserName = DefaultUserName + c.Password = c.tmpAdminPassword + + // Set communicator specific credentials and update defaults if different. + // Communicator specific credentials need to be updated as the standard Packer + // SSHConfigFunc and WinRMConfigFunc use communicator specific credentials, unless overwritten. + // SSH comm if c.Comm.SSHUsername == "" { - c.Comm.SSHUsername = DefaultUserName + c.Comm.SSHUsername = c.UserName } c.UserName = c.Comm.SSHUsername - if c.Comm.SSHPassword != "" { - c.Password = c.Comm.SSHPassword + if c.Comm.SSHPassword == "" { + c.Comm.SSHPassword = c.Password + } + c.Password = c.Comm.SSHPassword + + if c.Comm.Type == "ssh" { return nil } // WinRM comm if c.Comm.WinRMUser == "" { - c.Comm.WinRMUser = DefaultUserName + c.Comm.WinRMUser = c.UserName } c.UserName = c.Comm.WinRMUser if c.Comm.WinRMPassword == "" { // Configure password settings using Azure generated credentials - c.Comm.WinRMPassword = c.tmpAdminPassword + c.Comm.WinRMPassword = c.Password } + if !isValidPassword(c.Comm.WinRMPassword) { return fmt.Errorf("The supplied \"winrm_password\" must be between 8-123 characters long and must satisfy at least 3 from the following: \n1) Contains an uppercase character \n2) Contains a lowercase character\n3) Contains a numeric digit\n4) Contains a special character\n5) Control characters are not allowed") }