jckuester/awsweeper

Filters tag and created not working together

marcelocrocha opened this issue · 3 comments

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

`aws_instance:

  • tags:
    NOT(nuke): keep
  • created:
    before: 30d

aws_autoscaling_group:

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

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.

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 :)

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

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