-
Notifications
You must be signed in to change notification settings - Fork 764
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
Tree-shake existing
resources where possible
#13674
Comments
One issue encountered while working on this is that of the "non-inlinable" qualifiers listed above, i.e.
is that this list solves the problem in #13555 only because the property accessed in the provided example is If the criteria for which resources must be represented in the compiled JSON as
then users would only experience a breaking change if they were previously relying on broken behavior (having a non-existing resource depend on an existing resource in a non-symbolic name template). |
We've just ran into this problem as well. This example template builds and deploys just fine: resource uami1 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
scope: resourceGroup('rg-subscription-default-resources')
name: 'deployment-uami-${subscription().subscriptionId}'
}
resource uami2 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
scope: resourceGroup('rg-subscription-default-resources')
name: 'deployment-uami-${subscription().subscriptionId}'
}
output uami1 object = uami1
output uami2 object = uami2 ... but the moment you add a languageVersion 2.0 feature in there, template deployment will fail with an error stating that the userAssignedIdentity resource "is defined multiple times in a template". Simply adding a line like We ran into this problem because we're autogenerating our templates, and in some templates this results in referring to the same While in our use case this problem would be fixed by the proposal made by this issue (as we're not querying any runtime properties of the resource), wouldn't it be possible to change ARM's behavior such that it would allow deploying duplicate resources, if and only if all of the duplicates have |
This is bad that this issue exists even when the resource symbolic name (uami1 and uami2) is different. We often provide have scenarios where you define the user assigned identity so you can put it on the resource but also you have encryption and there you have to provide the user assigned identity as well if you choose to use it for encryption. That requires defining the same identity in two different existing statements. |
We just encountered the scenario of a broken deployment after adding a type import to our module, which converts it to languageVersion 2.0 automatically. Our deployment scenario: param deployContainerApps bool
resource serviceBus 'Microsoft.ServiceBus/namespaces@2021-06-01-preview' = {
name: resourceName
location: location
tags: tags
sku: 'someSku'
identity: {
type: 'SystemAssigned'
}
}
resource uami1 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
scope: resourceGroup('rg-subscription-default-resources')
name: 'deployment-uami-${subscription().subscriptionId}'
}
module roleAssignment 'rbac.bicep' = if (deployContainerApps) {
scope: resourceGroup('rg-subscription-default-resources')
name: 'deployment-uami-${subscription().subscriptionId}'
params: {
roleGuid: '000-000-00-00-000-000'
identity: deployContainerApps ? uami1 : ''
scope: serviceBus.id
}
} When we added a type import to this template we suddenly got the following error |
@jeskew I will do some testing once it is available in the official release as I have a lot of issues comparing to how existing works in language version 2. |
…oyments engine will use the GET response (#15693) Resolves #13674 Resolves #15686 This PR reapplies the change from #15447 now that the bug in indexing expression traversal is fixed. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/15693)
The semantics of
reference()
expressions vs"existing": true
resources do not have a 1:1 correspondence in ARM, but the Bicep compiler uses them interchangeably. While ARM's existing resources offer additional functionality and IMHO enhanced readability, templates may not declare multiple existing resources that point to the same resource ID (while duplicativereference()
calls are permitted), nor may templates use runtime expressions in resource top-level properties (which is permitted in some cases for expressions likeresourceId()
that overlap with the functionality offered byexisting
resources).In order to minimize the number of breaking changes template authors might encounter when switching their compilation target to symbolic name templates, Bicep should try to "tree-shake" existing resources by not emitting
"existing": true
resources in the compiled JSON template unless the template:apiVersion
,type
,id
, orname
,getSecret()
,dependsOn
property, ordependsOn
property on theexisting
resource.We may eventually need a mechanism that forces an
existing
resource to be present in the compiled JSON, but there is no need for one now. This might look like:The text was updated successfully, but these errors were encountered: