Skip to content

Commit

Permalink
Reworked Go func to del old projects
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpalamarchuk committed Nov 6, 2019
1 parent a9db806 commit 89e6494
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 186 deletions.
11 changes: 8 additions & 3 deletions modules/project_cleanup/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Old Project Cleanup Utility Module

This module schedules a job to clean up GCP projects older than a specified length of time, that match a particular key-value pair. This job runs every 5 minutes via Google Cloud Scheduled Functions. Please see the [utility's readme](./function_source/README.md) for more information as to its operation and configuration.
This module schedules a job to clean up GCP projects older than a specified length of time, that match a particular labels. This job runs every 5 minutes via Google Cloud Scheduled Functions. Please see the [utility's readme](./function_source/README.md) for more information as to its operation and configuration.

## Requirements

Expand All @@ -21,12 +21,17 @@ The following services must be enabled on the project housing the cleanup functi

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| job\_schedule | Cleaner function run frequency, in cron syntax | string | `"*/5 * * * *"` | no |
| max\_project\_age\_in\_hours | The maximum number of hours that a GCP project, selected by `target_tag_name` and `target_tag_value`, can exist | number | `"6"` | no |
| organization\_id | The organization ID whose projects to clean up | string | n/a | yes |
| project\_id | The project ID to host the scheduled function in | string | n/a | yes |
| region | The region the project is in (App Engine specific) | string | n/a | yes |
| target\_tag\_name | The name of a tag to filter GCP projects on for consideration by the cleanup utility | string | `"cft-ephemeral"` | no |
| target\_tag\_value | The value of a tag to filter GCP projects on for consideration by the cleanup utility | string | `"true"` | no |
| target\_excluded\_labels | Map of project lablels that won't be deleted. | map(string) | `<map>` | no |
| target\_folder\_id | Folder ID to delete all projects under. | string | `""` | no |
| target\_included\_labels | Map of project lablels that will be deleted. | map(string) | `<map>` | no |
| target\_tag\_name | The name of a tag to filter GCP projects on for consideration by the cleanup utility (legacy, use `target_included_labels` map instead). | string | `""` | no |
| target\_tag\_value | The value of a tag to filter GCP projects on for consideration by the cleanup utility (legacy, use `target_included_labels` map instead). | string | `""` | no |
| topic\_name | Name of pubsub topic connecting the scheduled projects cleanup function | string | `"pubsub_scheduled_project_cleaner"` | no |

## Outputs

Expand Down
4 changes: 4 additions & 0 deletions modules/project_cleanup/function_source/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go.mod
go.sum
pkg
README.md
11 changes: 7 additions & 4 deletions modules/project_cleanup/function_source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
This is a simple utility that scans a GCP organization for projects matching certain criteria, and enqueues such projects for deletion. Currently supported criteria are the combination of:

- **Age:** Only projects older than the configured age, in hours, will be marked for deletion.
- **Key-Value Pair:** Only projects whose labels contain the provided key-value pair will be marked for deletion.
- **Key-Value Pair Include:** Only projects whose labels contain the provided key-value pair will be marked for deletion.
- **Key-Value Pair Exclude:** Projects whose labels contain the provided key-value pair won't be marked for deletion.
- **Folder ID:** Only projects under this Folder ID will be recursively marked for deletion.

Both of these criteria must be met for a project to be deleted.

Expand All @@ -13,9 +15,10 @@ The following environment variables may be specified to configure the cleanup ut

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| `TARGET_TAG_NAME` | The tag name to match on for identifying projects to delete | string | n/a | yes |
| `TARGET_TAG_VALUE` | The tag value to match on for identifying projects to delete | string | n/a | yes |
| `MAX_PROJECT_AGE_HOURS` | The project age, in hours, at which point deletion should be considered | integer | n/a | yes |
| `TARGET_EXCLUDED_LABELS` | Labels to match on for identifying projects to avoid deletion | string | n/a | no |
| `TARGET_FOLDER_ID` | Folder ID to delete prjojects under | string | n/a | yes |
| `TARGET_INCLUDED_LABELS` | Labels to match on for identifying projects to delete | string | n/a | no |
| `MAX_PROJECT_AGE_HOURS` | The project age, in hours, at which point deletion should be considered | integer | n/a | no |

## Required Permissions

Expand Down
115 changes: 0 additions & 115 deletions modules/project_cleanup/function_source/go.sum

This file was deleted.

Loading

0 comments on commit 89e6494

Please sign in to comment.