-
Notifications
You must be signed in to change notification settings - Fork 762
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
Allow LINQ-style projections from arrays #6930
Comments
@alex-frankel Either of those issues would be excellent for this purpose. I'm curious though - to what extent could the ask be made simpler by introducing it in stages? ##Stage 1 ##Stage 2 Couple it all with richer type inference and this could be a huge step forward for Bicep. |
Sounds good. I'm not sure how realistic the stage 1 shortcut is, but definitely worth considering. Going to close this and track with the other issues. |
Is your feature request related to a problem? Please describe.
I have to deploy several public IP addresses as part of my deployment. I maintain an array variable in my deployment template that lists out this IP address information and all manner of other values (typically because IP addresses correspond with other resources deployed to a number of also-specified subnets). For example, this might look something like this:
I have a great many subnets, but you get the point. It's a central configuration object for both how the subnet is configured, but also general networking details for services that use this particular section. Because it's an array, I can then easily use it to spin up public IP addresses via another module (not detailed here):
All this works without issue - where having a projection, particularly a filter-able one would be useful is later on when I'm actually creating say, an application gateway. Say I need to actually know the name of the public IP address resource that was created earlier. Today this looks like this (knowing that the application gateway subnet is the first element in the array):
The problem isn't in setting this up the first time - it's in maintaining it. Say I don't need the DataExplorer subnet any longer, so I remove the subnet object from the array. This is now broken and I won't know it until I attempt to deploy and either the index is out of range (or worse, it deploys with the wrong information and I don't catch it until something doesn't work much further downstream).
This is a huge maintainability problem.
Describe the solution you'd like
I would like to be able to apply a filterable projection against an array at run-time (bonus points if the Intellisense can work out what I'm doing and provide rich typing support) not unlike what I can do with LINQ statements in C#.
Assuming I can only use those values that are known ahead of time (as is generally true today), I'd like to be able to apply a filter to my
pipNames
to select only the index that pertains to my Application Gateway based on name, like in the following:This would filter the pipNames to only those containing the string (based on how it was built) that matches that created for the Application Gateway. I could easily simplify this can just use the same named variable throughout for a common value as well. If there's a match, I get the name property. If not, it throws and I see that the deployment failed.
Describe the solution you'd really like
My proposal above would likely involve changes to ARM which isn't as likely to happen (though I've got to imagine they'd be well-received given how useful I'd find it). Rather than make those changes in ARM, again, all these values are known upfront (e.g. none is based on the output value of a module), so I'd like to see an extension of the constant folding idea applied to conditions such as this.
Specifically, identify LINQ operations as functions baked into Bicep itself and at build time, run this out in a what-if style fashion and determine what the values would be, then replace my function with those values so the actual ARM deployment is simply correct and using static values, and all the heavy lifting is just done on my own system at build-time.
For those values that are dependent on module outputs (which again cannot be worked out in advance), show an error at build indicating this isn't yet supported, but since this is the pipe dream section of the feature request, defer such projections to be evaluated by ARM at run-time where not possible to determine at build-time locally.
The text was updated successfully, but these errors were encountered: