From dd1fa7b7447ad18e8a138773eb0e422d0c8d4732 Mon Sep 17 00:00:00 2001 From: Seif Bassem <38246040+sebassem@users.noreply.github.com> Date: Tue, 1 Aug 2023 15:30:43 +0300 Subject: [PATCH 1/4] add 'microsoft.insights' provider registration --- .../pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 index 24b2e5db4..973a1b552 100644 --- a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 +++ b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 @@ -5,6 +5,9 @@ param ( [Parameter()] [String]$TopLevelMGPrefix = "$($env:TOP_LEVEL_MG_PREFIX)", + [Parameter()] + [String]$ManagementSubscriptionId = "$($env:MANAGEMENT_SUBSCRIPTION_ID)", + [Parameter()] [String]$TemplateFile = "upstream-releases\$($env:UPSTREAM_RELEASE_VERSION)\infra-as-code\bicep\orchestration\mgDiagSettingsAll\mgDiagSettingsAll.bicep", @@ -26,4 +29,8 @@ $inputObject = @{ Verbose = $true } +# Registering 'Microsoft.Insights' resource provider on the Management subscription +Select-AzSubscription -SubscriptionId $ManagementSubscriptionId +Register-AzResourceProvider -ProviderNamespace 'Microsoft.Insights' + New-AzManagementGroupDeployment @inputObject From 073d943249a6537d7e8f30420793586a6c60112d Mon Sep 17 00:00:00 2001 From: Seif Bassem <38246040+sebassem@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:07:06 +0300 Subject: [PATCH 2/4] adding resource provider registration --- .../Deploy-ALZMGDiagnosticSettings.ps1 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 index 973a1b552..8df9fe20c 100644 --- a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 +++ b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 @@ -31,6 +31,21 @@ $inputObject = @{ # Registering 'Microsoft.Insights' resource provider on the Management subscription Select-AzSubscription -SubscriptionId $ManagementSubscriptionId -Register-AzResourceProvider -ProviderNamespace 'Microsoft.Insights' + +$providers = @('Microsoft.insights') + +foreach ($provider in $providers ){ + $providerStatus= (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState + if($providerStatus -ne 'Registered'){ + Write-Host "`n Registering the '$provider' provider" + Register-AzResourceProvider -ProviderNamespace $provider + do { + $providerStatus= (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState + Write-Host "Waiting for the '$provider' provider registration to complete....waiting 10 seconds" + Start-Sleep -Seconds 10 + } until ($providerStatus -eq 'Registered') + Write-Host "`n The '$provider' has been registered successfully" + } +} New-AzManagementGroupDeployment @inputObject From e76555c0a24ccbc689edb5acbc775c10cef3beb7 Mon Sep 17 00:00:00 2001 From: Seif Bassem <38246040+sebassem@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:56:52 +0300 Subject: [PATCH 3/4] switch to write-output --- .../pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 index 8df9fe20c..e9a3e3bce 100644 --- a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 +++ b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 @@ -37,14 +37,14 @@ $providers = @('Microsoft.insights') foreach ($provider in $providers ){ $providerStatus= (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState if($providerStatus -ne 'Registered'){ - Write-Host "`n Registering the '$provider' provider" + Write-Output "`n Registering the '$provider' provider" Register-AzResourceProvider -ProviderNamespace $provider do { $providerStatus= (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState - Write-Host "Waiting for the '$provider' provider registration to complete....waiting 10 seconds" + Write-Output "Waiting for the '$provider' provider registration to complete....waiting 10 seconds" Start-Sleep -Seconds 10 } until ($providerStatus -eq 'Registered') - Write-Host "`n The '$provider' has been registered successfully" + Write-Output "`n The '$provider' has been registered successfully" } } From deaf3baaaa5152450b309e93375db7ee63c98ae7 Mon Sep 17 00:00:00 2001 From: Seif Bassem <38246040+sebassem@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:12:45 +0300 Subject: [PATCH 4/4] adding timer --- .../Deploy-ALZMGDiagnosticSettings.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 index e9a3e3bce..0c5bdf293 100644 --- a/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 +++ b/accelerator/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1 @@ -35,16 +35,24 @@ Select-AzSubscription -SubscriptionId $ManagementSubscriptionId $providers = @('Microsoft.insights') foreach ($provider in $providers ){ + $iterationCount = 0 + $maxIterations = 30 $providerStatus= (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState if($providerStatus -ne 'Registered'){ Write-Output "`n Registering the '$provider' provider" Register-AzResourceProvider -ProviderNamespace $provider do { $providerStatus= (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState + $iterationCount++ Write-Output "Waiting for the '$provider' provider registration to complete....waiting 10 seconds" Start-Sleep -Seconds 10 - } until ($providerStatus -eq 'Registered') - Write-Output "`n The '$provider' has been registered successfully" + } until ($providerStatus -eq 'Registered' -and $iterationCount -ne $maxIterations) + if($iterationCount -ne $maxIterations){ + Write-Output "`n The '$provider' has been registered successfully" + } + else{ + Write-Output "`n The '$provider' has not been registered successfully" + } } }