microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.
https://microsoft.github.io/PSRule/v2/
MIT License
390 stars 51 forks source link

Bicep was not valid. Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken #1418

Closed Gordonby closed 1 year ago

Gordonby commented 1 year ago

Description of the issue

I am encountering an issue running PSRule.Rules.Azure using PSRule 2.6 and 2.7 in my GitHub workflow.

Unable to expand resources because the source file '/home/runner/work/AKS-Construction/AKS-Construction/bicep/main.bicep' was not valid. Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.

To Reproduce

Use the param file https://github.com/Azure/AKS-Construction/blob/main/.github/workflows_dep/AksDeploy-ByoVnet.parameters.json

Module in use and version:

Additional context

Workflow result : https://github.com/Azure/AKS-Construction/actions/runs/4009804697 Workflow file: https://github.com/Azure/AKS-Construction/blob/main/.github/workflows/ByoVnetCI.yml#L86 PSRule settings: https://github.com/Azure/AKS-Construction/blob/main/ps-rule.yaml

github-actions[bot] commented 1 year ago

Thanks for raising your first issue, the team appreciates the time you have taken 😉

BernieWhite commented 1 year ago

@Gordonby Thanks for reporting the issue. Using an older version of Bicep CLI such as v0.11.x would be a temporary workaround until we fix the issue. The structure of the generated ARM code changed around this time.

aavdberg commented 1 year ago

Getting the same error at a customer:

Error: Unable to expand resources because the source file '/home/runner/work/iac/iac/Azure/Templates/ALZ/LandingZones/Corp/alz-ox-dwh/main/alz-ox-dwh-main.bicep' was not valid. Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.
BernieWhite commented 1 year ago

@aavdberg Can you confirm PSRule for Azure v1.24.1?

aavdberg commented 1 year ago
image