JulianHayward / Azure-MG-Sub-Governance-Reporting

Azure Governance Visualizer aka AzGovViz is a PowerShell script that captures Azure Governance related information such as Azure Policy, RBAC (a lot more) by polling Azure ARM, Storage and Microsoft Graph APIs.
MIT License
817 stars 295 forks source link

Key cannot be null in GitHub action #178

Closed reza8iucs closed 1 year ago

reza8iucs commented 1 year ago

Hi,

Starting two weeks ago we are seeing the following error in GitHub action that deploys the report to an Azure Site.

Verify 'AzAPICall' (1.1.68)
Get-Package: No match was found for the specified search criteria and module names
'AzAPICall'.

and also:


OperationStopped: 
Line |
  88 |  …         if (-not $htRoleDefinitionIdsUsedInPolicy.($roledefinitionId) …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Key cannot be null. (Parameter 'key')
Error: Error: The process '/usr/bin/pwsh' failed with exit code 1

Any idea how to solve this ?

Thanks


`Run azure/powershell@v1
Validating inputs
Module Az latest installed from hostedAgentFolder
Initializing Az Module
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command Test-Path (Join-Path /usr/share az_*)
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command try {
            $ErrorActionPreference = "Stop"
            $WarningPreference = "SilentlyContinue"
            $output = @{}
            $data = Get-Module -Name Az -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
            $output['AzVersion'] = $data.Version.ToString()
            $output['Success'] = "true"
        }
        catch {
            $output['Error'] = $_.exception.Message
        }
        return ConvertTo-Json $output
True
{
  "AzVersion": "9.3.0",
  "Success": "true"
}
Initializing Az Module Complete
Running Az PowerShell Script
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command /home/runner/work/_temp/0085079f-5ed2-4d6d-bd52-155b24c14cb1.ps1
Start AzGovViz 30-Mar-20[23](https://github.com/contoso/WiseGovViz/actions/runs/4560940643/jobs/8046360252#step:5:24) 05:30:58 (#v6_major_20230203_2)
Checking PowerShell edition and version
  PS check passed : (Major[7]; Minor[2] gt 0); (minimum supported version '7.0.3')
  PS Edition: Core; PS Version: 7.2.10
  PS Version check succeeded
Getting orphaned resources (ARG)
 Getting orphaned microsoft.resources/subscriptions/resourceGroups for 13 Subscriptions
 Getting orphaned microsoft.network/networkSecurityGroups for 13 Subscriptions
 Getting orphaned microsoft.network/routeTables for 13 Subscriptions
 Getting orphaned microsoft.network/networkInterfaces for 13 Subscriptions
 Getting orphaned microsoft.compute/disks for 13 Subscriptions
 Getting orphaned microsoft.network/publicIpAddresses for 13 Subscriptions
 Getting orphaned microsoft.network/loadBalancers for 13 Subscriptions
 Getting orphaned microsoft.compute/availabilitySets for 13 Subscriptions
 Getting orphaned microsoft.web/serverfarms for 13 Subscriptions
  8 orphaned microsoft.network/networkSecurityGroups found
  5 orphaned microsoft.network/loadBalancers found
  4 orphaned microsoft.network/publicIpAddresses found
  17 orphaned microsoft.compute/disks found
  11 orphaned microsoft.resources/subscriptions/resourceGroups found
  8 orphaned microsoft.network/networkInterfaces found
  0 orphaned microsoft.web/serverfarms found
  0 orphaned microsoft.compute/availabilitySets found
  3 orphaned microsoft.network/routeTables found
 Found 56 orphaned Resources
 Exporting OrphanedResources CSV '/home/runner/work/WiseGovViz/WiseGovViz/wiki/AzGovViz_***_ResourcesOrphaned.csv'
Getting orphaned resources (ARG) processing duration: 0.03[26](https://github.com/contoso/WiseGovViz/actions/runs/4560940643/jobs/8046360252#step:5:27)561833333333 minutes (1.959371 seconds)
Caching built-in Policy and RBAC Role definitions
 406 built-in Role definitions returned
 8[32](https://github.com/contoso/WiseGovViz/actions/runs/4560940643/jobs/8046360252#step:5:33) static Policy definitions returned
 93 built-in PolicySet definitions returned
 2055 built-in Policy definitions returned
OperationStopped: 
Line |
  88 |  …         if (-not $htRoleDefinitionIdsUsedInPolicy.($roledefinitionId) …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Key cannot be null. (Parameter 'key')
Error: Error: The process '/usr/bin/pwsh' failed with exit code 1`
JulianHayward commented 1 year ago

@reza8iucs thanks for reporting, but please check the releases when running into issues :) issue: https://github.com/JulianHayward/Azure-MG-Sub-Governance-Reporting/issues/175 fix: https://github.com/JulianHayward/Azure-MG-Sub-Governance-Reporting/releases

reza8iucs commented 1 year ago

Thanks Julian. Can you point me to the instructions on how to update my repo with the latest release of yours?

JulianHayward commented 1 year ago

compare https://github.com/JulianHayward/Azure-MG-Sub-Governance-Reporting/tree/master/.github/workflows (which ever you use) and replace https://github.com/JulianHayward/Azure-MG-Sub-Governance-Reporting/blob/master/pwsh/AzGovVizParallel.ps1 then you should be all set.

I recognize we need an update guidance..

reza8iucs commented 1 year ago

Thanks Julian. I only replaced my AzGovVizParallel.ps1 with the new version and it solved the problem.

Yeah an update guide for those who imported from your repository into their own private repositories would be great. I scratched my head today for a while trying to figure this out and ended up doing it manually.

Thanks again!