[Workflow] Cleanup PR Workspaces #1683
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "[Workflow] Cleanup PR Workspaces" | |
on: | |
schedule: | |
# 6am and 6pm every day except Sundays | |
- cron: '0 6,18 * * 0-6' | |
permissions: | |
contents: read | |
security-events: none | |
pull-requests: none | |
actions: none | |
checks: none | |
deployments: none | |
issues: none | |
packages: none | |
repository-projects: none | |
statuses: none | |
jobs: | |
terraform_environment_cleanup: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
- uses: unfor19/install-aws-cli-action@e8b481e524a99f37fbd39fdc1dcb3341ab091367 # v1.0.7 | |
- name: Get terraform version | |
id: set-terraform-version | |
uses: ministryofjustice/opg-github-actions/.github/actions/[email protected] | |
with: | |
terraform_directory: "./terraform/environment" | |
- uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # tag=v2.0.3 | |
with: | |
terraform_version: ${{ steps.set-terraform-version.outputs.version }} | |
terraform_wrapper: false | |
- name: Configure AWS Credentials For Terraform | |
uses: aws-actions/configure-aws-credentials@50ac8dd1e1b10d09dac7b8727528b91bed831ac0 # v3.0.2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }} | |
aws-region: eu-west-1 | |
role-duration-seconds: 3600 | |
role-session-name: OPGLPATerraformGithubAction | |
- uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Install Terraform Workspace Manager | |
run: | | |
wget https://github.com/ministryofjustice/opg-terraform-workspace-manager/releases/download/v0.3.2/opg-terraform-workspace-manager_Linux_x86_64.tar.gz -O $HOME/terraform-workspace-manager.tar.gz | |
sudo tar -xvf $HOME/terraform-workspace-manager.tar.gz -C /usr/local/bin | |
sudo chmod +x /usr/local/bin/terraform-workspace-manager | |
- name: Terraform Init | |
run: terraform init -input=false | |
working-directory: ./terraform/environment | |
- name: Destroy PR Terraform Workspaces | |
working-directory: ./terraform/environment | |
env: | |
TF_VAR_pagerduty_token: ${{ secrets.PAGERDUTY_TOKEN }} | |
run: | | |
../../scripts/pipeline/workspace_cleanup/workspace_cleanup.sh $(terraform-workspace-manager -protected-workspaces=true -aws-account-id=050256574573 -aws-iam-role=opg-lpa-ci) |