-
Notifications
You must be signed in to change notification settings - Fork 804
Description
Proposal - simplifying resource referencing (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.
Resources as params and outputs
A new type of resource will be accepted in param and output declarations to permit passing a reference to a resource as an input or output for a module. Supplying the type string for the resource would be optional, but functionality would be greatly reduced without it.
At compile-time, Bicep will type check for reference equality - it will ensure a valid resource reference is passed to a generic resource param, and it will ensure that a valid resource reference matching the expected type string is passed to a typed resource param.
Examples
Generic
// we haven't specified a resource type here
param lockableResource resource
resource lockResource 'Microsoft.Authorization/locks@2016-09-01' = {
scope: lockableResource
name: 'DontDelete'
...
}Input/Output
// input a resource reference
param storageAcc resource 'Microsoft.Storage/storageAccounts@2021-01-01'
var myContainer = storageAcc.child('blobServices', 'default').child('containers', 'myContainer')
// output a resource reference - note the resource type can be omitted
output myContainer resource = myContainerProperty access
param storageAcc resource 'Microsoft.Storage/storageAccounts@2021-01-01'
// list keys
var myKey = listKeys(storageAcc.id, storageAcc.apiVersion).keys[0].value
// property access
output accountTags object = storageAcc.tagsNotes
- If the param does not specify a resource type string, functionality will be greatly reduced - limited to using the resource as a scope for an extension resource, and accessing the resource
idproperty. We want to encourage module authors to be specific about the type they accept to provide optimal type safety. - API versions do not need to match across module params and outputs, but types must match if the param has specified a type.
- We will need to be careful when passing param references to resources at a different scope to the module, as they cannot be used for certain purposes (deploying children/extensions, for example).
Out of scope
- This proposal requires both inputs and outputs to accept a resource reference, and there is no conversion between resourceId string and resource reference. The following would not be permitted:
module myMod './module.bicep' = { name: 'myMod' params: { // resourceReference is a param of type 'resource' // resourceId is a string containing a resourceId resourceReference: resourceId } }
Codegen
The most straightforward option for JSON codegen is to generate a string parameter or output in the template JSON, with some associated metadata.
Metadata
Metadata
Assignees
Type
Projects
Status