Destroy Test (Test Account) Environment CRON #416
This file contains hidden or 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: 'Destroy Test (Test Account) Environment CRON' | |
| on: | |
| schedule: | |
| - cron: 59 17 * * 1-5 # utc time | |
| permissions: | |
| pull-requests: write | |
| id-token: write # This is required for requesting the JWT | |
| contents: read # This is required for actions/checkout | |
| jobs: | |
| remove_edge_associations: | |
| name: Remove Lambda@Edge Associations | |
| uses: ./.github/workflows/cleanup-cloudfront-edge-associations.yml | |
| with: | |
| sandbox_workspace: ndr-test | |
| lambda_function_name: 'ndr-test_EdgePresignLambda' | |
| python_version: 3.11 | |
| build_branch: main | |
| environment: test | |
| secrets: | |
| AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }} | |
| cleanup_versions_process: | |
| name: Cleanup Versions Process | |
| uses: ./.github/workflows/cleanup-appconfig-and-lambda-layer-versions.yml | |
| with: | |
| build_branch: main | |
| sandbox: ndr-test | |
| environment: test | |
| python_version: 3.11 | |
| secrets: | |
| AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }} | |
| terraform_destroy_process: | |
| runs-on: ubuntu-latest | |
| environment: test | |
| needs: [cleanup_versions_process] | |
| strategy: | |
| matrix: | |
| # Can't use an env var here unfortunately, we will have to update here with new sandbox environments | |
| sandbox-name: [ndr-test] | |
| steps: | |
| # Checkout the repository to the GitHub Actions runner | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} | |
| role-skip-session-tagging: true | |
| aws-region: ${{ vars.AWS_REGION }} | |
| mask-aws-account-id: true | |
| - name: View AWS Role | |
| run: aws sts get-caller-identity | |
| # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.11.4 | |
| terraform_wrapper: false | |
| - name: Terraform Init | |
| id: init | |
| run: terraform init -backend-config=backend-test.conf | |
| working-directory: ./infrastructure | |
| shell: bash | |
| - name: Terraform Set Workspace | |
| id: workspace | |
| run: terraform workspace select ${{ matrix.sandbox-name }} | |
| working-directory: ./infrastructure | |
| shell: bash | |
| - name: Pre-cleanup AWS Backup Recovery Points | |
| run: | | |
| RECOVERY_POINTS=$(aws backup list-recovery-points-by-backup-vault \ | |
| --backup-vault-name ${{ matrix.sandbox-name }}_backup_vault \ | |
| --region eu-west-2 \ | |
| --query 'RecoveryPoints[*].RecoveryPointArn' \ | |
| --output text) | |
| for ARN in $RECOVERY_POINTS; do | |
| echo "Deleting recovery point: $ARN" | |
| aws backup delete-recovery-point \ | |
| --backup-vault-name ${{ matrix.sandbox-name }}_backup_vault \ | |
| --recovery-point-arn $ARN \ | |
| --region eu-west-2 | |
| done | |
| - name: Terraform Destroy | |
| id: destroy | |
| run: terraform destroy -auto-approve -var-file="${{ vars.TF_VARS_FILE }}" | |
| working-directory: ./infrastructure |