Azure / Azure/bicep

"existing" functionality for modules

Open
#7,393 17 comments 11 reactions 0 assignees View on GitHub
enhancement Needs: Upvote
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Is your feature request related to a problem? Please describe.**

We have a Bicep module registry which we use to wrap Bicep templates, such that they are delivered to match our organisations collectively agreed security posture. So to create a storage account we'd do something like this:

```bicep
module deadLetterStorageAccount 'br:icebox.azurecr.io/bicep/ice/providers/storage/storage-accounts:v1.0' = {
name: 'lens-dead-letter-storage-account-${branchHash}'
params: {
tags: tags
location: location
storageAccountName: opticalDeadLetterStorageAccountName
skuName: 'Standard_ZRS'
}
}
```

If we want to reference the resource created by that module later elsewhere, we can do that using `existing` like so:

```bicep
resource opticalDeadLetterStorageAccount 'Microsoft.Storage/storageAccounts@2021-02-01' existing = {
name: opticalDeadLetterStorageAccountName
scope: resourceGroup(opticalStorageResourceGroupName)
}
```

But this is not a great developer experience as:
1. We have flipped from `module` syntax to `resource` syntax which is confusing
2. We have to go and look up what resource is used in the module to be able to write the module statement
3. If that module is updated to use a different resource, we have to find out the new one and then copy/pasta that across all our `resource ... existing` references

**Describe the solution you'd like**

What would be delightful is if there was some kind of `existing` syntax for modules. Imagine if, instead of:

```bicep
resource opticalDeadLetterStorageAccount 'Microsoft.Storage/storageAccounts@2021-02-01' existing = {
name: opticalDeadLetterStorageAccountName
scope: resourceGroup(opticalStorageResourceGroupName)
}
```

we could do:

```bicep
module deadLetterStorageAccount 'br:icebox.azurecr.io/bicep/ice/providers/storage/storage-accounts:v1.0' existing = {
name: 'lens-dead-letter-storage-account-${branchHash}'
params: {
tags: tags
location: location
storageAccountName: opticalDeadLetterStorageAccountName
skuName: 'Standard_ZRS'
}
}
```

This would make upgrades much more straightforward / intuitive.

There's obviously a whole bunch of complexity in what I'm suggesting - but something like this would be amazing. Something that allows you to acquire the resources created by a module directly rather than indirectly. What do you think?

Contributor guide

Open the contributing guide

Research direction

The issue names no implementation files, tests, or entry points. Start by tracing how Bicep parses and validates module declarations versus existing resources, then determine how module outputs and resource acquisition should behave; done means an agreed design and corresponding coverage for the proposed existing-module syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.