Skip to content

πŸ‘©πŸΌβ€πŸ’»β˜οΈ Create an Azure App Service #55

πŸ‘©πŸΌβ€πŸ’»β˜οΈ Create an Azure App Service

πŸ‘©πŸΌβ€πŸ’»β˜οΈ Create an Azure App Service #55

Workflow file for this run

name: πŸš€πŸ§¨ Destroy Infrastructure with Terraform
on:
issues:
types: [closed]
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.TF_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.TF_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.TF_CLIENT_SECRET }}
ARM_TENANT_ID: ${{ secrets.TF_TENANT_ID }}
concurrency:
group: ${{ github.event.issue.number }}
cancel-in-progress: true
permissions:
contents: read
issues: write
jobs:
destroy_terraform_infra:
name: "BOOM! πŸ’₯"
runs-on: ubuntu-latest
steps:
- name: Checkout code πŸ›Ž
uses: actions/checkout@v4
- name: Check for label starting with "issueops:"
run: |
labels=$(echo '${{ toJson(github.event.issue.labels) }}' | jq -r '.[] | select(.name | startswith("issueops:")) | .name')
if [ -n "$labels" ]; then
echo "Label found: $labels"
# label without issueops: prefix
infra_type=$(echo $labels | sed 's/issueops://')
echo "TF_WORKDIR=terraform/$infra_type" >> $GITHUB_ENV
echo "INFRA_TYPE=$infra_type" >> $GITHUB_ENV
else
echo "No label found starting with 'palabra'"
fi
- name: Set up Terraform πŸ’Ό
uses: hashicorp/setup-terraform@v3.1.2
- name: Terraform Init πŸ—
id: init
run: |
terraform init \
-backend-config="resource_group_name=${{ secrets.TF_STATE_RESOURCE_GROUP_NAME }}" \
-backend-config="storage_account_name=${{ secrets.TF_STATE_AZURE_STORAGE_NAME }}" \
-backend-config="container_name=${{ secrets.TF_STATE_CONTAINER_NAME }}" \
-backend-config="key=issue-${{ github.event.issue.number }}-terraform.tfstate" \
-backend-config="access_key=${{ secrets.TF_STATE_STORAGE_ACCESS_KEY }}"
working-directory: ${{ env.TF_WORKDIR }}
- name: Terraform output as JSON
run: |
ouput=$(terraform output -json | jq .)
if [ "$(echo "$output" | jq -e 'length == 0')" == "true" ]; then
exit 1
else
echo "Terraform output is not empty"
fi
- name: Export Terraform Outputs to tfvars
run: |
terraform output -json | jq -r 'to_entries | map("\(.key) = \(.value.value | @json)") | .[]'
terraform output -json | jq -r 'to_entries | map("\(.key) = \(.value.value | @json)") | .[]' > terraform.tfvars
working-directory: ${{ env.TF_WORKDIR }}
- name: Check the content of the terraform.tfvars file
run: cat terraform.tfvars
working-directory: ${{ env.TF_WORKDIR }}
- name: Terraform Destroy 🧨
run: |
terraform destroy -auto-approve \
-var="subscription_id=${{ secrets.TF_SUBSCRIPTION_ID }}"
working-directory: ${{ env.TF_WORKDIR }}
- name: Remove Labels ␑🏷
id: remove-labels
uses: issue-ops/labeler@v2.1.0
with:
action: remove
issue_number: ${{ github.event.issue.number }}
labels: |
deployed πŸš€βœ…
- name: Add Labels 🏷️
id: add-labels
uses: issue-ops/labeler@v2.1.0
with:
action: add
issue_number: ${{ github.event.issue.number }}
labels: |
destroyed πŸš€πŸ”₯