Azure / Azure/bicep

Validation fails on resource group that doesn't yet exist

Open
#14,718 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.29.47 (132ade51bc)

**Describe the bug**

Deployment validation fails when a module has a resourceGroup scope for a resource group that doesn't yet exist, but is created in preceding module.

**To Reproduce**

run.bicep
```
module test 'sub-module.bicep' = {
scope: subscription()
name: 'deploy-sub'
params: {
resourceGroupName: 'my-rg'
}
}
```

sub-module.bicep:
```
targetScope = 'subscription'

param resourceGroupName string = 'non-existing-rg'

resource applicationRG 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: resourceGroupName
location: deployment().location
tags: {}
}

module emptyDeployment 'test-empty.bicep' = { // an empty bicep file
name: 'emptyDeployment'
scope: applicationRG
}
```

`az deployment group create --name 'myDeployment' --resource-group 'myResourceGroup' --template-file run.bicep`

Produces:

> {"code": "ResourceGroupNotFound", "message": "Resource group 'my-rg' could not be found."}

**Additional context**

This isn't really a bicep issue, but I expect others to first search in the issues here.

What is interesting; this does work when directly calling `az deployment sub create ...` on the `sub-module.bicep`

Contributor guide

Open the contributing guide

Research direction

Start with the run.bicep, sub-module.bicep, and test-empty.bicep examples, then reproduce the failure with az deployment group create using the commands in the issue. Compare that behavior with az deployment sub create on sub-module.bicep; done means validation no longer reports ResourceGroupNotFound when the resource group is created by the preceding module.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.