Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deprecated sources by adding a IncludeDeprecated flag to source_ami_filter #403

Closed
Ckarles opened this issue Jul 13, 2023 · 3 comments · Fixed by #404
Closed

Support deprecated sources by adding a IncludeDeprecated flag to source_ami_filter #403

Ckarles opened this issue Jul 13, 2023 · 3 comments · Fixed by #404

Comments

@Ckarles
Copy link

Ckarles commented Jul 13, 2023

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

A call to AWS API DescribeImages can contain a boolean parameter IncludeDeprecated. Sending a DescribeImages with this flag to True while using Filters to find an image will add in the response non-private images which have been marked as deprecated.

I think this parameter is useful and should be supported by packer-plugin-amazon.

Use Case(s)

Using deprecated images as source.
Issue I'm facing right now: AMI was deprecated and we can't build from this images anymore. I'd like to only acknowledge and use IncludeDeprecated instead of the alternative (manually calling DescribeImage before the call to packer and find the ami-id to pass to packer).

Potential References

DescribeImage AWS API doc: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html
DescribeImage golang sdk: https://github.com/aws/aws-sdk-go-v2/blob/38e10609d10442e497844d3add2e4b9c6d2889f1/service/ec2/api_op_DescribeImages.go#L128C3-L128C20

Implementation:
AmiFilterOptions

type AmiFilterOptions struct {

DescribeImage parameters set:
if len(d.Filters) > 0 {
amiFilters, err := buildEc2Filters(d.Filters)
if err != nil {
err := fmt.Errorf("Couldn't parse ami filters: %s", err)
return nil, err
}
params.Filters = amiFilters
}
if len(d.Owners) > 0 {
params.Owners = d.GetOwners()
}

DescribeImage request:
req, resp := ec2conn.DescribeImagesRequest(&ec2.DescribeImagesInput{
Owners: []*string{aws.String("self")},
Filters: []*ec2.Filter{{
Name: aws.String("name"),
Values: []*string{aws.String(s.DestAmiName)},
}}})

@Ckarles Ckarles changed the title Add IncludeDeprecated flag to source_ami_filter Support deprecated sources by adding a IncludeDeprecated flag to source_ami_filter Jul 13, 2023
@lbajolet-hashicorp
Copy link
Contributor

Hi @Ckarles,

Good idea! I've opened a PR for this, if this is merged, this will be part of the next plugin release.

Thanks for the suggestion!

@lbajolet-hashicorp
Copy link
Contributor

Out of curiosity, and since it may help me write an acceptance test for this feature, could I ask you which image you are depending on if this is publicly available? I can find a deprecated AMI to run a build on I would think, but this would save me some search time if you can share yours :)

@Ckarles
Copy link
Author

Ckarles commented Jul 13, 2023

Hi,

thanks for the quick patch!

This image for example (on eu-west-1):

{
            "Architecture": "x86_64",
            "CreationDate": "2021-07-07T06:40:13.000Z",
            "ImageId": "ami-058b1b7fe545997ae",
            "ImageLocation": "amazon/amzn2-ami-hvm-2.0.20210701.0-x86_64-gp2",
            "ImageType": "machine",
            "Public": true,
            "OwnerId": "137112412989",
            "PlatformDetails": "Linux/UNIX",
            "UsageOperation": "RunInstances",
            "State": "available",
            "BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/xvda",
                    "Ebs": {
                        "DeleteOnTermination": true,
                        "SnapshotId": "snap-049de0aefa0006007",
                        "VolumeSize": 8,
                        "VolumeType": "gp2",
                        "Encrypted": false
                    }
                }
            ],
            "Description": "Amazon Linux 2 AMI 2.0.20210701.0 x86_64 HVM gp2",
            "EnaSupport": true,
            "Hypervisor": "xen",
            "ImageOwnerAlias": "amazon",
            "Name": "amzn2-ami-hvm-2.0.20210701.0-x86_64-gp2",
            "RootDeviceName": "/dev/xvda",
            "RootDeviceType": "ebs",
            "SriovNetSupport": "simple",
            "VirtualizationType": "hvm",
            "DeprecationTime": "2023-07-07T06:40:13.000Z"
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants