Skip to content

Commit

Permalink
feat: removal of folder should use the same time constraint used for …
Browse files Browse the repository at this point in the history
…projects (#79)
  • Loading branch information
daniel-cit authored Jun 9, 2022
1 parent 87037dd commit f4ab92b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/project_cleanup/function_source/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ func invoke(ctx context.Context) {
}
}

folderAgeFilter := func(folder *cloudresourcemanager2.Folder) bool {
folderCreatedAt, err := time.Parse(time.RFC3339, folder.CreateTime)
if err != nil {
logger.Printf("Fail to parse CreateTime for folder [%s], skip it. Error [%s]", folder.Name, err.Error())
return false
}
return folderCreatedAt.Before(resourceCreationCutoff)
}

removeFolder := func(folder *cloudresourcemanager2.Folder) {
folderId := folder.Name
removeFirewallPolicies(folderId)
Expand All @@ -363,7 +372,7 @@ func invoke(ctx context.Context) {
recursion(folder, recursion)
}
removeProjectsInFolder(folderId)
if folder.Parent != fmt.Sprintf("folders/%s", rootFolderId) && folder.Name != fmt.Sprintf("folders/%s", rootFolderId) {
if folder.Parent != fmt.Sprintf("folders/%s", rootFolderId) && folder.Name != fmt.Sprintf("folders/%s", rootFolderId) && folderAgeFilter(folder) {
removeFolder(folder)
}
return nil
Expand Down

0 comments on commit f4ab92b

Please sign in to comment.