Skip to content

Commit

Permalink
updating timeMargin to be consistent and called excludeAfter; updatin…
Browse files Browse the repository at this point in the history
…g test to match new condition so it passes
  • Loading branch information
ina-stoyanova committed Oct 7, 2020
1 parent a2353e1 commit ca1a0cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions aws/ecs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/gruntwork-io/gruntwork-cli/errors"
)

const firstSeenTagKey = "cloud-nuke-first-seen"

// Tag an ECS cluster identified by the given cluster ARN with a tag that has the given key and value
func tagEcsCluster(awsSession *session.Session, clusterArn *string, tagKey string, tagValue string) error {
svc := ecs.New(awsSession)
Expand All @@ -31,7 +33,7 @@ func tagEcsCluster(awsSession *session.Session, clusterArn *string, tagKey strin
return nil
}

func getAllEcsClustersOlderThan(awsSession *session.Session, region string, timeMargin time.Time) ([]*string, error) {
func getAllEcsClustersOlderThan(awsSession *session.Session, region string, excludeAfter time.Time) ([]*string, error) {
awsSession, err := session.NewSession(&awsgo.Config{
Region: awsgo.String(region),
})
Expand Down Expand Up @@ -59,7 +61,7 @@ func getAllEcsClustersOlderThan(awsSession *session.Session, region string, time
}
}

if firstSeenTime.Before(timeMargin) {
if excludeAfter.After(firstSeenTime) {
filteredEcsClusters = append(filteredEcsClusters, clusterArn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws/ecs_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestCanNukeAllEcsClustersOlderThan24Hours(t *testing.T) {
now := time.Now().UTC()
var oldClusterTagValue1 = now.Add(time.Hour * time.Duration(-48)).Format(time.RFC3339)
var youngClusterTagValue = now.Format(time.RFC3339)
var oldClusterTagValue2 = now.Add(time.Hour * time.Duration(-25)).Format(time.RFC3339)
var oldClusterTagValue2 = now.Add(time.Hour * time.Duration(-27)).Format(time.RFC3339)

tagEcsCluster(awsSession, cluster1.ClusterArn, tagKey, oldClusterTagValue1)
tagEcsCluster(awsSession, cluster2.ClusterArn, tagKey, youngClusterTagValue)
Expand Down

0 comments on commit ca1a0cb

Please sign in to comment.