-
Notifications
You must be signed in to change notification settings - Fork 742
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
Support for user defined functions #10465
Conversation
Here is an example of something I would replace with a UDF. I use this to generation the connection string for Cassandra DB, which includes each region. param location string
param secondaryLocations array = []
var secondaryRegions = [for (region, i) in secondaryLocations: {
locationName: contains(region, 'locationName') ? region.locationName : region
failoverPriority: contains(region, 'failoverPriority') ? region.failoverPriority : i + 1
isZoneRedundant: contains(region, 'isZoneRedundant') ? region.isZoneRedundant : isZoneRedundant
}]
var locations = union([
{
locationName: location
failoverPriority: 0
isZoneRedundant: isZoneRedundant
}
], secondaryRegions)
var unwind = [for location in locations: '${toLower(cassandraName)}-${location.locationName}.cassandra.cosmos.azure.com']
var locationString = replace(substring(string(unwind), 1, length(string(unwind))-2), '"', '') |
It would be a small-ish change in the ARM runtime to support user-defined types, and if it were up to me, I would rather put in the effort to close that feature gap than document and field questions about the limitation. But it did get me thinking: because types can contain symbolic references to other types, I can't think of any reason we would allow user-defined types and still disallow references to variables and parameters. Should we look at removing that restriction on UDFs, too? |
I think so - I just wanted to keep the initial implementation as simple as possible. One complexity is that UDFs overloads |
0b06184
to
3f56c3e
Compare
e927a96
to
f678f15
Compare
8f70ea2
to
dcd9d49
Compare
146b537
to
3264f96
Compare
3264f96
to
c6c22ff
Compare
291a851
to
3482a54
Compare
695d128
to
3da786e
Compare
@@ -60,44 +60,53 @@ module moduleWithConditionAndSelfCycle './main.bicep' = if ('foo' == 'bar') { | |||
|
|||
module './main.bicep' = { | |||
//@[007:021) [BCP096 (Error)] Expected a module identifier at this location. (CodeDescription: none) |'./main.bicep'| | |||
//@[007:021) [BCP094 (Error)] This module references itself, which is not allowed. (CodeDescription: none) |'./main.bicep'| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these new diagnostics intentional?
src/Bicep.Core/TypeSystem/DeployTimeConstantViolationVisitor.cs
Outdated
Show resolved
Hide resolved
@@ -48,6 +48,8 @@ public static EmitLimitationInfo Calculate(SemanticModel model) | |||
BlockModuleOutputResourcePropertyAccess(model, diagnostics); | |||
BlockSafeDereferenceOfModuleOrResourceCollectionMember(model, diagnostics); | |||
BlockCyclicAggregateTypeReferences(model, diagnostics); | |||
BlockUserDefinedFunctionsWithoutExperimentalFeaure(model, diagnostics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it's a convenient place to put any sort of ad hoc check. Will raise an issue to rename it.
🤩🎉🚀 |
Support to outer scoped variables and include/import feature would be very useful |
See https://github.com/Azure/bicep/blob/ant/exp/func/src/Bicep.Core.Samples/Files/Functions_LF/main.bicep for a syntax example.
Notes/limitations:
Closes #447
Closes #9239
Microsoft Reviewers: Open in CodeFlow