Skip to content

[Feature Request]: Re-work modules to new dependency approach #1791

Closed
@AlexanderSehr

Description

Description

Once PR #1624 is merged we can start transforming the current test parameter files into the new Bicep test files. As this will affect all top level modules it makes sense to do this module by module. To this end we should either create an issue per module or a checkbox list somewhere to track the progress.

Note: Several modules are already converted and await review in PR #1787

To get an overview of the expected effort you can find an outline of the expected dependencies in the following:

Resource Type # RG MSI Diag Dependencies
AAD/DomainServices 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • AnalysisServices/servers 5
    ApiManagement/service 6
  • Microsoft.KeyVault/vaults
  • AppConfiguration/configurationStores 6
  • Microsoft.Network/virtualNetworks
  • Authorization/policyAssignments 1
    Authorization/policyExemptions 1
  • /subscriptions/<>/providers/Microsoft.Authorization/policyAssignments/adp-<>-sb-pass-loc-rg
  • Automation/automationAccounts 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • Batch/batchAccounts 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • Cache/redis 2
  • Microsoft.Network/virtualNetworks
  • CognitiveServices/accounts 6
  • Microsoft.Network/virtualNetworks
  • Compute/availabilitySets 3
  • Microsoft.Compute/proximityPlacementGroups
  • Compute/diskEncryptionSets 3
  • Microsoft.KeyVault/vaults
  • Compute/disks 4
  • /Subscriptions/<>/Providers/Microsoft.Compute/Locations/westeurope/Publishers/MicrosoftWindowsServer/ArtifactTypes/VMImage/Offers/WindowsServer/Skus/2016-Datacenter/Versions/14393.4906.2112080838
  • Microsoft.Storage/storageAccounts
  • Compute/galleries 2
    Compute/images 2
    Compute/proximityPlacementGroups 2
    Compute/virtualMachines 10
  • Microsoft.Compute/proximityPlacementGroups
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/applicationSecurityGroups
  • Microsoft.Network/loadBalancers
  • Microsoft.Network/virtualNetworks
  • Compute/virtualMachineScaleSets 8
  • Microsoft.Compute/proximityPlacementGroups
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • ContainerInstance/containerGroups 1
    ContainerRegistry/registries 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • ContainerService/managedClusters 7
  • Microsoft.Compute/diskEncryptionSets
  • Microsoft.Network/virtualNetworks
  • Databricks/workspaces 5
    DataFactory/factories 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • DataProtection/backupVaults 2
    DBforPostgreSQL/flexibleServers 8
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/privateDnsZones
  • Microsoft.Network/virtualNetworks
  • DesktopVirtualization/applicationgroups 5
    DesktopVirtualization/hostpools 5
    DesktopVirtualization/scalingplans 2
    DesktopVirtualization/workspaces 5
    DocumentDB/databaseAccounts 5
    EventGrid/systemTopics 5
    EventGrid/topics 6
  • Microsoft.Network/virtualNetworks
  • EventHub/namespaces 6
  • Microsoft.Network/virtualNetworks
  • HealthBot/healthBots 2
    Insights/actionGroups 2
    Insights/activityLogAlerts 3
  • microsoft.insights/actiongroups
  • Insights/components 3
    Insights/diagnosticSettings 3
    Insights/metricAlerts 2
    Insights/privateLinkScopes 4
  • Microsoft.Network/virtualNetworks
  • Insights/scheduledQueryRules 2
    KeyVault/vaults 6
  • Microsoft.Network/virtualNetworks
  • KubernetesConfiguration/extensions 1
    KubernetesConfiguration/fluxConfigurations 1
    Logic/workflows 5
    MachineLearningServices/workspaces 8
  • Microsoft.Insights/components
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • ManagedIdentity/userAssignedIdentities 2
    NetApp/netAppAccounts 3
  • Microsoft.Network/virtualNetworks
  • Network/applicationGateways 8
  • Microsoft.Network/applicationGateways
  • Microsoft.Network/publicIPAddresses
  • Microsoft.Network/virtualNetworks
  • Network/applicationSecurityGroups 2
    Network/azureFirewalls 7
  • Microsoft.Network/publicIPAddresses
  • Microsoft.Network/virtualNetworks
  • Network/bastionHosts 7
  • Microsoft.Network/publicIPAddresses
  • Microsoft.Network/virtualNetworks
  • Network/connections 3
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworkGateways
  • Network/ddosProtectionPlans 2
    Network/expressRouteCircuits 5
    Network/firewallPolicies 1
    Network/frontDoors 3
  • Microsoft.Network/frontDoors
  • Network/ipGroups 2
    Network/loadBalancers 7
  • Microsoft.Network/publicIPAddresses
  • Microsoft.Network/virtualNetworks
  • Network/localNetworkGateways 2
    Network/natGateways 5
    Network/networkInterfaces 8
  • Microsoft.Network/applicationSecurityGroups
  • Microsoft.Network/loadBalancers
  • Microsoft.Network/virtualNetworks
  • Network/networkSecurityGroups 6
  • Microsoft.Network/applicationSecurityGroups
  • Network/networkWatchers 6
  • Microsoft.Compute/virtualMachines
  • Microsoft.Network/networkSecurityGroups
  • Network/privateDnsZones 3
  • Microsoft.Network/virtualNetworks
  • Network/privateEndpoints 4
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • Network/publicIPAddresses 5
    Network/publicIPPrefixes 2
    Network/routeTables 2
    Network/trafficmanagerprofiles 5
    Network/virtualHubs 4
  • Microsoft.Network/virtualHubs
  • Microsoft.Network/virtualNetworks
  • Microsoft.Network/virtualWans
  • Network/virtualNetworkGateways 6
  • Microsoft.Network/virtualNetworks
  • Network/virtualNetworks 8
  • Microsoft.Network/networkSecurityGroups
  • Microsoft.Network/routeTables
  • Microsoft.Network/virtualNetworks
  • Network/virtualWans 2
    Network/vpnGateways 3
  • Microsoft.Network/virtualHubs
  • Microsoft.Network/vpnSites
  • Network/vpnSites 3
  • Microsoft.Network/virtualWans
  • OperationalInsights/workspaces 6
  • Microsoft.Automation/automationAccounts
  • OperationsManagement/solutions 1
    RecoveryServices/vaults 7
  • Microsoft.Network/virtualNetworks
  • Microsoft.RecoveryServices/vaults
  • Resources/deploymentScripts 1
    Resources/resourceGroups 1
    Security/azureSecurityCenter 2
  • /subscriptions/<>
  • ServiceBus/namespaces 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • ServiceFabric/clusters 2
    SignalRService/webPubSub 2
  • Microsoft.Network/virtualNetworks
  • Sql/managedInstances 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • Sql/servers 7
  • /subscriptions/<>/resourceGroups/<>/providers/Microsoft.KeyVault/vaults/adp-<>-az-kv-x-001
  • Microsoft.Network/virtualNetworks
  • Storage/storageAccounts 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • Synapse/privateLinkHubs 3
  • Microsoft.Network/virtualNetworks
  • Synapse/workspaces 7
  • Microsoft.KeyVault/vaults
  • Microsoft.Network/virtualNetworks
  • VirtualMachineImages/imageTemplates 3
  • Microsoft.Compute/galleries
  • Web/connections 3
  • /subscriptions/<>/providers/Microsoft.Web/locations/westeurope/managedApis/azuremonitorlogs
  • Web/hostingEnvironments 6
  • Microsoft.Network/virtualNetworks
  • Web/serverfarms 5
    Web/sites 8
  • Microsoft.Insights/components
  • Microsoft.Network/virtualNetworks
  • Microsoft.Web/serverFarms
  • Web/staticSites 3
  • Microsoft.Network/virtualNetworks
  • Authorization/locks 0
    Authorization/policyDefinitions 0
    Authorization/policySetDefinitions 0
    Authorization/roleAssignments 0
    Authorization/roleDefinitions 0
    Consumption/budgets 0
    ManagedServices/registrationDefinitions 0
    Management/managementGroups 0
    Resources/tags 0

    The script that was used to generate the list is the following

    Script
    [CmdletBinding()]
    param (
        [Parameter()]
        [string] $ModulesPath
    )
    
    $moduleFolderPaths = (Get-ChildItem -Path $ModulesPath -Directory -Recurse).FullName | Where-Object {
        ((($_ -replace '\\', '/') -split '/modules/')[1] -split '/').Count -eq 2 -and $_ -notlike '*.shared*'
    }
    
    $resultSet = @{}
    foreach ($moduleFolderPath in $moduleFolderPaths) {
    
        $parameterFilePaths = (Get-ChildItem -Path (Join-Path $moduleFolderPath '.test') -Filter '*.json' -Recurse).FullName
    
        $references = [System.Collections.ArrayList]@()
    
        foreach ($parameterFilePath in $parameterFilePaths) {
            $content = Get-Content $parameterFilePath
            $references += $content | Where-Object {
                $_ -like '*:*' -and ($_ -split ':')[1].Trim() -like '*/subscriptions/*'
            } | ForEach-Object {
                    ($_ -split ':')[1].Trim()
            } | ForEach-Object {
                    ($_ -replace '/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/', '') -replace '"', ''
            } | ForEach-Object {
                if ($_ -like 'Microsoft.*') {
                        ($_ -split '/')[0, 1] -join '/'
                } else {
                    $_
                }
            }
        }
    
        # Special case: Resource Group
        $templatePath = Join-Path $moduleFolderPath 'deploy.bicep'
        $templateContent = Get-Content $templatePath
        if ($templateContent[0] -like '*resourceGroup*' -or $templateContent[0] -notlike '*targetScope*') {
            # Requires Resource Group deployment
            $references += 'Microsoft.Resources/resourceGroups'
        }
    
        # Special case: RBAC (MSI)
        $rbacFilePath = Join-Path $moduleFolderPath '.bicep' 'nested_roleAssignments.bicep'
        if (Test-Path $rbacFilePath) {
            # Requires Managed Identity deployment for RBAC
            $references += 'Microsoft.ManagedIdentity/userAssignedIdentities'
        }
    
        $providerNamespace = Split-Path (Split-Path $moduleFolderPath -Parent) -Leaf
        $resourceType = Split-Path $moduleFolderPath -Leaf
    
        $resultSet["$providerNamespace/$resourceType"] = ($references | Select-Object -Unique | Sort-Object)
    }
    
    
    $dependenciesTableTable = @(
        '| Resource Type | # | RG | MSI | Diag | Dependencies |',
        '| - | - | - | - | - | - |'
    )
    
    # With dependencies
    foreach ($resourceType in ($resultSet.Keys | Where-Object { $resultSet[$_].Count -gt 0 } | Sort-Object)) {
    
        # Convert array to arraylist to allow operations
        $references = [System.Collections.ArrayList]@()
        if ($resultSet[$resourceType] -is [array]) {
            $references.AddRange($resultSet[$resourceType])
        } else {
            $null = $references.Add($resultSet[$resourceType])
        }
        $dependenciesCount = $references.Count
    
        # Filter common patterns
        if ($references -contains 'Microsoft.Resources/resourceGroups') {
            $references.Remove('Microsoft.Resources/resourceGroups')
            $hasRg = $true
        } else {
            $hasRg = $false
        }
        if ($references -contains 'Microsoft.ManagedIdentity/userAssignedIdentities') {
            $references.Remove('Microsoft.ManagedIdentity/userAssignedIdentities')
            $hasMsi = $true
        } else {
            $hasMsi = $false
        }
        if ($references -contains 'microsoft.operationalinsights/workspaces') {
            $references.Remove('microsoft.operationalinsights/workspaces')
            $references.Remove('Microsoft.Storage/storageAccounts')
            $references.Remove('Microsoft.EventHub/namespaces')
            $hasDiag = $true
        } else {
            $hasDiag = $false
        }
    
        $dependencies = ''
        $references | ForEach-Object {
            $dependencies += "<li>$_</li>"
        }
        $dependenciesTableTable += '| `{0}` | {1} | {2} | {3} | {4} | {5} |' -f ($resourceType -replace 'Microsoft.', ''), $dependenciesCount, ($hasRg ? ':white_check_mark:' : ''), ($hasMsi ? ':white_check_mark:' : ''), ($hasDiag ? ':white_check_mark:' : ''), $dependencies
    }
    
    # Without any dependencies
    foreach ($resourceType in ($resultSet.Keys | Where-Object { $resultSet[$_].Count -eq 0 } | Sort-Object)) {
        $dependenciesTableTable += '| `{0}` | {1} | | | | |' -f ($resourceType -replace 'Microsoft.', ''), 0
    }
    
    $dependenciesTableTable

    Activity

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Assignees

    Labels

    Type

    No type

    Projects

    • Status

      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions