jckuester / awsweeper

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

Tags filter not working #45

Closed cloudlena closed 4 years ago

cloudlena commented 4 years ago

For me, the tags filter is not working... I have multiple resources that have the tag environment: test. However, when I run the following config:

aws_ami:
  - tags:
      environment: test
aws_autoscaling_group:
  - tags:
      environment: test
aws_cloudformation_stack:
  - tags:
      environment: test
aws_ebs_snapshot:
  - tags:
      environment: test
aws_ebs_volume:
  - tags:
      environment: test
aws_efs_file_system:
  - tags:
      environment: test
aws_eip:
  - tags:
      environment: test
aws_elb:
  - tags:
      environment: test
aws_iam_group:
  - tags:
      environment: test
aws_iam_instance_profile:
  - tags:
      environment: test
aws_iam_policy:
  - tags:
      environment: test
aws_iam_role:
  - tags:
      environment: test
aws_iam_user:
  - tags:
      environment: test
aws_instance:
  - tags:
      environment: test
aws_internet_gateway:
  - tags:
      environment: test
aws_key_pair:
  - tags:
      environment: test
aws_kms_alias:
  - tags:
      environment: test
aws_kms_key:
  - tags:
      environment: test
aws_launch_configuration:
  - tags:
      environment: test
aws_nat_gateway:
  - tags:
      environment: test
aws_network_acl:
  - tags:
      environment: test
aws_network_interface:
  - tags:
      environment: test
aws_route53_zone:
  - tags:
      environment: test
aws_route_table:
  - tags:
      environment: test
aws_s3_bucket:
  - tags:
      environment: test
aws_security_group:
  - tags:
      environment: test
aws_subnet:
  - tags:
      environment: test
aws_vpc:
  - tags:
      environment: test
aws_vpc_endpoint:
  - tags:
      environment: test

To me it looks like awsweeper doesn't support filtering by tags for all the AWS resources that officially support tags (e.g. aws_iam_role) in Terraform. Is that possible?

jckuester commented 4 years ago

That is correct. Unfortunately, tags are not always returned as part of a List... or Describe... and I need the add some extra logic to fetch tags for every resource (as @kadaan did here for the ELB https://github.com/cloudetc/awsweeper/pull/47).

Most preferable, I'd like to find some generic way to fetch tags for every resource. I'll need to investigate on that when I find time...

jckuester commented 4 years ago

@mastertinner to be more clear, I added an overview about which resources currently support tags in awsweeper: https://github.com/cloudetc/awsweeper#supported-resources

For aws_iam_role filtering should actually be working.

jckuester commented 4 years ago

@mastertinner just letting you know that I have now implemented a generic way to make tags working for all resources that support them: https://github.com/cloudetc/awsweeper/releases/tag/v0.9.0.

To see which resources support tags, see the list here (the list has gotten also much longer; over 200 resources are supported now): https://github.com/cloudetc/awsweeper#supported-resources

Let me know if I can close this issue :smiley:

cloudlena commented 4 years ago

Thanks a lot for your effort, @jckuester! Looks great and this issue can be closed.