-
Notifications
You must be signed in to change notification settings - Fork 756
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
Proposal - simplifying resource referencing (part 1) #2245
Comments
Exposing it as a method has a really nice effect of reducing the number of parameters that you have to pass to the Even though the name |
I lean towards parent and child. with resource it's not possible to get parent reference. as for extension resources in option 1, they start with provider namespaces like Microsoft. can we use that as something which will separate extension from child? |
@miqm that's a good point. I'm inclined to using different functions as it's unambiguous. Also I'd prefer the function names to be more explicit: // child resource
var myChild = storageAcc.childResource('blobServices', 'default')
// extension resource
var myExt = storageAcc.extensionResource('Microsoft.Insights/diagnosticSettings@2020-01-01', 'diags')
// parent resource
var storageAcc = blobServices.parentResource() |
Oh my bad. I read things too quickly and mixed up We have two types of "hierarchies" here (resource nesting and resource extending) and two directions of travel (up and down). In the worst case, we end up with 4 functions. For resource nesting, Where it gets confusing for me is what do we call traversing the extension "hierarchy". What is the name of a resource being extended relative to an extension? The other wrinkle is that resource extending also typically does not use parent/child terminology in any of our docs and other content. Could we fix that/teach users about it? I think the answer is yes here, but would it be going too far? Going up or down the hierarchy, it's technically feasible to distinguish between nesting and extending by inspecting the resource types (aka counting the But does it make sense to combine nesting and extending into a pair of functions if we've already split So I think the big choice we need to make is between these options (ignore names for now):
After that, things should fall into place IMO. With choice 1 above, there's also a tiny risk that we may have missed some rare case by combining the two hierarchy traversals. I can't think of anything, but we would be abstracting concepts that are technically separate in the runtime. @shenglol's point about more explicit function names ( |
idea: what about hving a method for traversing downwards (child, extension) and property (parent, scope) for going upwards? scope in case of classic resources would return resource group. scope of resource group returns subscription. |
It's also worth thinking about what this means for the nested resource scenario. I know that @marcre was keen for us to try to unify deploying children & deploying extensions - e.g.: Child: resource vnet 'Microsoft.Network/virtualNetworks@2020-08-01' = {
name: vnetName
resource subnet 'subnets' = {
name: subnetName
}
} Extension: resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
name: vmName
resource diags 'microsoft.insights/diagnosticSettings@2015-07-01' = {
name: diagsName
}
} If we were to enable this scenario, then conceptually (in Bicep at least), it might also feel confusing to people that with nested resources, there's a single hierarchy, but outside of nested resources, there are 2 hierarchies. e.g. using the above two examples: // these two references are equivalent
var subnet = vnet.child('subnets', subnetName)
var subnet2 = vnet::subnet
// these two references are equivalent, but why do I have to remember to use a different function?
var diags = vm.extension('microsoft.insights/diagnosticSettings@2015-07-01', diagsName)
var diags2 = vm::diags To me, I feel like this leads to two options:
I'm curious to hear whether this changes anything, and if so, which option (or other suggestion!) would be preferred. |
I prefer option 2. Although option 1 feels simpler, in fact it's obscuring the underlying concepts (e.g. the differences between child and extension resources) to a degree that I think it could be more confusing than helpful overall. |
I've revised this spec to remove references to extension resources. There's some benefit to providing similar functionality for them, but I feel like child references are going to be more useful - and it feels we can safely punt this decision. |
The docs page points here for the experimental feature Was a little tricky to find the details here.
|
Hi anthony-c-martin, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! 😄 🦾 |
This bot should close as not planned, not completed... Or just not close things |
Agreed. #10874 |
Is this still happening? |
Don't have a clear ETA as there is a dependency on a lower-level improvement to how we process expressions, but this is very much still on our committed list! |
Also intered on this, noticed this issue is very popular now. Specially regarding RoleAssignments as a module. Hope this get the proper attention a an ETA soon. Thanks for all support. |
This unfortunately won't get done in the current semester, but it's working its way up to the top of the list. Added it to our next semester which runs from March '25 - September '25. |
Proposal - simplifying
resource
referencing (part 1)Part 1 / Part 2
Problem statement
Passing around / obtaining references to resources in a type-safe manner is overly complex. Rather than inventing non-type-safe mechanisms to refer to resources or resource properties, we should provide a first-class syntax for doing so, with full type-safety and editor support.
New 'resource' function
The
az
namespace will expose an additional function namedresource
, which can be used to obtain a reference to a resource within the current scope.The
resource()
function takes the first parameter a string (following the resource type format), and a variable number of arguments based on the number of qualified types in the type string. The semantics and validation for the type string parameter behave exactly as those for the type string in resource declarations.Objects of type
scope
will also expose aresource()
function, which can be used similarly to obtain a reference to a resource at a different scope.Examples
Global function
Scope function
Use to set parent property
Use to set scope property
Notes
existing
keyword, but as a more convenient one-liner.The 'child' function on a resource
All resources will expose an additional function named
child
, which can be used to obtain a reference to a child resource of a given type.The
child()
function takes a string for the first parameter (following the nested resource type format), and a second argument for the child resource name.Examples
Obtaining child resource references
EDIT 5/28/21: Added info on
child()
function, removed proposal for extension resourcesThe text was updated successfully, but these errors were encountered: