Skip to content

Commit 0eefc6f

Browse files
committed
Document project cleanup utility
1 parent 6c22ddc commit 0eefc6f

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

‎examples/project_cleanup/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Old Project Cleanup Utility Module
2+
3+
This example 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.
4+
5+
Running this module requires an App Engine app in the specified project/region, which is not handled by this example. More information is in the [root readme](../../README.md#app-engine).
6+
7+
[^]: (autogen_docs_start)
8+
9+
10+
## Inputs
11+
12+
| Name | Description | Type | Default | Required |
13+
|------|-------------|:----:|:-----:|:-----:|
14+
| organization_id | The organization ID whose projects to clean up | string | - | yes |
15+
| project_id | The project ID to host the scheduled function in | string | - | yes |
16+
| region | The region the project is in (App Engine specific) | string | `us-central1` | no |
17+
18+
## Outputs
19+
20+
| Name | Description |
21+
|------|-------------|
22+
| name | The name of the job created |
23+
| project_id | The project ID |
24+
25+
[^]: (autogen_docs_end)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Project Cleanup Utility
2+
3+
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:
4+
5+
- **Age:** Only projects older than the configured age, in hours, will be marked for deletion.
6+
- **Key-Value Pair:** Only projects whose labels contain the provided key-value pair will be marked for deletion.
7+
8+
## Environment Configuration
9+
10+
The following environment variables may be specified to configure the cleanup utility:
11+
12+
| Name | Description | Type | Default | Required |
13+
|------|-------------|:----:|:-----:|:-----:|
14+
| `TARGET_TAG_NAME` | The tag name to match on for identifying projects to delete | string | n/a | yes |
15+
| `TARGET_TAG_VALUE` | The tag value to match on for identifying projects to delete | string | n/a | yes |
16+
| `MAX_PROJECT_AGE_HOURS` | The project age, in hours, at which point deletion should be considered | integer | n/a | yes |
17+
18+
## Required Permissions
19+
20+
This Cloud Function must be run as a Service Account with the `owner` role at an organization level.

‎examples/project_cleanup/function_source/main.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
// Copyright 2019 Google LLC
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
Copyright 2019 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
1416

1517
package project_cleaner
1618

0 commit comments

Comments
 (0)