-
Notifications
You must be signed in to change notification settings - Fork 753
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
Simplify properties that are resource references #285
Comments
This is a great point that you are bringing up. This one is a bit more challenging because the subnet is declared as a property not a resource, so bicep doesn't understand how to get an ID from it. Ideally the subnets would be declared as child resources, and then you could get the id as you would like:
The problem is that the vnet resourceType does not handle subnets as child resources particularly well. In theory we could special case what you want to do, but I would prefer to fix the networking APIs to better accommodate this. Does that make sense? Curious what others think about this one |
I kinda like the idea - it implies that the id property is the default property but that would have to then work for every scenario because we lose the option to reference the object in that case. I could see the object wanting to be used in outputs (rare but possible). |
Another option would be to assert that if the user did something like: vnet.subnets[subnetName].id We create a resourceId with the resourceId function as the user requested. It may not be a valid resourceId but that's no different than today when using the resourceId function. I'm struggling to think of a resource, other than subnets where it would be useful though... To @alex-frankel 's point of, maybe we should just fix the RP |
Not getting side-tracked by the fact that subnets are properties, the main point of this issue is to simplify the referencing of resources. Use the NSG reference as an example. In ARM the NSG reference requires a property that is an object with an "networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/.... )]"
} rather than requiring the Bicep to be:
It could be:
There are lots of examples in ARM where resources are referenced like this. |
@askew True, but problem is that no RP is the same. I have seen cases where the reference does not follow that logic and you only have the property in which you put the resource ID as string. AKS for example does this. I guess overall it is a matter if they can make this via some pattern without having to code per RP and would it be confusing for new users or not. Not sharing particular opinion just discussion the topic and my experience with RPs. |
sorry to bump this from months ago, but since it's still open, the current behaviour did kinda burn me today as a newcomer, because I thought the desired approach from this issue was actually what I was supposed to do! using the vscode tooling, I assumed, due to intellisense suggesting an NSG was the required type, that the symbolic reference was enough. So I went ahead and typed:
giving the following in the built ARM template:
and the tooling says it's fine, but deploying gives: // Deployment failed. Correlation ID: .
{
"error": {
"code": "InvalidRequestFormat",
"message": "Cannot parse the request.",
"details": [
{
"code": "MissingJsonReferenceId",
"message": "Value for reference id is missing. Path properties.networkSecurityGroup."
}
]
}
} Only by finding this issue did I understand I needed to do:
|
@anthony-c-martin, it would be interesting if RPs could somehow declare in swagger that this |
Copying comment from #2906:
|
This syntax perplexes me a bit... details.parent.id: foo On one hand it seems handy on another it seems like it's just confusing to mix the syntaxes... also thinking about a scenario where the details object has other properties... would I: details.parent.id: foo
details.parent.name: bar or details.parent.id: foo
details: {
name: bar
} Granted I assume we'd have restrictions (like disallowing that second example), but the benefit escapes me... esp over your example from #146... |
Terseness is the only benefit; semantically it's equivalent. In my example, it cuts 5 lines down to 1 line, and reduces the amount of punctuation required. I'm just trying to gauge interest with the above write-up. |
I think I prefer the solution in #146, @anthony-c-martin. The other suggestion is nice in that it's terse, but I feel like it's obscuring the way the type is defined. A single-line object declaration feels like it gives the same terseness without adding any conceptual overhead. |
I wasted hours today with the exact scenario that @beforan cites. I was assuming that the correct syntax would be:
...eventually realising that I have to reference it like this
The same happened with networkInterfaces
...which I'd assumed would be:
|
Thank you, yes, I do see the warning with the code above but not with
|
ARM makes extensive use of the format
Take for example the network interface in Bicep Playground 0.0.8, there is
subnet
,publicIpAddress
, andnetworkSecurityGroup
.Could this be simplified to:
Bicep should be able to tell that the ARM schema for the resource needs an object of the format
{ "id": "" }
so it can extract this directly from the reference.Also, the reference to the sub-resource (subnet in this case) could be simple dot notation as every sub-resource will have a name.
The text was updated successfully, but these errors were encountered: