Skip to content

Commit eabf13d

Browse files
Fix resource creation (#8)
* fix: check if group was created in current iteration * fix: check if any group is returned
1 parent b4f2e2e commit eabf13d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

resourceCreation.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ $clientSecret = $actionContext.Configuration.clientSecret
2626
# Define correlation property of groups - This has to be unique
2727
$correlationProperty = "externalId"
2828

29+
# Check if correlationproperty exists
30+
$groupsCreated = New-Object System.Collections.Generic.List[System.Object]
31+
2932
#region functions
3033
function Resolve-ZenyaErrorMessage {
3134
[CmdletBinding()]
@@ -223,10 +226,12 @@ try {
223226
Write-Verbose "Querying group that matches filter [$($filter)]"
224227

225228
$group = $null
226-
$group = $groupsGrouped["$($correlationValue)"]
229+
if($groupsGrouped -ne $null){
230+
$group = $groupsGrouped["$($correlationValue)"]
231+
}
227232

228233
# If resource does not exist
229-
if ($null -eq $group) {
234+
if ($null -eq $group -and -not($groupsCreated.Contains($correlationValue))) {
230235
<# Resource creation preview uses a timeout of 30 seconds
231236
while actual run has timeout of 10 minutes #>
232237
# Example: Department (department differs from other objects as the property for the name is "DisplayName", not "Name")
@@ -251,6 +256,8 @@ try {
251256

252257
$createdGroup = Invoke-RestMethod @splatWebRequest -Verbose:$false
253258

259+
$groupsCreated.Add($correlationValue)
260+
254261
$outputContext.AuditLogs.Add([PSCustomObject]@{
255262
# Action = "" # Optional
256263
Message = "Created group [$($correlationValue)] for resource [$($resource | ConvertTo-Json)]"

0 commit comments

Comments
 (0)