Open anthony-c-martin opened 1 week ago
So what is the goal of this issue - just to collect feedback?
My 2 cents:
...(condition ? value : blank)
, I don't think I would immediately understand that its purpose is "conditionally set or omit property".Maybe the bicep spread docs can be modified to more explicitly showcase the "conditionally set property on object" / "conditionally add element to array" usage pattern? I.e. make it more discoverable via internet search (SEO). https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/operator-spread
Maybe add a note to the docs pages for if
and ternary ? :
, mentioning that you cannot use them for these use cases, that you need to use ...
spread instead?
(After discovering the "set or skip" unresolved issue, I settled on a union()
with a ternary ? :
instead.)
@odegroot - thank you for the detailed feedback! I've created #15499 to cover your comments on documentation, and have reworded the original issue text to try and explain the purpose more clearly.
Problem statement
This issue exists generally to track the requirement of being able to conditionally set a property on an object. This is often necessary, because although when authoring in Bicep we don't distinguish between the absence of a value and explicitly setting a value to
null
, some of the services which handle resource deployment (resource providers) do.For example, it might be desirable to conditionally not set a property:
However, if
setFooProp
is false, this is equivalent to writing:Whereas the author may instead intend to have the following instead:
To accomplish the latter option, a more significant refactor is needed. We support this with the spread operator:
Or by refactoring into a variable:
Why is this a new issue?
The requirement for "set-or-skip" was originally being tracked by #387, which is now over 4 years old, and is one of our highest-upvoted issue with many comments. Since then, we've implemented the spread operator (usage docs).
The requirements of the original issue are satisfied with the spread operator, but we wanted to continue to collect feedback about set-or-skip, because of the popularity of the thread. We are having a hard time prioritizing this work because we're not sure whether:
As such we have closed #387 but intend to keep this issue open to track new feedback. Please comment on this issue if you'd like to help us answer the above!
Special-case syntax
Under #387, the original discussion was mostly around introducing a new dedicated syntax - here is a prototype of the syntax example for "set-or-skip" syntax that was being discussed. This is not implemented, and is not something we are currently considering without clear feedback supporting it: