Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Nullable parameters with JValue null #2535

Closed
BernieWhite opened this issue Nov 15, 2023 · 0 comments · Fixed by #2549
Closed

[BUG] Nullable parameters with JValue null #2535

BernieWhite opened this issue Nov 15, 2023 · 0 comments · Fixed by #2549
Assignees
Labels
bug Something isn't working feature: pre-flight-expansion Issues relating to expansion of ARM and Bicep.
Milestone

Comments

@BernieWhite
Copy link
Collaborator

BernieWhite commented Nov 15, 2023

Updated 2023-11-20: Initial fix is available in v1.31.2. Additional scenarios will be patched in v1.31.3.

Existing rule

No response

Description of the issue

A problem exists evaluating nullable parameter with tryGet when combined with JValue type.

Error messages

Error: Failed to expand bicep source '/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/key-vault/vault/tests/e2e/defaults/main.test.bicep'. Exception calling "GetBicepResources" with "2" argument(s): "Unable to expand resources because the source file '/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/key-vault/vault/tests/e2e/defaults/main.test.bicep' was not valid. An error occurred evaluating expression '[length(variables('secretList'))]' line 849. An error occurred evaluating expression '[coalesce(tryGet(parameters('secrets'), 'secureList'), createArray())]' line 630. Cannot access child value on Newtonsoft.Json.Linq.JValue."

Reproduction

param accessPolicies array?

@secure()
param secrets object?

var formattedAccessPolicies = [for accessPolicy in (accessPolicies ?? []): {
  objectId: accessPolicy.objectId
  tenantId: contains(accessPolicy, 'tenantId') ? accessPolicy.tenantId : tenant().tenantId
  permissions: {}
}]

var secretList = secrets.?secureList ?? []

resource kv 'Microsoft.KeyVault/vaults@2023-07-01' = {
  name: 'keyVault'
  #disable-next-line no-loc-expr-outside-params
  location: resourceGroup().location
  properties: {
    sku: {
      family: 'A'
      name: 'standard'
    }
    tenantId: tenant().tenantId
    accessPolicies: formattedAccessPolicies
  }
}

resource kvSecret 'Microsoft.KeyVault/vaults/secrets@2023-07-01' = [for item in secretList: {
  name: item.name
  properties: {
    value: item.value
  }
}]

Version of PSRule

2.9.0

Version of PSRule for Azure

1.31.0

Additional context

See microsoft/PSRule#1640

@BernieWhite BernieWhite added bug Something isn't working feature: pre-flight-expansion Issues relating to expansion of ARM and Bicep. labels Nov 15, 2023
@BernieWhite BernieWhite added this to the v1.31.2 milestone Nov 15, 2023
@BernieWhite BernieWhite self-assigned this Nov 15, 2023
BernieWhite added a commit to BernieWhite/PSRule.Rules.Azure that referenced this issue Nov 15, 2023
BernieWhite added a commit to BernieWhite/PSRule.Rules.Azure that referenced this issue Nov 20, 2023
@BernieWhite BernieWhite mentioned this issue Nov 20, 2023
4 tasks
@BernieWhite BernieWhite modified the milestones: v1.31.2, v1.31.3 Nov 20, 2023
BernieWhite added a commit to BernieWhite/PSRule.Rules.Azure that referenced this issue Nov 22, 2023
BernieWhite added a commit to BernieWhite/PSRule.Rules.Azure that referenced this issue Nov 22, 2023
@BernieWhite BernieWhite mentioned this issue Nov 22, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature: pre-flight-expansion Issues relating to expansion of ARM and Bicep.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant