Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

platform/api/aws: copy createVolumePermission when replicating #1112

Merged
merged 1 commit into from Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions platform/api/aws/images.go
Expand Up @@ -555,6 +555,15 @@ func (a *API) CopyImage(sourceImageID string, regions []string) (map[string]Imag
}
snapshot := describeSnapshotRes.Snapshots[0]

describeSnapshotAttributeRes, err := a.ec2.DescribeSnapshotAttribute(&ec2.DescribeSnapshotAttributeInput{
Attribute: aws.String("createVolumePermission"),
SnapshotId: aws.String(snapshotID),
})
if err != nil {
return nil, fmt.Errorf("couldn't describe createVolumePermission: %v", err)
}
createVolumePermissions := describeSnapshotAttributeRes.CreateVolumePermissions

describeAttributeRes, err := a.ec2.DescribeImageAttribute(&ec2.DescribeImageAttributeInput{
Attribute: aws.String("launchPermission"),
ImageId: aws.String(sourceImageID),
Expand All @@ -580,7 +589,7 @@ func (a *API) CopyImage(sourceImageID string, regions []string) (map[string]Imag
res.data, res.err = aa.copyImageIn(a.opts.Region, sourceImageID,
*image.Name, *image.Description,
image.Tags, snapshot.Tags,
launchPermissions)
launchPermissions, createVolumePermissions)
ch <- res
}()
}
Expand All @@ -599,7 +608,7 @@ func (a *API) CopyImage(sourceImageID string, regions []string) (map[string]Imag
return amis, err
}

func (a *API) copyImageIn(sourceRegion, sourceImageID, name, description string, imageTags, snapshotTags []*ec2.Tag, launchPermissions []*ec2.LaunchPermission) (ImageData, error) {
func (a *API) copyImageIn(sourceRegion, sourceImageID, name, description string, imageTags, snapshotTags []*ec2.Tag, launchPermissions []*ec2.LaunchPermission, createVolumePermissions []*ec2.CreateVolumePermission) (ImageData, error) {
imageID, err := a.FindImage(name)
if err != nil {
return ImageData{}, err
Expand Down Expand Up @@ -658,6 +667,19 @@ func (a *API) copyImageIn(sourceRegion, sourceImageID, name, description string,
}
}

if len(createVolumePermissions) > 0 {
_, err = a.ec2.ModifySnapshotAttribute(&ec2.ModifySnapshotAttributeInput{
Attribute: aws.String("createVolumePermission"),
SnapshotId: &snapshotID,
CreateVolumePermission: &ec2.CreateVolumePermissionModifications{
Add: createVolumePermissions,
},
})
if err != nil {
return ImageData{}, fmt.Errorf("couldn't grant createVolumePermissions: %v", err)
}
}

if len(launchPermissions) > 0 {
_, err = a.ec2.ModifyImageAttribute(&ec2.ModifyImageAttributeInput{
Attribute: aws.String("launchPermission"),
Expand Down