π©πΌβπ»βοΈ Create an Azure App Service #55
This file contains hidden or 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: π𧨠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 ππ₯ |