Merge pull request #663 from ktruong7/public-AMI

builder/amazon/all: added option to make AMI public
This commit is contained in:
Mitchell Hashimoto 2013-12-06 18:05:45 -08:00
commit b2fc77870b
5 changed files with 15 additions and 0 deletions

View File

@ -202,6 +202,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Description: b.config.AMIDescription,
Users: b.config.AMIUsers,
Groups: b.config.AMIGroups,
Visibility: b.config.AMIVisibility,
},
&awscommon.StepCreateTags{
Tags: b.config.AMITags,

View File

@ -15,6 +15,7 @@ type AMIConfig struct {
AMIProductCodes []string `mapstructure:"ami_product_codes"`
AMIRegions []string `mapstructure:"ami_regions"`
AMITags map[string]string `mapstructure:"tags"`
AMIVisibility string `mapstructure:"ami_visibility"`
}
func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
@ -29,6 +30,7 @@ func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
templates := map[string]*string{
"ami_name": &c.AMIName,
"ami_description": &c.AMIDescription,
"ami_visibility": &c.AMIVisibility,
}
errs := make([]error, 0)

View File

@ -13,6 +13,7 @@ type StepModifyAMIAttributes struct {
Groups []string
ProductCodes []string
Description string
Visibility string
}
func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAction {
@ -26,6 +27,7 @@ func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAc
valid = valid || (s.Users != nil && len(s.Users) > 0)
valid = valid || (s.Groups != nil && len(s.Groups) > 0)
valid = valid || (s.ProductCodes != nil && len(s.ProductCodes) > 0)
valid = valid || s.Visibility == "public"
if !valid {
return multistep.ActionContinue
@ -59,6 +61,14 @@ func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAc
}
}
if s.Visibility == "public" {
group := make([]string, 1)
group[0] = "all"
options["public ami"] = &ec2.ModifyImageAttribute{
AddGroups: group,
}
}
for region, ami := range amis {
ui.Say(fmt.Sprintf("Modifying attributes on AMI (%s)...", ami))
regionconn := ec2.New(ec2conn.Auth, aws.Regions[region])

View File

@ -119,6 +119,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Description: b.config.AMIDescription,
Users: b.config.AMIUsers,
Groups: b.config.AMIGroups,
Visibility: b.config.AMIVisibility,
},
&awscommon.StepCreateTags{
Tags: b.config.AMITags,

View File

@ -225,6 +225,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Users: b.config.AMIUsers,
Groups: b.config.AMIGroups,
ProductCodes: b.config.AMIProductCodes,
Visibility: b.config.AMIVisibility,
},
&awscommon.StepCreateTags{
Tags: b.config.AMITags,