Azure / Azure/bicep

Reference resource group that is created via a module

Open
#4,992 8 comments 12 reactions 0 assignees View on GitHub
enhancement revisit
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 2h
Merged PRs (30d)
79

Description

Created this issue based on [#1454](https://github.com/Azure/bicep/issues/1454).

What Im trying to do is within the same deployment, create a resource groupby using a module and then create other resources. When doing so, currently I cant reference the resourcegroup outputs in the scope, since this is disabled. My question is, how can it work in this setup?
I am specifically asking how it can work with a module resource group, since I know that creating the resource resourcegroup in the main template itself will work. For my current usecase, I want to use a precreated module of a resource group:

resourceGroup.bicep :
```bicep
targetScope='subscription'

param resourceGroupName string
param location string

var resourceGroupNameWithSuffix= 'rg-${resourceGroupName}'

resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: resourceGroupNameWithSuffix
location: location
}

output resourceGroupId string = rg.id
output resourceGroupName string = rg.name
```

main.bicep
```bicep
targetScope='subscription'

param resourceGroupName string = 'bb-poc'

var location = deployment().location

module rg '../resources/resourceGroup.bicep' = {
name: 'resourcegroupdeploy'
params:{
location: location
resourceGroupName: resourceGroupName
}
}

module appServicePlanDeployment '../resources/appServicePlan.bicep' = {
name: 'appserviceplandeploy'
scope: resourceGroup(rg.outputs.resourceGroupName)
params:{
appServicePlanName: 'testing'
}
}
```

Current error on the line ```scope: resourceGroup(rg.outputs.resourceGroupName)```
:
```This expression is being used in an assignment to the "scope" property of the "module" type, which requires a value that can be calculated at the start of the deployment. Properties of rg which can be calculated at the start include "name".b```

Contributor guide

Open the contributing guide

Research direction

Start with resourceGroup.bicep and main.bicep, then inspect the module scope handling represented by appServicePlanDeployment and the reported scope diagnostic. Confirm how module outputs are evaluated for deployment scope; done means the resource-group module output can be used to scope the dependent module, with coverage for this example or a documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, infrastructure
Issue type
Feature
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.