Unable to reference connection status of connection resource in condition
Bicep version 0.26.170
Describe the bug I only want to deploy a series of VM's if a previously deployed VPN connection status is "Connected" however I'm getting the following error: The expression cannot be evaluated, because the identifier properties of the referenced existing resource including "name" cannot be calculated at the start of the deployment. In this situation, the accessible properties of "dccon" include "apiVersion", "id", "name", "type".bicep(BCP307).
To Reproduce Try and reference the connection status property for an existing connection resource and use it in an if condition.
It might not be obvious from the error message, but it's saying that a status property like "connected" cannot be checked at compile time. And if it cannot be checked compile time it cannot be used for conditionals.
While I haven't tested your specific use case (so disclaimer about it actually working) I'm guessing you might be able to workaround like this:
- Add a "deployVMs" bool as a param in the VM Bicep.
- Run a deployment script with a PowerShell/Azure CLI script to check status of VPN.
- Parse output and run a deployment of the VM Bicep with with a true or false accordingly.
This is a current design limitation. Moving the relevant property to a parameter as @ahelland suggested is the least-bad workaround. You could either deploy this file directly or call it as a module. If you share the full code sample, we can add more detail on a recommendation.