From 47d360621f3fa858a8b02ee92d60f4646894f086 Mon Sep 17 00:00:00 2001 From: Seif Bassem <38246040+sebassem@users.noreply.github.com> Date: Sun, 24 Dec 2023 19:59:24 +0200 Subject: [PATCH] Refactor role assignment queries in Bicep Landing Zone tests --- tests/pester/full.tests.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/pester/full.tests.ps1 b/tests/pester/full.tests.ps1 index c74e67e..faf4352 100644 --- a/tests/pester/full.tests.ps1 +++ b/tests/pester/full.tests.ps1 @@ -65,10 +65,11 @@ Describe "Bicep Landing Zone (Sub) Vending Tests" { It "Should Have a Role Assignment for an known AAD Group with the Reader role directly upon the Subscription" { $iterationCount = 0 do { - $roleAssignment = Get-AzRoleAssignment -Scope "/subscriptions/$subId" -RoleDefinitionName "Reader" -ObjectId "7eca0dca-6701-46f1-b7b6-8b424dab50b3" -ErrorAction SilentlyContinue + #$roleAssignment = Get-AzRoleAssignment -Scope "/subscriptions/$subId" -RoleDefinitionName "Reader" -ObjectId "7eca0dca-6701-46f1-b7b6-8b424dab50b3" -ErrorAction SilentlyContinue + $roleAssignment = Get-AzRoleAssignment -Scope /subscriptions/$subId | Where-Object { $_.ObjectId -eq "7eca0dca-6701-46f1-b7b6-8b424dab50b3" -and $_.RoleDefinitionName -eq "Reader"} -ErrorAction SilentlyContinue if ($null -eq $roleAssignment) { Write-Host "Waiting for Subscription Role Assignments to be eventually consistent... Iteration: $($iterationCount)" -ForegroundColor Yellow - Start-Sleep -Seconds 40 + Start-Sleep -Seconds 45 $iterationCount++ } } until ( @@ -83,10 +84,11 @@ Describe "Bicep Landing Zone (Sub) Vending Tests" { It "Should Have a Role Assignment for an known AAD Group with the Network Contributor role directly upon the Resource Group" { $iterationCount = 0 do { - $roleAssignment = Get-AzRoleAssignment -Scope "/subscriptions/$subId/resourceGroups/rsg-$location-net-hs-pr-$prNumber" -RoleDefinitionName "Network Contributor" -ObjectId "7eca0dca-6701-46f1-b7b6-8b424dab50b3" -ErrorAction SilentlyContinue + #$roleAssignment = Get-AzRoleAssignment -Scope "/subscriptions/$subId/resourceGroups/rsg-$location-net-hs-pr-$prNumber" -RoleDefinitionName "Network Contributor" -ObjectId "7eca0dca-6701-46f1-b7b6-8b424dab50b3" -ErrorAction SilentlyContinue + $roleAssignment = Get-AzRoleAssignment -Scope "/subscriptions/resourceGroups/rsg-$location-net-hs-pr-$prNumber" | Where-Object { $_.ObjectId -eq "7eca0dca-6701-46f1-b7b6-8b424dab50b3" -and $_.RoleDefinitionName -eq "Network Contributor"} -ErrorAction SilentlyContinue if ($null -eq $roleAssignment) { Write-Host "Waiting for Resource Group Role Assignments to be eventually consistent... Iteration: $($iterationCount)" -ForegroundColor Yellow - Start-Sleep -Seconds 40 + Start-Sleep -Seconds 45 $iterationCount++ } } until (