Merge pull request #2324 from tcahill/group-launch-permissions
Fix setting ami_groups
This commit is contained in:
commit
95dd79740f
|
@ -44,12 +44,21 @@ func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAc
|
||||||
|
|
||||||
if len(s.Groups) > 0 {
|
if len(s.Groups) > 0 {
|
||||||
groups := make([]*string, len(s.Groups))
|
groups := make([]*string, len(s.Groups))
|
||||||
|
adds := make([]*ec2.LaunchPermission, len(s.Groups))
|
||||||
|
addGroups := &ec2.ModifyImageAttributeInput{
|
||||||
|
LaunchPermission: &ec2.LaunchPermissionModifications{},
|
||||||
|
}
|
||||||
|
|
||||||
for i, g := range s.Groups {
|
for i, g := range s.Groups {
|
||||||
groups[i] = &g
|
groups[i] = aws.String(g)
|
||||||
}
|
adds[i] = &ec2.LaunchPermission{
|
||||||
options["groups"] = &ec2.ModifyImageAttributeInput{
|
Group: aws.String(g),
|
||||||
UserGroups: groups,
|
}
|
||||||
}
|
}
|
||||||
|
addGroups.UserGroups = groups
|
||||||
|
addGroups.LaunchPermission.Add = adds
|
||||||
|
|
||||||
|
options["groups"] = addGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s.Users) > 0 {
|
if len(s.Users) > 0 {
|
||||||
|
|
|
@ -50,11 +50,11 @@ func TestBuilderAcc_amiSharing(t *testing.T) {
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: testBuilderAccSharing,
|
Template: testBuilderAccSharing,
|
||||||
Check: checkAMISharing(1, "932021504756"),
|
Check: checkAMISharing(2, "932021504756", "all"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkAMISharing(count int, uid string) builderT.TestCheckFunc {
|
func checkAMISharing(count int, uid, group string) builderT.TestCheckFunc {
|
||||||
return func(artifacts []packer.Artifact) error {
|
return func(artifacts []packer.Artifact) error {
|
||||||
if len(artifacts) > 1 {
|
if len(artifacts) > 1 {
|
||||||
return fmt.Errorf("more than 1 artifact")
|
return fmt.Errorf("more than 1 artifact")
|
||||||
|
@ -84,17 +84,28 @@ func checkAMISharing(count int, uid string) builderT.TestCheckFunc {
|
||||||
return fmt.Errorf("Error in Image Attributes, expected (%d) Launch Permissions, got (%d)", count, len(imageResp.LaunchPermissions))
|
return fmt.Errorf("Error in Image Attributes, expected (%d) Launch Permissions, got (%d)", count, len(imageResp.LaunchPermissions))
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
userFound := false
|
||||||
for _, lp := range imageResp.LaunchPermissions {
|
for _, lp := range imageResp.LaunchPermissions {
|
||||||
if uid == *lp.UserID {
|
if lp.UserID != nil && uid == *lp.UserID {
|
||||||
found = true
|
userFound = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !userFound {
|
||||||
return fmt.Errorf("Error in Image Attributes, expected User ID (%s) to have Launch Permissions, but was not found", uid)
|
return fmt.Errorf("Error in Image Attributes, expected User ID (%s) to have Launch Permissions, but was not found", uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
groupFound := false
|
||||||
|
for _, lp := range imageResp.LaunchPermissions {
|
||||||
|
if lp.Group != nil && group == *lp.Group {
|
||||||
|
groupFound = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !groupFound {
|
||||||
|
return fmt.Errorf("Error in Image Attributes, expected Group ID (%s) to have Launch Permissions, but was not found", group)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +214,8 @@ const testBuilderAccSharing = `
|
||||||
"source_ami": "ami-76b2a71e",
|
"source_ami": "ami-76b2a71e",
|
||||||
"ssh_username": "ubuntu",
|
"ssh_username": "ubuntu",
|
||||||
"ami_name": "packer-test {{timestamp}}",
|
"ami_name": "packer-test {{timestamp}}",
|
||||||
"ami_users":["932021504756"]
|
"ami_users":["932021504756"],
|
||||||
|
"ami_groups":["all"]
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue