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 ( ...@@ -17,6 +17,7 @@ import (
type config struct { type config struct {
AccessKey string `json:"access_key"` AccessKey string `json:"access_key"`
AMIName string `json:"ami_name"`
Region string Region string
SecretKey string `json:"secret_key"` SecretKey string `json:"secret_key"`
SourceAmi string `json:"source_ami"` SourceAmi string `json:"source_ami"`
...@@ -96,7 +97,7 @@ func (b *Builder) Run(build packer.Build, ui packer.Ui) { ...@@ -96,7 +97,7 @@ func (b *Builder) Run(build packer.Build, ui packer.Ui) {
ui.Say("Creating the AMI...\n") ui.Say("Creating the AMI...\n")
createOpts := &ec2.CreateImage{ createOpts := &ec2.CreateImage{
InstanceId: instance.InstanceId, InstanceId: instance.InstanceId,
Name: "ZIMAGINE", Name: b.config.AMIName,
} }
createResp, err := ec2conn.CreateImage(createOpts) createResp, err := ec2conn.CreateImage(createOpts)
...@@ -107,6 +108,20 @@ func (b *Builder) Run(build packer.Build, ui packer.Ui) { ...@@ -107,6 +108,20 @@ func (b *Builder) Run(build packer.Build, ui packer.Ui) {
ui.Say("AMI: %s\n", createResp.ImageId) 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 // Make sure we clean up the instance by terminating it, no matter what
defer func() { defer func() {
// TODO: error handling // 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