Skip to content

528 add deploy workflow #625

528 add deploy workflow

528 add deploy workflow #625

name: Delete Review App
on:
pull_request:
types: [closed]
branches: [main]
jobs:
delete-review-app:
name: Delete Review App ${{ github.event.pull_request.number }}
concurrency: deploy_review_${{ github.event.pull_request.number }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
runs-on: ubuntu-latest
environment: review
steps:
- uses: actions/checkout@v3
- name: Extract configuration from tfvars
id: config
run: |
KEY_VAULT_NAME=$(jq -r '.key_vault_name' $TFVARS)
PAAS_SPACE=$(jq -r '.paas_space' $TFVARS)
if [ -z "$KEY_VAULT_NAME" ]; then
echo "::error ::Failed to extract key_vault_name from $TFVARS"
exit 1
fi
if [ -z "$PAAS_SPACE" ]; then
echo "::error ::Failed to extract paas_space from $TFVARS"
exit 1
fi
echo ::set-output name=key_vault_name::$KEY_VAULT_NAME
echo ::set-output name=paas_space::$PAAS_SPACE
shell: bash
env:
TFVARS: workspace_variables/review.tfvars.json
working-directory: terraform/paas
- uses: Azure/login@v1
with:
creds: ${{ secrets.azure_credentials }}
- uses: Azure/get-keyvault-secrets@v1
id: get_secrets
with:
keyvault: ${{ steps.config.outputs.key_vault_name }}
secrets: "TFSTATE-CONTAINER-ACCESS-KEY,PAAS-USER,PAAS-PASSWORD"
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.0.10
terraform_wrapper: false
- name: Set Environment variables
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
TF_STATE_FILE=review/review-pr-$PR_NUMBER.tfstate
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "TF_STATE_FILE=$TF_STATE_FILE" >> $GITHUB_ENV
pr_state_file=$(az storage blob list -c faltrn-tfstate \
--account-key ${{ steps.get_secrets.outputs.TFSTATE-CONTAINER-ACCESS-KEY }} \
--account-name "s165d01faltrntfstatedv" \
--prefix $TF_STATE_FILE --query "[].name" -o tsv)
if [ -n "$pr_state_file" ]; then echo "TF_STATE_EXISTS=true" >> $GITHUB_ENV; fi;
- name: Terraform
if: env.TF_STATE_EXISTS == 'true'
id: terraform
run: |
make ci review terraform-destroy
env:
ARM_ACCESS_KEY: ${{ steps.get_secrets.outputs.TFSTATE-CONTAINER-ACCESS-KEY }}
TF_VAR_azure_sp_credentials_json: ${{ secrets.azure_credentials }}
TF_VAR_flt_docker_image: "ghcr.io/dfe-digital/find-a-lost-trn:no-tag"
pr_id: ${{ github.event.pull_request.number }}
shell: bash
- name: Delete tf state file
if: env.TF_STATE_EXISTS == 'true'
run: |
az storage blob delete -c faltrn-tfstate --name ${{ env.TF_STATE_FILE }} \
--account-key ${{ steps.get_secrets.outputs.TFSTATE-CONTAINER-ACCESS-KEY }} \
--account-name "s165d01faltrntfstatedv"