Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Added ssh_private_ip config to enable use of VM private IP addresses #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packer/builder/azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Config struct {
tmpServiceName string
tmpContainerName string
userImageName string
SSHPrivateIp bool `mapstructure:"ssh_private_ip"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssh_private_ip -> use_private_ip, also, let's do SSHPrivateIp -> UsePrivateIP to keep it consistent. (This should also made to work similarly for Windows VM's, once I get those over to using WinRM instead of CustomScript.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased my branch before I pushed, but I recall originally using use_private_ip. For some reason, I had a problem in that my config was never picked up, and was always empty. That's why I ended up changing to SSHPrivateIp.

It's highly likely I was doing something wrong. I'll try changing the value around and re-testing at my next opportunity.


Comm communicator.Config `mapstructure:",squash"`

Expand Down
1 change: 1 addition & 0 deletions packer/builder/azure/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func getDefaultTestConfig(publishSettingsFileName string) map[string]interface{}
"location": "Central US",
"instance_size": "Large",
"user_image_label": "boo",
"use_private_ip": false,
}
}

Expand Down
28 changes: 16 additions & 12 deletions packer/builder/azure/step_poll_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (s *StepPollStatus) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
vmc := vm.NewClient(client)
ui := state.Get(constants.Ui).(packer.Ui)
config := state.Get(constants.Config).(*Config)

errorMsg := "Error polling temporary Azure VM is ready: %s"

Expand Down Expand Up @@ -101,18 +102,21 @@ func (s *StepPollStatus) Run(state multistep.StateBag) multistep.StepAction {
log.Println("s.OSType = " + s.OSType)

if s.OSType == constants.Target_Linux {
endpoints := deployment.RoleInstanceList[0].InstanceEndpoints
if len(endpoints) == 0 {
err := fmt.Errorf(errorMsg, "deployment.RoleInstanceList[0].InstanceEndpoints list is empty")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

vip := endpoints[0].Vip
state.Put(constants.SSHHost, vip)

ui.Message("VM Endpoint: " + vip)
var ip string
if config.SSHPrivateIp {
ip = deployment.RoleInstanceList[0].IPAddress
} else {
endpoints := deployment.RoleInstanceList[0].InstanceEndpoints
if len(endpoints) == 0 {
err := fmt.Errorf(errorMsg, "deployment.RoleInstanceList[0].InstanceEndpoints list is empty")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ip = endpoints[0].Vip
}
state.Put(constants.SSHHost, ip)
ui.Message("VM Endpoint: " + ip)
}

roleList := deployment.RoleList
Expand Down