Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRMP-919 [Fix]: Add missing checks for distribution id #196

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions .github/workflows/terraform-destroy-dev-environments-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
environment: development
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
Expand Down Expand Up @@ -53,16 +54,17 @@ jobs:
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
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
Expand All @@ -86,31 +88,6 @@ jobs:
working-directory: ./infrastructure
shell: bash

- name: Get CloudFront Distribution ID
id: cloudfront
run: |
aws cloudfront list-distributions > distributions.json
distribution_id=$(jq -r --arg origin_id "${{ matrix.sandbox-name }}-lloyd-george-store" \
'.DistributionList.Items[] | select(.Origins.Items[].Id==$origin_id) | .Id' distributions.json | head -n 1)

echo "Distribution ID found: $distribution_id"
echo "DISTRIBUTION_ID=$distribution_id" >> $GITHUB_ENV

# Install dependencies for Python scripts
- name: Install Python and Dependencies
id: dependencies
run: |
python3 -m venv ./venv
./venv/bin/pip3 install --upgrade pip
./venv/bin/pip3 install boto3==1.33.11

# Run script to remove Lambda@Edge associations
- name: Remove Lambda@Edge & CloudFront associations
id: lambda
run: ./venv/bin/python3 -u scripts/remove_edge_associations.py ${{ matrix.sandbox-name }}
env:
LAMBDA_FUNCTION_NAME: '$${{ matrix.sandbox-name }}_EdgePresignLambda'

- name: Terraform Destroy
id: destroy
run: terraform destroy -auto-approve -var-file="${{ vars.TF_VARS_FILE }}"
Expand Down
39 changes: 13 additions & 26 deletions .github/workflows/terraform-destroy-test-environments-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ permissions:
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
Expand All @@ -33,7 +45,7 @@ jobs:
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main

Expand Down Expand Up @@ -66,31 +78,6 @@ jobs:
working-directory: ./infrastructure
shell: bash

- name: Get CloudFront Distribution ID
id: cloudfront
run: |
aws cloudfront list-distributions > distributions.json
distribution_id=$(jq -r --arg origin_id "${{ matrix.sandbox-name }}-lloyd-george-store" \
'.DistributionList.Items[] | select(.Origins.Items[].Id==$origin_id) | .Id' distributions.json | head -n 1)

echo "Distribution ID found: $distribution_id"
echo "DISTRIBUTION_ID=$distribution_id" >> $GITHUB_ENV

# Install dependencies for Python scripts
- name: Install Python and Dependencies
id: dependencies
run: |
python3 -m venv ./venv
./venv/bin/pip3 install --upgrade pip
./venv/bin/pip3 install boto3==1.33.11

# Run script to remove Lambda@Edge associations
- name: Remove Lambda@Edge & CloudFront associations
id: lambda
run: ./venv/bin/python3 -u scripts/remove_edge_associations.py ${{ matrix.sandbox-name }}
env:
LAMBDA_FUNCTION_NAME: '$${{ matrix.sandbox-name }}_EdgePresignLambda'

- name: Terraform Destroy
id: destroy
run: terraform destroy -auto-approve -var-file="${{ vars.TF_VARS_FILE }}"
Expand Down
Loading