Update short-circuiting algorithm in Preflight API
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Bicep version**
Bicep CLI version 0.37.4 (27cc8db2ed)
**Describe the bug**
When validating a Bicep deployment using `az stack group validate`, the command completes successfully with no error, even if required parameters are missing or null. In contrast, `az deployment group what-if` fails with a specific error if a required parameter is missing or null. The issue is observed when we are using nested bicep module.
We expect `az stack group validate` and `az deployment group what-if` should have consistent behavior, and should catch the missing parameter issue.
**To Reproduce**
Steps to reproduce the behavior:
Create the following files in a single folder:
`main.bicep`
```typescript
@description('Site configuration object')
param siteConfig object = {}
@description('Optional tags for resources')
param tags object = {}
// Process parameters through module (similar to parameters.bicep)
module params 'parameters.bicep' = {
name: '${deployment().name}-params'
params: {
siteConfig: siteConfig
}
}
// Get processed storage configuration
var storageConfig = params.outputs.storageParams
// Create a module for the storage account to use the processed parameters
module storageDeployment 'storage.bicep' = {
name: '${deployment().name}-storage'
params: {
storageConfig: storageConfig
tags: tags
}
}
output storageAccountId string = storageDeployment.outputs.storageAccountId
output storageAccountName string = storageDeployment.outputs.storageAccountName
```
`main.bicepparam`
```typescript
using './main.bicep'
param siteConfig = {
storage: {
name: 'teststorage001'
sku: {
name: 'Standard_LRS'
}
}
}
param tags = {
Environment: 'Test'
Purpose: 'ValidationTest'
}
```
`parameters.bicep`: this is a nested module for user to maintain all the configuration for the bicep, in the example, I have removed `kind` in the `storageBase`, and expect a deployment failure.
```typescript
// Parameters processing module (similar to module/bicep/parameters.bicep)
import * as types from 'types.bicep'
@description('Site configuration')
param siteConfig object = {}
// Base storage configuration
var storageBase = {
name: 'defaultstoragetest0'
sku: {
name: 'Standard_LRS'
}
}
// Merge site config with base config using union
var storageConfig = union(
storageBase,
siteConfig
)
// Output the processed storage configuration
output storageParams types.StorageConfigType = storageConfig
```
`storage.bicep`: a bicep module to deploy a storage account
```typescript
// Storage account deployment module
import * as types from 'types.bicep'
@description('Storage configuration')
param storageConfig types.StorageConfigType
@description('Optional tags for resources')
param tags object = {}
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: storageConfig.name
location: resourceGroup().location
sku: {
name: storageConfig.sku.name
}
kind: storageConfig.kind
tags: tags
properties: {
accessTier: 'Hot'
allowBlobPublicAccess: false
minimumTlsVersion: 'TLS1_2'
}
}
output storageAccountId string = storageAccount.id
output storageAccountName string = storageAccount.name
```
`type.bicep`: user defined type
```typescript
// Type definitions for the simplified example
@export()
type StorageConfigType = {
@description('Required. Storage account name')
name: string
@description('Required. Storage account SKU')
sku: {
name: ('Standard_LRS' | 'Standard_GRS' | 'Standard_ZRS' | 'Premium_LRS')
}
@description('Required. Storage account kind')
kind: ('Storage' | 'StorageV2' | 'BlobStorage')
}
```
When running `az stack group validate --name teststack --resource-group your-rg --template-file .\main.bicep --parameters .\main.bicepparam --action-on-unmanage detachAll --deny-settings-mode none`, I got:
```json
{
"error": null,
...
"validatedResources": [
{
"id": "/subscriptions/de3c4d5e-af08-451a-a873-438d86ab6f4b/resourceGroups/runyutestbicep/providers/Microsoft.Resources/deployments/teststack-params",
"resourceGroup": "runyutestbicep"
},
{
"id": "/subscriptions/de3c4d5e-af08-451a-a873-438d86ab6f4b/resourceGroups/runyutestbicep/providers/Microsoft.Resources/deployments/teststack-storage",
"resourceGroup": "runyutestbicep"
}
]
}
```
When running `az deployment group what-if --resource-group your-rg --template-file .\main.bicep --parameters .\main.bicepparam`, I got:
```
InvalidTemplate - Deployment template validation failed: 'The provided value for the template parameter 'storageConfig' is not valid. A non-null value for the property 'kind' must be provided, but the property was null or missing. Please see https://aka.ms/arm-syntax-parameters for usage details.'.
```
## Expected Behavior
Both commands should behave consistently, fail validation when `kind` is missing/null
## Actual Behavior
- `az stack group validate` cannot catch the missing `kind` error
- `az deployment group what-if` correctly identifies the missing `kind` error
Contributor guide
Assessment
This issue has not been assessed yet.