Output of modules, that are created in a for loop, can not be used in 0.17.1.
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 81
Description
**Bicep version**
Bicep CLI version 0.17.1 (d423d61882)
**Describe the bug**
So I encountered a previous issue which can be found in #10549. This was said to be fixed in 0.17.1, but now it is even more broken. I would like to know if what I am doing will ever be possible or, if not, how I could get around the problem? What I am trying to do is using the output from a module, that contains a for loop. I create, for example, 2 public IPs by calling a module and then I want to use the output inside of a variable (see example below). I don't understand why this doesn't work and would like some help how you guys would make this work?
**To Reproduce**
I have a bicep file that simply creates a Public IP address called publicIpAddress.bicep:
```bicep
@description('The name of the public IP resource.')
param publicIpAddressName string
@description('The Azure region into which the resources should be deployed.')
param location string
@description('The public IP address allocation method.')
param publicIpAddressType string
@description('Name of a public IP address SKU.')
param publicIpAddressSku string
resource publicIpAddress 'Microsoft.Network/publicIPAddresses@2022-07-01' = {
name: toUpper(publicIpAddressName)
location: location
properties: {
publicIPAllocationMethod: publicIpAddressType
}
sku: {
name: publicIpAddressSku
}
}
output publicIPId string = publicIpAddress.id
```
I call this module in another file and would like to use the outputed ID of the public IP address in a variable. See the code below:
```bicep
var frontendIPConfigurationsMapper = [for i in range(0, length(publicIpAddresses)): {
id: ''
name: 'FrontenIPConfig-${i}'
privateIPAddress: ''
privateIPAllocationMethod: 'Dynamic'
privateLinkConfigurationIDOrName: ''
publicIPAddressID: publicIpModule[i].outputs.publicIPId // Linter gives error here
subnetID: ''
}]
module publicIpModule '../../Modules/Network/publicIpAddress/publicIpAddress.bicep' = [for publicIpAddress in publicIpAddresses: {
name: publicIpAddress.name
params: {
publicIpAddressName: publicIpAddress.name
location: publicIpAddress.location
publicIpAddressSku: publicIpAddress.sku
publicIpAddressType: publicIpAddress.type
}
}]
```
The publicIpAddresses parameter that is used above looks like this:
```json
"publicIpAddresses": {
"value": [
{
"name": "FrontendIPConfig-PublicIP-1",
"location": "westeurope",
"sku": "Standard",
"type": "Static"
}
]
}
```
The error that the linter gives (inside the variable at the line where I put the comment) is the following:
`This expression is being used in the for-body of the variable "frontendIPConfigurationsMapper", which requires values that can be calculated at the start of the deployment. The property "outputs" of publicIpModule cannot be calculated at the start. Properties of publicIpModule which can be calculated at the start include "name".bicep(BCP182)`
**Additional context**
Previous issue that I created: #10549
Contributor guide
Assessment
This issue has not been assessed yet.