-
Notifications
You must be signed in to change notification settings - Fork 96
211 lines (175 loc) · 7 KB
/
azure-ipam-testing.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: Azure IPAM Testing
run-name: Azure IPAM Deployment & Testing
on:
pull_request:
branches:
- main
env:
ACR_NAME: ${{ vars.IPAM_TEST_ACR }}
IPAM_UI_NAME: ipam-ui-${{ github.run_id }}-${{ github.run_attempt }}
IPAM_ENGINE_NAME: ipam-engine-${{ github.run_id }}-${{ github.run_attempt }}
jobs:
deploy:
name: Deploy Azure IPAM
runs-on: ubuntu-latest
outputs:
ipamURL: ${{ steps.deployScript.outputs.ipamURL }}
ipamUIAppId: ${{ steps.deployScript.outputs.ipamUIAppId }}
ipamEngineAppId: ${{ steps.deployScript.outputs.ipamEngineAppId }}
ipamSuffix: ${{ steps.deployScript.outputs.ipamSuffix }}
ipamResourceGroup: ${{ steps.deployScript.outputs.ipamResourceGroup }}
steps:
- name: Install Deployment Prerequisites
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az, Microsoft.Graph -AllowClobber -Force
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Checkout Azure IPAM Code
uses: actions/checkout@v4
with:
sparse-checkout: |
deploy
engine
ui
- name: Build Azure IPAM Container
run: |
az acr build -r $ACR_NAME -t ipam:${{ github.run_id }}-${{ github.run_attempt }} -f ./Dockerfile.deb .
- name: Update Bicep File
working-directory: deploy
shell: pwsh
run: |
$acrName = "$env:ACR_NAME.azurecr.io"
$containerName = "ipam:${{ github.run_id }}-${{ github.run_attempt }}"
$bicepFile = Get-Content -Path ./modules/appService.bicep
$bicepFile = $bicepFile -replace "azureipam.azurecr.io", $acrName
$bicepFile = $bicepFile -replace "ipam:latest", $containerName
$bicepFile | Out-File -FilePath ./modules/appService.bicep -Force
- name: Deploy Azure IPAM
working-directory: deploy
id: deployScript
shell: pwsh
run: ./deploy.ps1 -Location "westus3" -UIAppName $env:IPAM_UI_NAME -EngineAppName $env:IPAM_ENGINE_NAME
- name: "Upload Logs"
working-directory: logs
id: uploadLogs
env:
AZURE_IPAM_SUFFIX: ${{ steps.deployScript.outputs.ipamSuffix }}
STORAGE_ACCT_RG: ${{ vars.LOGGING_STORAGE_RG }}
STORAGE_ACCT_NAME: ${{ vars.LOGGING_STORAGE_NAME }}
STORAGE_ACCT_CTR: ${{ vars.LOGGING_STORAGE_CTR }}
shell: pwsh
run: |
$archiveName = "IPAM-RUN(${{ github.run_id }})-ATTEMPT(${{ github.run_attempt }})-SUFFIX($env:AZURE_IPAM_SUFFIX).zip"
Compress-Archive -Path ./* -DestinationPath /tmp/$archiveName
$storage = Get-AzStorageAccount -Name $env:STORAGE_ACCT_NAME -ResourceGroupName $env:STORAGE_ACCT_RG
$context = $storage.Context
$uploadDetails = @{
File = "/tmp/$archiveName"
Container = $env:STORAGE_ACCT_CTR
Blob = $archiveName
Context = $context
StandardBlobTier = "Hot"
}
Set-AzStorageBlobContent @uploadDetails
Write-Output "logFile=$archiveName" >> $Env:GITHUB_OUTPUT
- name: "Output Azure IPAM Deployment Details"
env:
DEPLOYMENT_DETAILS: ${{ steps.uploadLogs.outputs.deployDetails }}
shell: pwsh
run: |
$deployDetails = @{
GITHUB_RUN_ID = "${{ github.run_id }}(${{ github.run_attempt }})"
IPAM_SUFFIX = "${{ steps.deployScript.outputs.ipamSuffix }}"
IPAM_UI_APP_ID = "${{ steps.deployScript.outputs.ipamUIAppId }}"
IPAM_ENGINE_APP_ID = "${{ steps.deployScript.outputs.ipamEngineAppId }}"
IPAM_URL = "${{ steps.deployScript.outputs.ipamURL }}"
IPAM_LOG_FILE = "${{ steps.uploadLogs.outputs.logFile }}"
}
Write-Host "-------------------"
Write-Host "Deployment Details:"
Write-Host "-------------------"
Write-Host ($deployDetails | Format-Table | Out-String) -NoNewline
Write-Host "-------------------"
- name: "Sleep for 5 Minutes"
shell: pwsh
run: Start-Sleep -s 300
test:
name: Test Azure IPAM
runs-on: ubuntu-latest
needs: [ deploy ]
steps:
- name: Install Testing Prerequisites
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az, Pester -AllowClobber -Force
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Checkout Azure IPAM Code
uses: actions/checkout@v4
with:
sparse-checkout: |
tests
- name: Test Azure IPAM w/ Pester
working-directory: tests
env:
IPAM_RESOURCE_GROUP: ${{ needs.deploy.outputs.ipamResourceGroup }}
IPAM_URL: ${{ needs.deploy.outputs.ipamURL }}
IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }}
shell: pwsh
run: |
Import-Module Pester -PassThru
$pesterSettings = @{
Run = @{
Path = "./azureipam.tests.ps1"
PassThru = $true
SkipRemainingOnFailure = "Run"
}
Output = @{
Verbosity = "Detailed"
}
}
$pesterConfig = New-PesterConfiguration -Hashtable $pesterSettings
Invoke-Pester -Configuration $pesterConfig
cleanup:
name: Cleanup Azure IPAM
runs-on: ubuntu-latest
needs: [ deploy, test ]
steps:
- name: Install Cleanup Prerequisites
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az -AllowClobber -Force
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name : Remove Azure IPAM Resources
shell: pwsh
run: |
Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force
- name : Remove Azure IPAM Identities
shell: pwsh
run: |
$tenantId = (Get-AzContext).Tenant.Id
$scope = "/providers/Microsoft.Management/managementGroups/$tenantId"
$uiApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }}
$engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }}
$engineSpn = Get-AzADServicePrincipal -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }}
Remove-AzRoleAssignment -ObjectId $engineSpn.Id -Scope $scope -RoleDefinitionName Reader
$engineSpn | Remove-AzADServicePrincipal
$uiApp | Remove-AzADApplication
$engineApp | Remove-AzADApplication
- name: "Remove Azure IPAM Container"
run: |
az acr repository delete --name $ACR_NAME --repository ipam --yes