Azure / Azure/arm-template-whatif

WhatIf ignores conditional deployment check

Open
#433 0 comments 0 reactions 0 assignees View on GitHub
Needs: Triage :mag:
Dominant language
HTML
Stars
101
Forks
21
Avg merge
3h 35m
Merged PRs (30d)
1

Description

**Bicep version**

Bicep CLI version 0.42.1 (caea9302e8)

**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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running `az deployment mg what-if --management-group-id mymanagementgroup --template-file main.bicep` with the supplied `main.bicep` and `modules/test.bicep` files, then compare the result with an actual deployment. Trace how What-If evaluates the conditional module and its scope expression; done means the false module is skipped without the invalid subscription identifier error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.