Created
December 8, 2021 04:00
-
-
Save olafloogman/e5f623d881cd49742f78f72c503655c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
targetScope = 'resourceGroup' | |
@description('Resource name to check in current scope (resource group)') | |
param resourceName string | |
@description('Resource ID of user managed identity with reader permissions in current scope') | |
param identityPrincipalId string | |
param location string = resourceGroup().location | |
param utcValue string = utcNow() | |
// used to pass into deployment script | |
var resourceGroupName = resourceGroup().name | |
// The script below performs an 'az resource list' command to determine whether a resource exists | |
resource resource_exists_script 'Microsoft.Resources/deploymentScripts@2020-10-01' = { | |
name: 'resource_exists' | |
location: location | |
kind: 'AzureCLI' | |
identity: { | |
type: 'UserAssigned' | |
userAssignedIdentities: { | |
'${identityPrincipalId}': {} | |
} | |
} | |
properties: { | |
forceUpdateTag: utcValue | |
azCliVersion: '2.15.0' | |
timeout: 'PT10M' | |
arguments: '\'${resourceGroupName}\' \'${resourceName}\'' | |
scriptContent: 'result=$(az resource list --resource-group ${resourceGroupName} --name ${resourceName}); echo $result; echo $result | jq -c \'{Result: map({name: .name})}\' > $AZ_SCRIPTS_OUTPUT_PATH' | |
cleanupPreference: 'OnSuccess' | |
retentionInterval: 'P1D' | |
} | |
} | |
output exists bool = length(resource_exists_script.properties.outputs.Result) > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment