From 6e4ea5f68c1c4355c035d3ad75766705842fa269 Mon Sep 17 00:00:00 2001 From: Vitor Tomaz <40804779+vitomaz-msft@users.noreply.github.com> Date: Thu, 26 May 2022 23:38:55 +0100 Subject: [PATCH] Check NAT gateway associated with subnet --- .../prepare-subnet/prepareSubnet.ps1 | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/samples/manage/azure-sql-db-managed-instance/prepare-subnet/prepareSubnet.ps1 b/samples/manage/azure-sql-db-managed-instance/prepare-subnet/prepareSubnet.ps1 index bfcf3eae..96d0fe23 100644 --- a/samples/manage/azure-sql-db-managed-instance/prepare-subnet/prepareSubnet.ps1 +++ b/samples/manage/azure-sql-db-managed-instance/prepare-subnet/prepareSubnet.ps1 @@ -183,31 +183,33 @@ function VerifySubnet { param ( $subnet ) - Write-Host("Verifying subnet '{0}'." -f $subnet.Name) - If($subnet.AddressPrefix.Split('/')[1] -le 28) - { - Write-Host "Passed Validation - Subnet is of enough size." -ForegroundColor Green - } - Else - { - Write-Host "Failed Validation - Minimum supported subnet size is /28." -ForegroundColor Red - Break - } - If( + Write-Host("Verifying subnet '{0}'." -f $subnet.Name) + If ($subnet.AddressPrefix.Split('/')[1] -le 28) { + Write-Host "Passed Validation - Subnet is of enough size." -ForegroundColor Green + } + Else { + Write-Host "Failed Validation - Minimum supported subnet size is /28." -ForegroundColor Red + Break + } + If ( ($subnet.IpConfigurations.Count -eq 0) -and ( ($subnet.ResourceNavigationLinks.Count -eq 0) -or ($subnet.ResourceNavigationLinks[0].LinkedResourceType -eq 'Microsoft.Sql/virtualClusters') ) - ) - { - Write-Host "Passed Validation - There are no conflicting resources inside the subnet." -ForegroundColor Green - } - Else - { - Write-Host "Failed Validation - Subnet is already in use." -ForegroundColor Red + ) { + If ($subnet.NatGateway.Id) { + Write-Host "Failed Validation - There is a NAT gateway associated with this subnet." -ForegroundColor Red Break } + Else { + Write-Host "Passed Validation - There are no conflicting resources inside the subnet." -ForegroundColor Green + } + } + Else { + Write-Host "Failed Validation - Subnet is already in use." -ForegroundColor Red + Break + } }