Added option to make ami public automatically
This commit is contained in:
parent
27063b236e
commit
3589b0ba27
|
@ -202,6 +202,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Description: b.config.AMIDescription,
|
Description: b.config.AMIDescription,
|
||||||
Users: b.config.AMIUsers,
|
Users: b.config.AMIUsers,
|
||||||
Groups: b.config.AMIGroups,
|
Groups: b.config.AMIGroups,
|
||||||
|
Visibility: b.config.AMIVisibility,
|
||||||
},
|
},
|
||||||
&awscommon.StepCreateTags{
|
&awscommon.StepCreateTags{
|
||||||
Tags: b.config.AMITags,
|
Tags: b.config.AMITags,
|
||||||
|
|
|
@ -15,6 +15,7 @@ type AMIConfig struct {
|
||||||
AMIProductCodes []string `mapstructure:"ami_product_codes"`
|
AMIProductCodes []string `mapstructure:"ami_product_codes"`
|
||||||
AMIRegions []string `mapstructure:"ami_regions"`
|
AMIRegions []string `mapstructure:"ami_regions"`
|
||||||
AMITags map[string]string `mapstructure:"tags"`
|
AMITags map[string]string `mapstructure:"tags"`
|
||||||
|
AMIVisibility string `mapstructure:"ami_visibility"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
|
func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
|
||||||
|
@ -29,6 +30,7 @@ func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
|
||||||
templates := map[string]*string{
|
templates := map[string]*string{
|
||||||
"ami_name": &c.AMIName,
|
"ami_name": &c.AMIName,
|
||||||
"ami_description": &c.AMIDescription,
|
"ami_description": &c.AMIDescription,
|
||||||
|
"ami_visibility": &c.AMIVisibility,
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := make([]error, 0)
|
errs := make([]error, 0)
|
||||||
|
|
|
@ -13,6 +13,7 @@ type StepModifyAMIAttributes struct {
|
||||||
Groups []string
|
Groups []string
|
||||||
ProductCodes []string
|
ProductCodes []string
|
||||||
Description string
|
Description string
|
||||||
|
Visibility string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAction {
|
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.Users != nil && len(s.Users) > 0)
|
||||||
valid = valid || (s.Groups != nil && len(s.Groups) > 0)
|
valid = valid || (s.Groups != nil && len(s.Groups) > 0)
|
||||||
valid = valid || (s.ProductCodes != nil && len(s.ProductCodes) > 0)
|
valid = valid || (s.ProductCodes != nil && len(s.ProductCodes) > 0)
|
||||||
|
valid = valid || s.Visibility == "public"
|
||||||
|
|
||||||
if !valid {
|
if !valid {
|
||||||
return multistep.ActionContinue
|
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 {
|
for region, ami := range amis {
|
||||||
ui.Say(fmt.Sprintf("Modifying attributes on AMI (%s)...", ami))
|
ui.Say(fmt.Sprintf("Modifying attributes on AMI (%s)...", ami))
|
||||||
regionconn := ec2.New(ec2conn.Auth, aws.Regions[region])
|
regionconn := ec2.New(ec2conn.Auth, aws.Regions[region])
|
||||||
|
|
|
@ -119,6 +119,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Description: b.config.AMIDescription,
|
Description: b.config.AMIDescription,
|
||||||
Users: b.config.AMIUsers,
|
Users: b.config.AMIUsers,
|
||||||
Groups: b.config.AMIGroups,
|
Groups: b.config.AMIGroups,
|
||||||
|
Visibility: b.config.AMIVisibility,
|
||||||
},
|
},
|
||||||
&awscommon.StepCreateTags{
|
&awscommon.StepCreateTags{
|
||||||
Tags: b.config.AMITags,
|
Tags: b.config.AMITags,
|
||||||
|
|
|
@ -225,6 +225,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Users: b.config.AMIUsers,
|
Users: b.config.AMIUsers,
|
||||||
Groups: b.config.AMIGroups,
|
Groups: b.config.AMIGroups,
|
||||||
ProductCodes: b.config.AMIProductCodes,
|
ProductCodes: b.config.AMIProductCodes,
|
||||||
|
Visibility: b.config.AMIVisibility,
|
||||||
},
|
},
|
||||||
&awscommon.StepCreateTags{
|
&awscommon.StepCreateTags{
|
||||||
Tags: b.config.AMITags,
|
Tags: b.config.AMITags,
|
||||||
|
|
Loading…
Reference in New Issue