diff --git a/.github/workflows/cancel-subscription.yml b/.github/workflows/cancel-subscription.yml index 407596e6..a4c1ea4d 100644 --- a/.github/workflows/cancel-subscription.yml +++ b/.github/workflows/cancel-subscription.yml @@ -4,6 +4,19 @@ on: pull_request: types: - closed + paths: + - "**.bicep" + - "tests/pester/**.ps1" + workflow_dispatch: + inputs: + manualRun: + description: "Manually Run" + required: false + default: false + type: boolean + subName: + description: "Subscription Name to Cancel" + required: false env: ARM_TENANT_ID: "${{ secrets.ARM_TENANT_ID }}" @@ -31,7 +44,8 @@ jobs: enable-AzPSSession: true allow-no-subscriptions: true - - name: Cancel Subscription + - name: Cancel Subscription Via PR Close + if: ${{ inputs.manualRun }} == false id: cancel uses: azure/powershell@v1 with: @@ -49,3 +63,21 @@ jobs: Update-AzSubscription -SubscriptionId "$($subToCancel.SubscriptionId)" -Action "Cancel" azPSVersion: "latest" + - name: Cancel Subscription Via Manual Run + if: ${{ inputs.manualRun }} == true + id: cancel + uses: azure/powershell@v1 + with: + inlineScript: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az.Subscription -Force + Update-AzConfig -DisplayBreakingChangeWarning $false + $subToCancel = Get-AzSubscription -SubscriptionName "sub-blzv-tests-pr-${{ inputs.subName }}" + Write-Host "Subscription to Cancel: $($subToCancel.SubscriptionId)" -ForegroundColor Cyan + Write-Host "" + Write-Host "Moving Subscription to Management Group: bicep-lz-vending-automation-decom..." -ForegroundColor Yellow + New-AzManagementGroupSubscription -GroupName "bicep-lz-vending-automation-decom" -SubscriptionId "$($subToCancel.SubscriptionId)" + Write-Host "" + Write-Host "Cancelling Subscription..." -ForegroundColor Yellow + Update-AzSubscription -SubscriptionId "$($subToCancel.SubscriptionId)" -Action "Cancel" + azPSVersion: "latest"