Commit 6686b623 authored by Nevins Bartolomeo's avatar Nevins Bartolomeo

AWS availability zone could be incorrect when using spot instances with no AZ specified

parent b49d74d9
...@@ -75,6 +75,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi ...@@ -75,6 +75,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
} }
spotPrice := s.SpotPrice spotPrice := s.SpotPrice
availabilityZone := s.AvailabilityZone
if spotPrice == "auto" { if spotPrice == "auto" {
ui.Message(fmt.Sprintf( ui.Message(fmt.Sprintf(
"Finding spot price for %s %s...", "Finding spot price for %s %s...",
...@@ -96,6 +97,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi ...@@ -96,6 +97,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
} }
var price float64 var price float64
for _, history := range resp.History { for _, history := range resp.History {
log.Printf("[INFO] Candidate spot price: %s", history.SpotPrice) log.Printf("[INFO] Candidate spot price: %s", history.SpotPrice)
current, err := strconv.ParseFloat(history.SpotPrice, 64) current, err := strconv.ParseFloat(history.SpotPrice, 64)
...@@ -105,6 +107,9 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi ...@@ -105,6 +107,9 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
} }
if price == 0 || current < price { if price == 0 || current < price {
price = current price = current
if s.AvailabilityZone == "" {
availabilityZone = history.AvailabilityZone
}
} }
} }
if price == 0 { if price == 0 {
...@@ -158,7 +163,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi ...@@ -158,7 +163,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
SubnetId: s.SubnetId, SubnetId: s.SubnetId,
AssociatePublicIpAddress: s.AssociatePublicIpAddress, AssociatePublicIpAddress: s.AssociatePublicIpAddress,
BlockDevices: s.BlockDevices.BuildLaunchDevices(), BlockDevices: s.BlockDevices.BuildLaunchDevices(),
AvailZone: s.AvailabilityZone, AvailZone: availabilityZone,
} }
runSpotResp, err := ec2conn.RequestSpotInstances(runOpts) runSpotResp, err := ec2conn.RequestSpotInstances(runOpts)
if err != nil { if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment