builder/amazon/common: use new API for goamz to set AMI attributes
/cc @jmassara
This commit is contained in:
parent
2ba59617fc
commit
dcfbef4fc0
|
@ -20,48 +20,20 @@ func (s *StepModifyAttributes) Run(state map[string]interface{}) multistep.StepA
|
|||
amis := state["amis"].(map[string]string)
|
||||
ami := amis[ec2conn.Region.Name]
|
||||
|
||||
if s.Description != "" {
|
||||
ui.Say(fmt.Sprintf("Setting Description of AMI (%s) to '%s'...", ami, s.Description))
|
||||
_, err := ec2conn.ModifyImageAttribute(ami, &ec2.ModifyImageAttribute{
|
||||
Attribute: ec2.DescriptionAttribute,
|
||||
Description: s.Description,
|
||||
})
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error setting Description of AMI (%s): %s", ami, err)
|
||||
state["error"] = err
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
options := &ec2.ModifyImageAttribute{
|
||||
Description: s.Description,
|
||||
AddUsers: s.Users,
|
||||
AddGroups: s.Groups,
|
||||
ProductCodes: s.ProductCodes,
|
||||
}
|
||||
|
||||
if len(s.Users) > 0 || len(s.Groups) > 0 {
|
||||
ui.Say(fmt.Sprintf("Setting Launch Permissions for AMI (%s)...", ami))
|
||||
_, err := ec2conn.ModifyImageAttribute(ami, &ec2.ModifyImageAttribute{
|
||||
Attribute: ec2.LaunchPermissionAttribute,
|
||||
Operation: ec2.LaunchPermissionAdd,
|
||||
Users: s.Users,
|
||||
Groups: s.Groups,
|
||||
})
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error setting Launch Permissions for AMI (%s): %s", ami, err)
|
||||
state["error"] = err
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
if len(s.ProductCodes) > 0 {
|
||||
ui.Say(fmt.Sprintf("Setting Product Code(s) for AMI (%s)...", ami))
|
||||
_, err := ec2conn.ModifyImageAttribute(ami, &ec2.ModifyImageAttribute{
|
||||
Attribute: ec2.ProductCodeAttribute,
|
||||
ProductCodes: s.ProductCodes,
|
||||
})
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error setting Product Code(s) for AMI (%s): %s", ami, err)
|
||||
state["error"] = err
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
ui.Say("Modifying AMI attributes...")
|
||||
_, err := ec2conn.ModifyImageAttribute(ami, options)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error modify AMI attributes: %s", err)
|
||||
state["error"] = err
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
|
|
Loading…
Reference in New Issue