diff --git a/.github/workflows/terraform-destroy-dev-environments-cron.yml b/.github/workflows/terraform-destroy-dev-environments-cron.yml index f8909c16..47fca958 100644 --- a/.github/workflows/terraform-destroy-dev-environments-cron.yml +++ b/.github/workflows/terraform-destroy-dev-environments-cron.yml @@ -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 @@ -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 @@ -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 }}" diff --git a/.github/workflows/terraform-destroy-test-environments-cron.yml b/.github/workflows/terraform-destroy-test-environments-cron.yml index a7e7063d..f2efbcee 100644 --- a/.github/workflows/terraform-destroy-test-environments-cron.yml +++ b/.github/workflows/terraform-destroy-test-environments-cron.yml @@ -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 @@ -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 @@ -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 }}"