-
Notifications
You must be signed in to change notification settings - Fork 26
Description
We use terraform to manage our launch templates: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template
and it doesn't delete old versions ever. It would be nice if there was an option on this plugin to still delete amis that are part of launch templates, but not launch template verions that are used in ASGs, or the latest, or the default version of a launch template. Otherwise nothing ever gets deleted unless we go in manually and delete a bunch of old launch template versions.
It might be nice if that was completely configurable, options like:
launch_template_versions = { # launch templates versions to look at
latest = 6 # do not consider amis from the most recent 6 versions of launch templates for deletion
asg = true # do not consider amis that are part of launch template versions configured in asgs for deletion
all = true # do not consider amis part of any launch template version for deletion
default = true # do not consider amis part of the default launch template version for deletion
}This could default to:
launch_template_versions = {
all = true
}just to be on the safe side. I believe this is how it behaves currently.
I would probably personally set it to:
launch_template_versions = {
latest = 3
asg = true
}to delete amis from all launch templates other than the most recent 3, and any that are part of asgs.
An alternative is for terraform to implement an argument to limit the number of versions of the launch template that are kept.
My current workaround is to put the ami id in the name_prefix so there's only ever one ami in any versions of the launch template:
resource "aws_launch_template" "main" {
update_default_version = true
name_prefix = "some-descriptive-name-${data.aws_ami.image.image_id}"
lifecycle {
create_before_destroy = true
}
...