Create resource if another resource exists #2595
-
|
What's the correct way to create the resource logWorkspace 'Microsoft.OperationalInsights/workspaces@2020-10-01' existing = {
name: 'my-lg'
}
resource diagnostics 'Microsoft.Insights/diagnosticsettings@2017-05-01-preview' = if (logWorkspace) {
name: 'my-dg'
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
|
key thing here is scope you should find something helpful here : #2067 (reply in thread) |
Beta Was this translation helpful? Give feedback.
-
|
Can you clarify your scenario a bit for me? Do you know (in advance of the deployment starting) if the log analytics workspace has been deployed or not? If it has not been deployed are you going to deploy it as part of this bicep deployment? If the LA workspace was deployed previously, why wasn't diagnostics added at the time of creation? There is no concept of an "existence check" in bicep. The What we will typically see is the "intent to deploy a resource" expressed as a parameter, and then a conditional check to deploy something based on that intent. For example: |
Beta Was this translation helpful? Give feedback.
-
|
This is interesting case. This behaviour implies that it's not bicep responsibility to do any checks before trying to deploy resorurces. This would work fine if you start a greenfield project with bicep, and there are great practices how to build solid IaaC when there is no legacy . |
Beta Was this translation helpful? Give feedback.





Can you clarify your scenario a bit for me?
Do you know (in advance of the deployment starting) if the log analytics workspace has been deployed or not? If it has not been deployed are you going to deploy it as part of this bicep deployment? If the LA workspace was deployed previously, why wasn't diagnostics added at the time of creation?
There is no concept of an "existence check" in bicep. The
existskeyword is to get a symbolic reference to a known, previously deployed resource and one that you do not intend to update as part of this deployment.What we will typically see is the "intent to deploy a resource" expressed as a parameter, and then a conditional check to deploy something bas…