Commit 4fc76443 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazonebs: Wait for AMI to become ready

parent e071739c
......@@ -17,6 +17,7 @@ import (
type config struct {
AccessKey string `json:"access_key"`
AMIName string `json:"ami_name"`
Region string
SecretKey string `json:"secret_key"`
SourceAmi string `json:"source_ami"`
......@@ -96,7 +97,7 @@ func (b *Builder) Run(build packer.Build, ui packer.Ui) {
ui.Say("Creating the AMI...\n")
createOpts := &ec2.CreateImage{
InstanceId: instance.InstanceId,
Name: "ZIMAGINE",
Name: b.config.AMIName,
}
createResp, err := ec2conn.CreateImage(createOpts)
......@@ -107,6 +108,20 @@ func (b *Builder) Run(build packer.Build, ui packer.Ui) {
ui.Say("AMI: %s\n", createResp.ImageId)
// Wait for the image to become ready
ui.Say("Waiting for AMI to become ready...\n")
for {
imageResp, err := ec2conn.Images([]string{createResp.ImageId}, ec2.NewFilter())
if err != nil {
ui.Error("%s\n", err.Error())
return
}
if imageResp.Images[0].State == "available" {
break
}
}
// Make sure we clean up the instance by terminating it, no matter what
defer func() {
// TODO: error handling
......
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