Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #154 from dbrennand/fix-resource-Microsoft.Network…
Browse files Browse the repository at this point in the history
…/networkSecurityGroups

Add fix for resource type Microsoft.Network/networkSecurityGroups missing data
  • Loading branch information
rtibi authored Aug 5, 2020
2 parents 0440f7c + afd03df commit 91b7c45
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions subscription replicator/Scripts/resource_retriever.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,38 @@ $resourceTypes = @(
if($resourceType -eq "All"){
$resources = @()
foreach($rt in $resourceTypes){
$resources += Get-AzureRmResource -ResourceType $rt
# Check if resource type is Microsoft.Network/networkSecurityGroups. Use specific API version: 2017-10-01
# The API discovery (via Get-AzureRmResource) chooses the API version: 2016-09-01 by default
# The response with this API version is missing data shown below:
<#
Example missing data:
"destinationPortRanges": [
"80",
"443",
"6060",
"8080"
],
"sourceAddressPrefixes": [
"10.192.1.0/27",
"10.203.0.0/16"
],
#>
# To fix this, we use the API version 2017-10-01 which is used by Get-AzureRmNetworkSecurityGroup
if($rt -eq "Microsoft.Network/networkSecurityGroups"){
$resources += Get-AzureRmResource -ResourceType $rt -ApiVersion "2017-10-01"
}
else{
$resources += Get-AzureRmResource -ResourceType $rt
}
}
}
else{
$resources = Get-AzureRmResource -ResourceType $resourceType
if($rt -eq "Microsoft.Network/networkSecurityGroups"){
$resources += Get-AzureRmResource -ResourceType $rt -ApiVersion "2017-10-01"
}
else{
$resources = Get-AzureRmResource -ResourceType $resourceType
}
}

$waitBlock =
Expand All @@ -110,7 +137,16 @@ Add-Content -Path ".\Deployment_Files\DeployResources.ps1" -Value "Write-Output

foreach($resource in $resources){
#convert resource to a JSON string
$resource = Get-AzureRmResource -ResourceId $resource.ResourceId
# Check if resource type is Microsoft.Network/networkSecurityGroups. Use specific API version: 2017-10-01
# The API discovery (via Get-AzureRmResource) chooses the API version: 2016-09-01 by default
# The response with this API version is missing data. See example above
# To fix this, we use the API version 2017-10-01 which is used by Get-AzureRmNetworkSecurityGroup
if($resource.ResourceType -eq "Microsoft.Network/networkSecurityGroups"){
$resource = Get-AzureRmResource -ResourceId $resource.ResourceId -ApiVersion "2017-10-01"
}
else{
$resource = Get-AzureRmResource -ResourceId $resource.ResourceId
}
$resourceJSONString = $resource | ConvertTo-Json -Depth 7

.\resource_processor.ps1 -resourceJSONString $resourceJSONString `
Expand Down

0 comments on commit 91b7c45

Please sign in to comment.