manifests/collectors/Networking/vNETPeering.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Networking/vNETPeering.ps1 (AB#5660).
# Field expressions are copied verbatim from the original collector and evaluate in an
# equivalent scope -- see docs/design/decisions/declarative-collectors.md.
# Review before trusting; regenerate rather than hand-patch if the source collector changes.
#
@{
    ResourceTypes = @(
        'microsoft.network/virtualnetworks'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = '@($_.PROPERTIES.virtualNetworkPeerings).Count -gt 0'

    FilterPreamble = ''

    RowLoopVariable = '1'

    Preamble = @'
$ResUCount = 1
                $sub1 = $SUB | Where-Object { $_.Id -eq $1.subscriptionId }
                $data = $1.PROPERTIES
                $Tags = if(![string]::IsNullOrEmpty($1.tags.psobject.properties)){$1.tags.psobject.properties}else{'0'}
'@


    AdditionalRowLoops = @(
        @{
            Variable = '2'
            Source = '$data.addressSpace.addressPrefixes'
            # AB#6845: this is the LOCAL VNet's address space, not the peering's. A VNet whose
            # addressSpace is absent from the payload lost every one of its peerings, because
            # loop 4 is nested inside this one and never ran.
            EmitNullWhenEmpty = $true
            Preamble = ''
        }
        @{
            Variable = '4'
            Source = '$data.virtualNetworkPeerings'
            # AB#6845 decision ($4) -- DELIBERATELY NOT GUARDED. Unlike every other loop fixed
            # under this bug, the row here IS the child: this worksheet is an inventory of
            # PEERINGS, and a VNet with none has nothing to say on it. Nor is the VNet lost by
            # staying out -- it has its own worksheet in Networking/VirtualNetwork, which is where
            # an unpeered VNet belongs. A parent-only row would put a VNet on the peering sheet
            # with every peering column blank, which reads as a broken peering rather than an
            # absent one, and would make "how many peerings does this estate have" unanswerable by
            # reading the row count.
            #
            # Contrast loop $2 in this same file, which DOES set EmitNullWhenEmpty: that one fans
            # out over the local VNet's own address prefixes, which are an ATTRIBUTE of the parent
            # rather than a separate thing being inventoried. The behaviour of this loop is
            # asserted, not merely skipped, in tests/Collector.VanishingParent.Tests.ps1.
            #
            # Note also the AdditionalFilter at the top of this file, which admits only VNets with
            # at least one peering. An unpeered VNet never reaches this loop in the first place,
            # so the flag would be doubly unreachable here.
            Preamble = ''
        }
        @{
            Variable = '5'
            Source = '$4.properties.remoteAddressSpace.addressPrefixes'
            # AB#6845: the remote address space is an ATTRIBUTE of a peering that does exist, and
            # it is genuinely absent whenever the remote VNet uses `ipamPoolPrefixAllocations` or
            # the peering is still Initiated. Dropping the row lost a real peering -- including
            # its state, the very column an operator opens this sheet for.
            EmitNullWhenEmpty = $true
            Preamble = ''
        }
    )

    TagLoop = @{
        Variable = 'Tag'
        Source = '$Tags'
        Preamble = ''
    }

    Fields = @(
        @{
            Name = 'ID'
            Expression = '$1.id'
        }
        @{
            Name = 'Subscription'
            Expression = '$sub1.Name'
        }
        @{
            Name = 'Resource Group'
            Expression = '$1.RESOURCEGROUP'
        }
        @{
            Name = 'VNET Name'
            Expression = '$1.NAME'
        }
        @{
            Name = 'Location'
            Expression = '$1.LOCATION'
        }
        @{
            Name = 'Zone'
            Expression = '$1.ZONES'
        }
        @{
            Name = 'Address Space'
            Expression = '$2'
        }
        @{
            Name = 'Peering Name'
            Expression = '$4.name'
        }
        @{
            Name = 'Peering VNet'
            Expression = '(Get-AZSCIdSegment -Id $4.properties.remoteVirtualNetwork.id -Index 8)'
        }
        @{
            Name = 'Peering State'
            Expression = '$4.properties.peeringState'
        }
        @{
            Name = 'Peering Use Remote Gateways'
            Expression = '$4.properties.useRemoteGateways'
        }
        @{
            Name = 'Peering Allow Gateway Transit'
            Expression = '$4.properties.allowGatewayTransit'
        }
        @{
            Name = 'Peering Allow Forwarded Traffic'
            Expression = '$4.properties.allowForwardedTraffic'
        }
        @{
            Name = 'Peering Do Not Verify Remote Gateways'
            Expression = '$4.properties.doNotVerifyRemoteGateways'
        }
        @{
            Name = 'Peering Allow Virtual Network Access'
            Expression = '$4.properties.allowVirtualNetworkAccess'
        }
        @{
            Name = 'Peering Address Space'
            Expression = '$5'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
        @{
            Name = 'Tag Name'
            Expression = '[string]$Tag.Name'
        }
        @{
            Name = 'Tag Value'
            Expression = '[string]$Tag.Value'
        }
    )

    Export = @{
        WorksheetName = 'Peering'
        TableNamePrefix = 'PeeringsTable_'
        Columns = @(
            'Subscription'
            'Resource Group'
            'Location'
            'Zone'
            'Peering Name'
            'VNET Name'
            'Address Space'
            'Peering VNet'
            'Peering Address Space'
            'Peering State'
            'Peering Use Remote Gateways'
            'Peering Allow Gateway Transit'
            'Peering Allow Forwarded Traffic'
            'Peering Do Not Verify Remote Gateways'
            'Peering Allow Virtual NetworkAccess'
            'Resource U'
        )
        TagColumns = @(
            'Tag Name'
            'Tag Value'
        )
        TagColumnsBefore = 'Resource U'
        NumberFormat = '0'
        ConditionalText = @(
            'New-ConditionalText disconnected -Range J:J'
        )
    }

    SourceCollector = 'Modules/Public/InventoryModules/Networking/vNETPeering.ps1'
}