Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance cancel workflow #34

Merged
merged 2 commits into from
Dec 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .github/workflows/cancel-subscription.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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:
Expand All @@ -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"