Adds support for adding tags to the AMI
This commit is contained in:
parent
ef59ee41a8
commit
852c10264b
|
@ -3,6 +3,7 @@ package common
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/mitchellh/goamz/ec2"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ type RunConfig struct {
|
||||||
SecurityGroupId string `mapstructure:"security_group_id"`
|
SecurityGroupId string `mapstructure:"security_group_id"`
|
||||||
SubnetId string `mapstructure:"subnet_id"`
|
SubnetId string `mapstructure:"subnet_id"`
|
||||||
VpcId string `mapstructure:"vpc_id"`
|
VpcId string `mapstructure:"vpc_id"`
|
||||||
|
Tags []ec2.Tag
|
||||||
|
|
||||||
// Unexported fields that are calculated from others
|
// Unexported fields that are calculated from others
|
||||||
sshTimeout time.Duration
|
sshTimeout time.Duration
|
||||||
|
|
|
@ -107,7 +107,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
},
|
},
|
||||||
&common.StepProvision{},
|
&common.StepProvision{},
|
||||||
&stepStopInstance{},
|
&stepStopInstance{},
|
||||||
&stepCreateAMI{},
|
&stepCreateAMI{
|
||||||
|
Tags: b.config.Tags,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run!
|
// Run!
|
||||||
|
|
|
@ -12,7 +12,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepCreateAMI struct{}
|
type stepCreateAMI struct {
|
||||||
|
Tags []ec2.Tag
|
||||||
|
}
|
||||||
|
|
||||||
type amiNameData struct {
|
type amiNameData struct {
|
||||||
CreateTime string
|
CreateTime string
|
||||||
|
@ -64,6 +66,19 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add tags to AMI
|
||||||
|
if s.Tags != nil {
|
||||||
|
ui.Say(fmt.Sprintf("Add tags to AMI (%s)...", createResp.ImageId))
|
||||||
|
amiId := []string{createResp.ImageId}
|
||||||
|
_, err := ec2conn.CreateTags(amiId, s.Tags)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Error adding tags to AMI (%s): %s", createResp.ImageId, err)
|
||||||
|
state["error"] = err
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue