Staging Environment Ready for Testing #37
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: Housekeeping - Destroy Staging on Issue Closed with label "staging" | |
on: | |
issues: | |
types: [closed] | |
permissions: | |
actions: read | |
contents: read | |
issues: write | |
id-token: write | |
jobs: | |
deprovision: | |
name: Deprovisioning Staging environment | |
if: contains(github.event.issue.labels.*.name, 'staging') | |
runs-on: ubuntu-latest | |
environment: STAGE | |
steps: | |
- name: Checkout code | |
uses: actions/[email protected] | |
- name: 'Az CLI Login via OIDC' | |
uses: azure/[email protected] | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Terraform Init | |
run: terraform init | |
working-directory: ./terraform/staging | |
env: | |
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
ARM_USE_OIDC: true | |
- name: Terraform Plan Destroy | |
id: plan_destroy | |
run: terraform plan -destroy -out=tfplan -var 'sql_admin_password=${{ secrets.SA_PASSWORD }}' | |
working-directory: ./terraform/staging | |
env: | |
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
ARM_USE_OIDC: true | |
- name: Check if Destroy is Needed | |
id: check_destroy | |
run: | | |
if terraform show -json tfplan | jq -e '.resource_changes | length == 0'; then | |
echo "No resources to destroy." | |
echo "DESTROY_NEEDED=false" >> $GITHUB_ENV | |
else | |
echo "Resources need to be destroyed." | |
echo "DESTROY_NEEDED=true" >> $GITHUB_ENV | |
fi | |
working-directory: ./terraform/staging | |
- name: Terraform Destroy | |
if: env.DESTROY_NEEDED == 'true' | |
run: terraform destroy -auto-approve -var 'sql_admin_password=${{ secrets.SA_PASSWORD }}' | |
working-directory: ./terraform/staging | |
env: | |
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
ARM_USE_OIDC: true |