Added optional module names as an experimental feature #12600
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Currently, module names are a required property on
module
declarations. Modules are compiled to nested deployments in the JSON and the name expression is transpiled as-is. With deeply-nested module hierarchies it is very easy to create module names that conflict in grandchild deployments, which causes difficult to diagnose failures at deploy time. This partially fixes #3897.I'm introducing an experimental feature that once enabled, makes the
name
property inmodule
declarations optional. There is no change in behavior if the feature is disabled.With the feature enabled and
name
omitted in amodule
, we generate the following name expression in the JSON:[format('<symbolic name prefix>-{0}-{1}', copyIndex(), uniqueString('<symbolic name>', deployment().name))]
[format('<symbolic name prefix>-{0}', uniqueString('<symbolic name>', deployment().name))]
above represents the full symbolic name of the enclosing
module
declaration. is a substring of that starts at index 0 and takes as many characters as possible to fit within a deployment name.Considerations
uniqueString()
function always returns 13 characterscopyIndex()
serialized to a string is always 3 characters since the max value is 800. While this approach leaves up to 2 characters unused in module loops with 1 or 2-digit iteration counts, it makes the symbolic name prefix consistent, improving readability in the portal.Bicep authors should not take a dependency on the algorithm used to calculate the name. We reserve the right to change it at any time in the future without notice.
We will add a linter for module names in the future, but it is out of scope of this PR.
Portal experience
Module loop
main.bicep
mod.bicep
Azure Portal (count = 500)
Module nesting
main.bicep
mod.bicep
mod2.bicep
Azure Portal (count = 500)
Microsoft Reviewers: Open in CodeFlow