-
Notifications
You must be signed in to change notification settings - Fork 42
83 lines (76 loc) · 3.27 KB
/
cancel-subscription.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Cancel Subscription on PR Close
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 }}"
ARM_CLIENT_ID: "${{ secrets.ARM_CLIENT_ID }}"
ARM_CLIENT_SECRET: "${{ secrets.ARM_CLIENT_SECRET }}"
GH_PR_NUMBER: "${{ github.event.number }}"
jobs:
vending:
name: Vending Subscription for Tests and Networking Scenarios
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Azure Login
id: login
uses: azure/login@v2
with:
creds: '{"clientId":"${{ env.ARM_CLIENT_ID }}","clientSecret":"${{ env.ARM_CLIENT_SECRET }}","tenantId":"${{ env.ARM_TENANT_ID }}"}'
enable-AzPSSession: true
allow-no-subscriptions: true
- name: Cancel Subscription Via PR Close
if: ${{ inputs.manualRun == false }}
id: cancel-pr
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az.Subscription -Force
Install-Module Az.Resources -Force
Install-Module Az.Accounts -Force
Update-AzConfig -DisplayBreakingChangeWarning $false
$subToCancel = Get-AzSubscription -SubscriptionName "sub-blzv-tests-pr-${{ env.GH_PR_NUMBER }}"
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"
- name: Cancel Subscription Via Manual Run
if: ${{ inputs.manualRun == true }}
id: cancel-manual
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az.Subscription -Force
Install-Module Az.Resources -Force
Install-Module Az.Accounts -Force
Update-AzConfig -DisplayBreakingChangeWarning $false
$subToCancel = Get-AzSubscription -SubscriptionName "${{ github.event.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"