diff --git a/.github/scripts/purge-aws-rds-snapshots.sh b/.github/scripts/purge-aws-rds-snapshots.sh new file mode 100755 index 00000000..f9efcc03 --- /dev/null +++ b/.github/scripts/purge-aws-rds-snapshots.sh @@ -0,0 +1,23 @@ +# ------------------------------------------------------------ +# Copyright 2023 The Radius Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ------------------------------------------------------------ + +set -xe + +aws rds describe-db-snapshots --query 'DBSnapshots[].DBSnapshotIdentifier' --output text > snapshots.txt +for rds_snapshot_identifier in $(cat ./snapshots.txt) +do + aws rds delete-db-snapshot --db-snapshot-identifier $rds_snapshot_identifier +done diff --git a/.github/workflows/purge-aws-rds-snapshots.yaml b/.github/workflows/purge-aws-rds-snapshots.yaml new file mode 100644 index 00000000..ad8fd4e3 --- /dev/null +++ b/.github/workflows/purge-aws-rds-snapshots.yaml @@ -0,0 +1,19 @@ +name: Purge AWS RDS DBInstance snapshots +on: + schedule: + # Runs at 00:30 and 12:30 + - cron: "30 0,12 * * *" +jobs: + purge_rds_snapshots: + name: Purge AWS RDS DBInstance snapshots + runs-on: [ubuntu-latest] + steps: + - name: Purge AWS RDS DBInstance snapshots + run: | + ./.github/scripts/purge-aws-rds-snapshots.sh + - name: Create GitHub issue on failure + if: ${{ failure() }} + run: | + gh issue create --title "Purge AWS RDS DBInstance snapshots workflow failed" \ + --body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." \ + --repo ${{ github.repository }}