Skip to content

WhatIf ignores conditional deployment check #19391

@jocoyo

Description

@jocoyo

Bicep version

Bicep CLI version 0.42.1 (caea930)

Describe the bug

Bicep WhatIf appears to be ignoring the (false) condition on a conditional module deployment and throwing an error once it evaluates the module scope, an expression which would only be valid if the deployment condition resolved to true.

An actual deployment completes succesfully, indicating that the deployment does correctly skip the module.

Unless I'm missing something, this template and conditional deployment logic is correct and was working fine until quite recently (first noticed ~ a week ago).

To Reproduce

A minimal template that reproduces my issue:

targetScope = 'managementGroup'

var assignmentScopeId = '/providers/microsoft.management/managementgroups/mymanagementgroup'

module testModule './modules/test.bicep' = if (contains(
  toLower(assignmentScopeId),
  'resourcegroups/'
)) {
  scope: resourceGroup(split(assignmentScopeId, '/')[2], split(assignmentScopeId, '/')[4])
  name: 'testModule'
}

./modules/test.bicep is just an empty bicep file (so the default targetScope is resourceGroup).

Running:
az deployment mg what-if --management-group-id mymanagementgroup --template-file main.bicep

results in:
InvalidTemplate - Deployment template validation failed: 'The provided value 'microsoft.management' is not valid subscription identifier. Please see https://aka.ms/arm-resource-functions/#resourceid for usage details.'.

The error shows that the whatif is reaching the scope expression (getting the 'microsoft.management' substring which is not expected in that context) when the deployment condition should have resulted in the module whatif evaluation being skipped altogether.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions