Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output of modules, that are created in a for loop, can not be used in 0.17.1. #10674

Open
TheCrazyCanian opened this issue May 11, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@TheCrazyCanian
Copy link

Bicep version
Bicep CLI version 0.17.1 (d423d61)

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:

@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:

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:

    "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

@github-project-automation github-project-automation bot moved this to Todo in Bicep May 11, 2023
@ghost ghost added the Needs: Triage 🔍 label May 11, 2023
@TheCrazyCanian TheCrazyCanian changed the title Output of modules, that are created in a for loop, can not be used. Output of modules, that are created in a for loop, can not be used in 0.17.1. May 11, 2023
@shenglol
Copy link
Contributor

The error is by design. Referencing a runtime property in a for loop is never a supported feature due to a limitation of the ARM deployment engine. We added validation for runtime property validation a while ago, but there was a regression that caused the NotImplementedException reported in #10549. The fix was just to bring back the error message.

@github-project-automation github-project-automation bot moved this from Todo to Done in Bicep May 17, 2023
@shenglol shenglol reopened this May 17, 2023
@shenglol
Copy link
Contributor

Leaving this open as an enhancement. We can investigate in the future if there is anything we can do to overcome the ARM deployment engine limitation and add support for runtime property references in loops.

@shenglol shenglol added the enhancement New feature or request label May 17, 2023
@aaronparker
Copy link

Is there an alternative we can use to get to properties of the module output?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

4 participants