hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
73 stars 110 forks source link

Amazon EBS Volume builder should support setting EBS Volume Snapshot Description #470

Closed saxonww closed 7 months ago

saxonww commented 7 months ago

Description

The Amazon EBS Volume builder enables Packer to create EBS Volume Snapshots. It supports setting snapshot_tags, snapshot_users, and snapshot_groups, but not snapshot description.

The builder supports sharing snapshots cross-account via snapshot_users. However, tag metadata set via snapshot_tags is not visible cross-account, leaving only the snapshot ID, owner (account ID), and KMS key ID visible on snapshots created via the Packer AWS EBS Volume builder.

This feature request is to add the capability to set snapshot description.

Use Case(s)

Any process that leverages an organization's internal versioning scheme would benefit from this feature, as the Description metadata is the simplest way to communicate version information.

A concrete example would be a CI process which packages a product release as an EBS volume snapshot. Without setting Description, consumers would have to maintain a separate mapping of snapshot ID to version and/or manually configure by unique snapshot ID when working cross-account.

Potential configuration

variable "ami_name" {}
variable "ami_owner" {}
variable "product_name" {}
variable "product_version" {}
variable "region" {}
variable "user_accounts" {}

data "amazon-ami" "base" {
    filters = {
        virtualization-type = "hvm"
        name                = var.ami_name
        root-device-type    = "ebs"
    }
    owners      = [var.ami_owner]
    most_recent = true
    region      = var.region
}

source "amazon-ebsvolume" "main" {
    region               = var.region
    ssh_username         = "ec2-user"
    instance_type        = "t3.nano"
    source_ami           = data.amazon-ami.base.id

    ebs_volumes {
        device_name = "/dev/xvda"
        volume_type = "gp3"
        delete_on_termination = true
        volume_size = 10
    }

    ebs_volumes {
        volume_type = "gp3"
        device_name = "/dev/xvdf"
        delete_on_termination = true
        volume_size = 3

        snapshot_description = "${var.product_name}-${var.product_version}"
        snapshot_users = var.user_accounts
        snapshot_volume = true
    }
}

build {
    # do build stuff
}

Potential References

lbajolet-hashicorp commented 7 months ago

Hi @saxonww,

That is a good idea indeed, and this should be reasonably easy to implement! We probably won't do it too soon though since we're a bit busy with other things right now, but at first glance this should essentially be adding the Description to the CreateImageInput call for create ami, would you be available to open a PR for this? We'd be glad to help if that interests you, please let us know what you think!

saxonww commented 7 months ago

Hi @saxonww,

That is a good idea indeed, and this should be reasonably easy to implement! We probably won't do it too soon though since we're a bit busy with other things right now, but at first glance this should essentially be adding the Description to the CreateImageInput call for create ami, would you be available to open a PR for this? We'd be glad to help if that interests you, please let us know what you think!

Yeah I think so, I'm concerned about getting a good test written - I haven't looked at how to do that - but the rest of it seems easy.

lbajolet-hashicorp commented 7 months ago

Yeah as far as testing goes this is likely a job for acceptance tests, I suggest you try the feature in your account, and we can write one after that, which we can then run in our account each week (there's a recurring job each Sunday for those). I can assist when comes time to write the acceptance test, no worries about that!