Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Aging time Added to all of the resources in awsnuke - whitelist pre-population, etc. #767

Open
nhemchand opened this issue Mar 21, 2022 · 5 comments

Comments

@nhemchand
Copy link

I want to check whether awsnuke to see if resources that haven't reached a specific age (30 days, etc.) can automatically added to the awsnuke whitelist.

@nhemchand nhemchand changed the title Can Aging be Added to awsnuke - whitelist pre-population, etc. Can Aging time Added to all of the resources in awsnuke - whitelist pre-population, etc. Mar 29, 2022
@nhemchand
Copy link
Author

nhemchand commented Mar 29, 2022

1.This code snippet does not seem to be working.
Im still able to delete ec2 instance of 60days old.
######################

EC2Instance:
- property: dateOlderThan
  value: "time.Now().AddDate(0, 0, -90d)"

######################

2.Can similar logic as above used for other 375 resources as well?
nuke resource-types | wc -l ( 375 resources )

@svenwltr
Copy link
Member

svenwltr commented Apr 5, 2022

Hello.

You have to specify the duration in hours. For example 90 days would be 2160h.

For example:

EC2Instance:
- property: dateOlderThan
  value: "2160h"

⚠️ It might also have to be a negative number (eg 2160h). Not sure about this, because I neither implemented nor used this feature.


"time.Now().AddDate(0, 0, -90d)"

This is the second time I am seeing this random code snippet in a config file. Where did you get this from?

@nhemchand
Copy link
Author

nhemchand commented Apr 5, 2022

  1. Does property "dateOlderThan" support for all of the resource types nuke supports?

$ bin/aws-nuke-mac resource-types | wc -l
373

  1. I got the references for the random code snippet from the following.
    https://stackoverflow.com/questions/71409119/how-do-you-terminate-resources-that-are-older-than-x-days-using-aws-nuke

@nhemchand
Copy link
Author

By the way, this condition does not work.
It is deleting resources older than 90 days as well.
I tried with negative number as well ( eg: -2160h )

EC2Instance:
   - property: dateOlderThan
      value: "2160h"

@svenwltr
Copy link
Member

svenwltr commented Apr 6, 2022

Does property "dateOlderThan" support for all of the resource types nuke supports?

No, only properties that look like a date.

By the way, this condition does not work.

The filter syntax is wrong. dateOlderThan is a filter type, not a property. The properties are logged by aws-nuke on execution. In case of EC2 instances, you can see that LaunchTime looks like a date:

eu-west-1 - EC2Instance - i-05fad575ab16ef746 - [Identifier: "i-05fad575ab16ef746", ImageIdentifier: "ami-00326b38b90636d3d", InstanceState: "running", InstanceType: "m6a.2xlarge", LaunchTime: "2022-04-06T11:18:59Z", tag:Name: "worker-stateful-dysprosium", tag:aws:autoscaling:groupName: "worker-stateful-dysprosium", tag:aws:ec2:fleet-id: "fleet-22aace4e-5c2b-218a-241a-018a14ce99f8", tag:aws:ec2launchtemplate:id: "lt-0aebdaec69b603a3c", tag:aws:ec2launchtemplate:version: "1", tag:k8s.io/cluster-autoscaler/enabled: "true", tag:kubernetes.io/cluster/staging: "owned"] - would remove

So you can use this as a property:

EC2Instance:
- property: LaunchTime
  type: dateOlderThan
  value: "2160h" # might be negative

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants