Azure / Azure/bicep

Feature: Apply lambda functions to looped module outputs

Open
#9,463 0 comments 2 reactions 0 assignees View on GitHub
enhancement Needs: Upvote
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

This is one of [two](https://github.com/Azure/bicep/issues/9462) asks for something similar - two different ways of accomplishing what I'm trying to do, but because they're two different features, I didn't feel a single issue was the best place for each.

I have a dictionary of items keyed by a certificate subject name paired with a collection of values. As part of the deployment, I loop through these with a `for` statement:

```bicep
module SslCertificateIssue './resources/certificate-generation.bicep' = [for (subject, index) in items(CertificateSubjects): {
//...
}]
```

This module outputs a string value of the name of the secret output as stored in Key Vault so I might reference the secret in still other modules. I would like to be able to capture this output for each element in the loop and pass into the array of another module, e.g.:

```bicep
module SslCertificateIssue './resources/certificate-generation.bicep' = [for (subject, index) in items(CertificateSubjects): {
// ...
}]

var SecretNames => map(SslCertificateIssue, issuance => issuance.outputs.SecretName)
```

This yields the error `Directly referencing a resource or module collection is not currently supported. Apply an array indexer to the expression.` which is funny, as this isn't supported either, per my [other ask](https://github.com/Azure/bicep/issues/9462).

Thanks for the consideration!

Since creating this post, I've since realized that one can build a `for` loop, accessing the index there, and assign directly to a variable that I can then pass into the downstream modules. However, while this doesn't indicate any issues at dev-time, this fails at runtime with the error "BCP182: This expression is being used in the for-body of the variable 'SecretNames', which requires values that can be calculated at the start of the deployment." indicating that I cannot use the module outputs here.

As such, I'd request that the lambda functionality be created so as to make very specific functionality more broadly and uniformly applied throughout the Bicep language.

Contributor guide

Open the contributing guide

Research direction

Start with the looped module example using ./resources/certificate-generation.bicep, the SecretName output, and the variable expression that currently produces BCP182. Review the linked issue 9462 for the related request; done should mean a lambda or map operation can transform looped module outputs for downstream modules without deployment-time evaluation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.