Azure / PSRule.Rules.Azure

Rules to validate Azure resources and infrastructure as code (IaC) using PSRule.
https://azure.github.io/PSRule.Rules.Azure/
MIT License
389 stars 84 forks source link

PSRule failing on pipeline task #2089

Closed maxricketts closed 1 year ago

maxricketts commented 1 year ago

Deploying the same pipeline to two differenet clients i get the below two errors on both. On one client PSRule will still run and give me a pass score and relevant fixes etc.

And the other one will not give me anything.

Should be pretty much two identical deployments.

After the PSRule stage, it deploys with out trouble into azure.

Az CLI and Bicep to the latest versions as of 9th March 2023

Using PSRule v2.7.0 Using PSRule.Rules.Azure v1.25.0

[error]Failed to expand bicep source 'C:\a\1\s.devops\bicep\avd\vm.bicep'. Exception calling "GetBicepResources" with "2" argument(s): "Unable to expand resources because the source file 'C:\a\1\s.devops\bicep\avd\vm.bicep' was not valid. An error occurred evaluating expression '[variables('avdHostsRGName')]' line 131. An error occurred evaluating expression '[format('{0}-{1}hosts-rg', variables('resourcePrefix'), parameters('HostPoolName'))]' line 119. The parameter named 'HostPoolName' was not set or a defaultValue was defined."

Rules processed: 0, failed: 0, errored: 0 Run alm_avd/24394 completed in 00:00:05.3046953 Output written to the following file: 'C:\a\1\s\rule-report.xml' [error]One or more assertions failed.

[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if ([Console]::InputEncoding -is [Text.UTF8Encoding] -and [Console]::InputEncoding.GetPreamble().Length -ne 0) { [Console]::InputEncoding = New-Object Text.UTF8Encoding $false } if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\a_tasks\ps-rule-assert_8804fc31-b62f-4d49-b2a1-c80dc0879dae\2.6.2301031\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\a_tasks\ps-rule-assert_8804fc31-b62f-4d49-b2a1-c80dc0879dae\2.6.2301031\powershell.ps1'''))"'. Finishing: Analyze Azure bicep files

BernieWhite commented 1 year ago

@maxricketts This seems to be related to a required/ mandatory parameter called HostPoolName. Is that incorrect?

maxricketts commented 1 year ago

@BernieWhite - Sorry will this need defining in the PSRule yaml under Azure_Parameter_Defaults

BernieWhite commented 1 year ago

@maxricketts Ok great. So confirming the issue is:

You are defining as value for HostPoolName (which is a required parameter) in AZURE_PARAMETER_DEFAULTS but it is not working.

maxricketts commented 1 year ago

@BernieWhite - Please close this ticket. Error at my end.