Commit 12e7042c authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/chroot: wait for volume to beecome ready

parent c7b88d65
...@@ -75,6 +75,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -75,6 +75,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&StepInstanceInfo{}, &StepInstanceInfo{},
&StepSourceAMIInfo{}, &StepSourceAMIInfo{},
&StepCreateVolume{}, &StepCreateVolume{},
//&StepAttachVolume{},
} }
// Run! // Run!
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
awscommon "github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
) )
...@@ -59,6 +60,31 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio ...@@ -59,6 +60,31 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
// Set the volume ID so we remember to delete it later // Set the volume ID so we remember to delete it later
s.volumeId = createVolumeResp.VolumeId s.volumeId = createVolumeResp.VolumeId
log.Printf("Volume ID: %s", s.volumeId)
// Wait for the volume to become ready
stateChange := awscommon.StateChangeConf{
Conn: ec2conn,
Pending: []string{"creating"},
StepState: state,
Target: "available",
Refresh: func() (interface{}, string, error) {
resp, err := ec2conn.Volumes([]string{s.volumeId}, ec2.NewFilter())
if err != nil {
return nil, "", err
}
return nil, resp.Volumes[0].Status, nil
},
}
_, err = awscommon.WaitForState(&stateChange)
if err != nil {
err := fmt.Errorf("Error waiting for volume: %s", err)
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue return multistep.ActionContinue
} }
......
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