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
394 stars 85 forks source link

Unable to set parameter defaults option with type object #1355

Closed dkaubar closed 2 years ago

dkaubar commented 2 years ago

Description of the issue

Azure pipelines fail to expand and use bicep template with error: Failed to expand bicep source '...\application-insights.bicep'. Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file '...\application-insights.bicep' was not valid. An error occurred evaluating expression '[parameters('resourceTags')]' line 0. The parameter named 'resourceTags' was not set or a defaultValue was defined."

in ps-rule.yaml we have it defined as (took example from https://github.com/Azure/PSRule.Rules.Azure/blob/0f63b3fe7c42a86607cbc9dd86699c90f97d32ac/tests/PSRule.Rules.Azure.Tests/ps-rule-options.yaml):

  AZURE_BICEP_FILE_EXPANSION: true
  AZURE_BICEP_FILE_EXPANSION_TIMEOUT: 60
  AZURE_PARAMETER_DEFAULTS:
    ...
    resourceTags:
      env: "test"
    #string parameters seem to work fine

.bicep template have these params:

param applicationInsightsName string
param location string = resourceGroup().location
param sharedRgName string
param logAnalyticsWorkspace string
param resourceTags object

pipeline task:

      - task: ps-rule-assert@1
        displayName: "Run PSRule scan"
        inputs:
          path: "$(System.DefaultWorkingDirectory)"
          inputType: "repository"
          inputPath: "$(projectDirectory)/bicep/*.bicep"
          source:
          modules: "PSRule.Rules.Azure"
          outputFormat: "NUnit3"
          outputPath: "$(Pipeline.Workspace)/PSRule/ps-rule-results.xml"

To Reproduce

Steps to reproduce the issue:

run Azure DevOps pipeline with above configuration targeting .bicep template that has input parameter with type object

Expected behaviour

Default parameter value for type Object is passed from ps-rule.yaml file

Error output

Failed to expand bicep source '...\application-insights.bicep'. Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file '...\application-insights.bicep' was not valid. An error occurred evaluating expression '[parameters('resourceTags')]' line 0. **The parameter named 'resourceTags' was not set or a defaultValue was defined.**"

Module in use and version:

From Azure DevOps pipeline:

Using PSRule v2.0.0+ae35a2ed4f7463f36a1f2a1ea1901b9cc932d5e9
Using PSRule.Rules.Azure v1.14.0

Additional context

BernieWhite commented 2 years ago

@dkaubar Thank you for reporting this. Appears to be an issue with the parameters of object type.

BernieWhite commented 2 years ago

@dkaubar This should be fixed in v1.14.1.