ekristen / libnuke

Common Golang Packages for use by the Various Cloud Nuke Tools
MIT License
22 stars 3 forks source link

consider: only warn on date parse error #70

Open ekristen opened 3 weeks ago

ekristen commented 3 weeks ago

Original Post

In current state when you use a dateOlderThan filter, it'll return an error if it comes across a resource/field that it cannot parse as a date, and will prevent aws-nuke from running on all of the other resources it may have successfully processed

This change will instead only log a warning when an error occurs, which the user will be able to see. The resource will not be filtered out (although I'm not opinionated either way, my main goal is to not hold up aws-nuke from running because one resource was misconfigured)

I'm open to feedback/change requests

Here's an example output with these changes:

Do you really want to nuke the account with the ID 123456789012 and the alias 'my-account'?
Waiting 3s before continuing.
time="2024-07-11T21:22:47Z" level=warning msg="Failed to parse date IAMNOTADATE: unable to parse time IAMNOTADATE"
us-west-1 - DynamoDBTable - testing - [Identifier: "testing", tag:expiration-date: "IAMNOTADATE"] - would remove
Scan complete: 1 total, 1 nukeable, 0 filtered.

The above resources would be deleted with the supplied configuration. Provide --no-dry-run to actually destroy resources.

Upstream Reference: https://github.com/rebuy-de/aws-nuke/pull/1245

ekristen commented 3 weeks ago

I think it makes sense to just change this behavior to log the error. After thinking about this this wont actually change the filtering. It wouldn't have matched to begin with and an error just interrupts.

ekristen commented 3 weeks ago

I think this should remain error because this is parsing the configuration and if it's an invalid duration it should be error'd out, or we need a validation on config to error it out before this point.

https://github.com/ekristen/libnuke/blob/main/pkg/filter/filter.go#L131-L134

However, this one should just be a log message because if it gets bad data from a resource, we shouldn't full stop.

https://github.com/ekristen/libnuke/blob/main/pkg/filter/filter.go#L135-L138