Skip to content

jq: error: null (null) has no keys for any template without a parameters object #956

Description

@Agger1995

Describe the bug

Given a parameterless resource template, when attempting to push or validate the template using the AzOps pipelines, the jq statement throws an error statement in the pipeline log.
jq: error (at <stdin>:76): null (null) has no keys

This is not super critical, as the Powershell ConvertFrom-Json -AsHashtable seems to handle the error case just fine, however the error log could be interpreted as an actual fault.

Scripts in question:

Steps to reproduce

  1. A parameterless main.bicep:
var location = 'westeurope'

resource example 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: 'st${uniqueString(resourceGroup().id)}'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}
  1. Build it and show Bicep omits parameters entirely rather than emitting {}:
$ bicep build main.bicep --outfile main.json
$ jq 'has("parameters")' main.json
false
$ jq '.parameters | with_entries(select(.value.defaultValue == null))' main.json
jq: error: null (null) has no keys

Note:
The is not a bicep specific error, and is even reproducible with the following bare-bones ARM template:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": []
}

Proposed Solution:

Add a safeguard to the jq statement, which defaults to an empty object in case .parameters does not exist:

Old: .parameters | with_entries(select(.value.defaultValue == null))
New: .parameters // {} | with_entries(select(.value.defaultValue == null))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions