builder/amazon/common: use new API for goamz to set AMI attributes

/cc @jmassara
This commit is contained in:
Mitchell Hashimoto 2013-08-08 22:43:29 -07:00
parent b0394c6d30
commit 1f53e047a3
1 changed files with 12 additions and 40 deletions

View File

@ -20,48 +20,20 @@ func (s *StepModifyAttributes) Run(state map[string]interface{}) multistep.StepA
amis := state["amis"].(map[string]string) amis := state["amis"].(map[string]string)
ami := amis[ec2conn.Region.Name] ami := amis[ec2conn.Region.Name]
if s.Description != "" { options := &ec2.ModifyImageAttribute{
ui.Say(fmt.Sprintf("Setting Description of AMI (%s) to '%s'...", ami, s.Description)) Description: s.Description,
_, err := ec2conn.ModifyImageAttribute(ami, &ec2.ModifyImageAttribute{ AddUsers: s.Users,
Attribute: ec2.DescriptionAttribute, AddGroups: s.Groups,
Description: s.Description, ProductCodes: s.ProductCodes,
})
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
}
} }
if len(s.Users) > 0 || len(s.Groups) > 0 { ui.Say("Modifying AMI attributes...")
ui.Say(fmt.Sprintf("Setting Launch Permissions for AMI (%s)...", ami)) _, err := ec2conn.ModifyImageAttribute(ami, options)
_, err := ec2conn.ModifyImageAttribute(ami, &ec2.ModifyImageAttribute{ if err != nil {
Attribute: ec2.LaunchPermissionAttribute, err := fmt.Errorf("Error modify AMI attributes: %s", err)
Operation: ec2.LaunchPermissionAdd, state["error"] = err
Users: s.Users, ui.Error(err.Error())
Groups: s.Groups, return multistep.ActionHalt
})
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
}
} }
return multistep.ActionContinue return multistep.ActionContinue