-
Notifications
You must be signed in to change notification settings - Fork 756
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
A dependency on an existing
resource doesn't actually require the resource to exist
#13325
Comments
There are a couple quirks of the ARM platform that you're running in to. The first is that The second is that |
This is by design and explained further in the above comment |
Even though this was marked as The following template will still successfully deploy and will output resource IDs of resources that do not exist, as there's no explicit #disable-next-line no-unused-params
param foo string? // this is only here to force templateVersion 2.0
resource uami1 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: 'does-not-exist'
}
resource uami2 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: 'does-not-exist-as-well'
}
output uami1Id string = uami1.id
output uami2Id string = uami2.id The following template has an explicit #disable-next-line no-unused-params
param foo string? // this is only here to force templateVersion 2.0
resource uami1 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: 'does-not-exist'
}
resource uami2 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: 'does-not-exist-as-well'
dependsOn: [ // with https://github.com/Azure/bicep/pull/15447 this now results in a failure to deploy when uami1
uami1 // does not exist (but only in templateVersion 2.0 templates)
]
}
output uami1Id string = uami1.id
output uami2Id string = uami2.id Again, note that this only applies to languageVersion 2.0 templates! Leaving out the |
Bicep version
Bicep CLI version 0.24.24 (5646341)
Describe the bug
(This is somewhat related to #2716, but is about a different use case and scenario.)
Some, but not all, references to existing resources will work just fine even if the referred-to resource doesn't exist at all:
This template will work for any value of sqlServerName (or more precisely: any value that meets the naming restrictions for SQL Server resources).
This is a problem because I'm trying to do something like this (pseudocode), which silently doesn't work:
My expectation is that
scriptToRunOnSqlServer
does not deploy ifsqlServer
does not exist. In reality the deploymentScript does deploy.Worse, it will also fail an case of an implicit dependency, e.g. when the deployment script resource does not have the explicit
dependsOn
but includessqlServer.name
somewhere in its definition. That will just run the deployment script as if there's a server with that name, even though it doesn't exist at all.Further background
Looking at the resulting ARM, it turns out that there are two types of references to existing resources, and they behave differently:
[variables('sqlServerName')]
(in the first example template above). This type of reference will work even when the referred-to resource does not even exist.reference()
function. This type of reference will fail if the referred-to resource does not exist.This difference is completely invisible in the Bicep template (other than that you can only use references of the first type in certain locations, but that's beside the point here) . Only at deployment time the difference has an effect. This is undocumented and unintuitive. Things would be much more consistent if a dependency (either explicit or implicit) on an
existing
resource always results areference()
to the target resource.The text was updated successfully, but these errors were encountered: