jckuester / awsweeper

A tool for cleaning your AWS account
Mozilla Public License 2.0
467 stars 45 forks source link

Filters tag and created not working together #130

Closed marcelocrocha closed 2 years ago

marcelocrocha commented 2 years ago

In a filter with both, tag and created, it looks like just the first one is having an effect. For example:

`aws_instance:

aws_autoscaling_group:

Awsweeper is deleting all the instances that do not have that tag, not taking into consideration the created before 30d filter. And even deleting instances with the tag as well it looks like.

The --dry-run even shows that indeed the tag is there in the instance:

Id: i-iu5h23i465h3i6 Tags: [nuke: keep] Created: 2021-09-14 17:40:52 +0000 UTC

Is there a proper way to have two filters working at the same time like this?

But if I remove the created, and only use tag, it works and the resource with the tag won't be listed for deletion.

jckuester commented 2 years ago

Hi @marcelocrocha,

what you want is probably

`aws_instance:
  - tags:
      NOT(nuke): keep
    created:
      before: 30d     

You basically specified an OR but you want an AND (I know defining the filter as a YAML is not always super intuitive). This is documented here in the README: https://github.com/jckuester/awsweeper#filter. If you have suggestions for improving the readability on how to use the filters, your feedback is welcome :)

marcelocrocha commented 2 years ago

Interesting, didn't notice that. Thanks for the update. I'll test that and will let you know how it goes.

marcelocrocha commented 2 years ago

Yep, it worked as you described @jckuester . Thanks.