Error handling #12262
Unanswered
romanrabodzei
asked this question in
Q&A
Error handling
#12262
Replies: 1 comment 2 replies
-
I don't think there is a way to handle it natively with Bicep due to idempotency, but there is a workaround. You can take a look at deployment scripts. By using deployment scripts you can run PowerShell and query a resource via de Azure PowerShell cmdlets. I have a snippet for you that you can use for testing: resource resManagedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2022-01-31-preview' = {
name: 'my-managed-identity'
location: parLocation
}
resource resDeploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'check-if-resource-exists'
location: parLocation
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${resManagedIdentity.id}' : {}
}
}
properties: {
azPowerShellVersion: '9.0'
retentionInterval: 'P1D'
scriptContent: '''
$resourceExists = // Do your check here using Azure PowerShell cmdlets!
$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['resourceExists'] = $resourceExists
'''
}
}
output outExists bool = resDeploymentScript.properties.outputs.resourceExists |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
The question is not new, but the proposed solutions are not what I'm looking for.
3 Ways To Check If Resource Exists In Azure Bicep
The goal is to check if the resource exists or not.
The code:
The output (expected):
With the existing resource:
The output says it does exist.
I know it is possible in Terraform. Looking for something that will work like in Powershel with -errorAction SilentlyContinue
Beta Was this translation helpful? Give feedback.
All reactions