⚡ Lazy-load Azure network, AKS, IAM, and Redis sub-resources#7014
Open
⚡ Lazy-load Azure network, AKS, IAM, and Redis sub-resources#7014
Conversation
There was a problem hiding this comment.
Lazy-loading Azure network sub-resources reduces unnecessary API data processing, but a pre-existing resource name typo will cause outbound rule creation to fail at runtime.
Additional findings (file/line not in diff):
- 🟡
providers/azure/resources/network.go:2279— Same pre-existing nil-safety issue:ipConfig.Properties.PrivateIPAddressaccessed without checkingipConfig.Properties != nilin firewallipConfigurations().
Contributor
27d9615 to
ed89d64
Compare
ed89d64 to
1073709
Compare
1b53b4f to
1073709
Compare
1073709 to
c44cbf7
Compare
c44cbf7 to
ddb17e9
Compare
Convert 18 eagerly-loaded properties to computed methods across SecurityGroup, Firewall, LoadBalancer, and VirtualNetworkGateway. Sub-resources are now only materialized when the user actually queries those fields, avoiding unnecessary CreateResource calls during list operations. Each resource caches the raw SDK properties in an Internal struct so the data is available for lazy loading without re-fetching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…load AKS/IAM/Redis sub-resources - Fix pre-existing typo: "outbundRule" → "outboundRule" in CreateResource - Add nil checks on Properties before accessing PrivateIPAddress in: - Firewall ipConfigurations() - Firewall managementIpConfiguration() - VirtualNetworkGateway ipConfigurations() - Lazy-load AKS cluster aadProfile and autoUpgradeProfile - Lazy-load IAM roleDefinition permissions - Lazy-load Redis privateEndpointConnections Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- redis.go: Merge duplicate Internal struct into single definition - network.go: Guard lb.SKU and fw.Properties/SKU nil dereferences - iam.go: Skip nil permission entries in lazy-loaded permissions() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ddb17e9 to
4d9c42c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts 23 eagerly-loaded sub-resource fields across 6 Azure resource types to lazy-loaded computed methods. This means sub-resource data is only fetched when a query actually references it, instead of being materialized on every scan.
What changed
Network resources (network.go):
probes,backendPools,frontendIpConfigs,inboundNatPools,inboundNatRules,outboundRules,loadBalancerRules. Previously every LB list call parsed all 7 sub-resource arrays upfront. Now the list call returns just the LB metadata; sub-resources are only materialized from the cached Properties when accessed.ipConfigurations,managementIpConfiguration,networkRules,natRules,applicationRules.interfaces,securityRules,defaultSecurityRules.ipConfigurations,bgpSettings,natRules.AKS (aks.go):
aadProfile,autoUpgradeProfile. These were parsed from the cluster Properties on every list even though most queries don't inspect them.IAM (iam.go):
permissions. The permissions array is now lazy-loaded from the cached role definition properties.Redis (redis.go):
privateEndpointConnections. Parsed on demand instead of during the list call.API call savings
Azure List APIs return the full resource object including all sub-resource arrays in the Properties blob. Before this PR, we were parsing all of those into MQL resources during the list call — meaning every sub-resource got
CreateResourcecalled even if no query ever touched it.After this PR, the raw
Propertiesstruct is cached on the Internal struct, and sub-resources are only materialized when a query accesses the field. This eliminates thousands of unnecessaryCreateResource+convert.JsonToDictcalls during scan initialization.Example: A subscription with 20 Load Balancers, each with ~5 probes, 3 backend pools, 4 frontend IPs, 2 NAT rules, 2 outbound rules, and 3 LB rules:
CreateResourcecalls at scan start, even if the query is justazure.subscription.networkService.loadBalancers { name }CreateResourcecalls at scan start. Sub-resources only created if the query traverses into them.Also fixed
outbundRule→outboundRule(resource name was misspelled)Test plan
make test/lintpassesmake providers/build/azure && make providers/install/azuremql shell azure:azure.subscription.networkService.loadBalancers { name probes backendPools }azure.subscription.networkService.firewalls { name ipConfigurations networkRules }azure.subscription.networkService.securityGroups { name securityRules defaultSecurityRules }azure.subscription.aksService.clusters { name aadProfile autoUpgradeProfile }azure.subscription.authorizationService.roleDefinitions { name permissions }azure.subscription.cacheService.redisInstances { hostName privateEndpointConnections }🤖 Generated with Claude Code