philips-labs / terraform-aws-github-runner

Terraform module for scalable GitHub action runners on AWS
https://philips-labs.github.io/terraform-aws-github-runner/
MIT License
2.62k stars 627 forks source link

[ami-housekeeper] allow customizing ParameterFilters for SSM #4259

Open GMartinez-Sisti opened 2 weeks ago

GMartinez-Sisti commented 2 weeks ago

Hi, I've been using ami-housekeeper for some time now, it really helps to make sure we don't end up with a lot of AMIs as I build a new one every week.

Although, today I had an issue where AMIs in use were deleted and I was able to pinpoint it to the ami-housekeeper SSM query that didn't match up our provided ssmParameterNames filter. After investigating and reading the docs again I realized that the ami-housekeeper expects the parameters to contain ami-id in the name. Initially I thought this was a suggestion, instead of a requirement since we can also customize the filter to search for parameter name using ssmParameterNames. Docs:

When you set ssmParameterNames to *ami-id, the module will regard all AMIs referenced in SSM as in use, sparing them from deletion.

I looked into the code to check how to customize it:

https://github.com/philips-labs/terraform-aws-github-runner/blob/26ad5c17181f3d904972e4e1342d2d8006afeb23/lambdas/functions/ami-housekeeper/src/ami.ts#L194-L202

and would like to add a new parameter named ssmParameterFilters to use the defaults as the current values, but allow it to be customizable so we can use any desired filter. I already have a working lambda, so please let me know if this is something that would be accepted and I would open a PR for it.

Thank you!