Skip to content

Commit

Permalink
Update VM resource graph query to use unique fields during iteration. (
Browse files Browse the repository at this point in the history
…#306)

Signed-off-by: Archana Holla <[email protected]>
  • Loading branch information
archanapholla authored Sep 6, 2023
1 parent 2e45df4 commit bda1f7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pkg/cloudprovider/plugins/azure/azure_crd_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ func computeInstanceToInternalVirtualMachineObject(instance *virtualMachineTable
}

var nsgIds []string
if nwInf.NsgID != nil {
if nwInf.NsgID != nil && *nwInf.NsgID != "" {
nsgIds = append(nsgIds, *nwInf.NsgID)
}

var asgIDs []string
for _, asgID := range nwInf.ApplicationSecurityGroupIDs {
asgIDs = append(asgIDs, *asgID)
if asgID != nil && *asgID != "" {
asgIDs = append(asgIDs, *asgID)
}
}

networkInterface := runtimev1alpha1.NetworkInterface{
Expand Down
16 changes: 8 additions & 8 deletions pkg/cloudprovider/plugins/azure/azure_resourcegraph_vmTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ const (
" {{ end }}" +
" | extend publicIpId = tolower(tostring(ipconfig.properties.publicIPAddress.id))" +
" | extend nicPrivateIp = ipconfig.properties.privateIPAddress" +
" | extend applicationSecurityGroup = ipconfig.properties.applicationSecurityGroups" +
" | extend applicationSecurityGroups = ipconfig.properties.applicationSecurityGroups" +
" | join kind = leftouter (" +
" Resources" +
" | where type =~ 'microsoft.network/publicipaddresses'" +
" | project publicIpId = tolower(id), nicPublicIp = properties.ipAddress" +
" ) on publicIpId" +
" | mvexpand applicationSecurityGroup" +
" | extend appId = tolower(applicationSecurityGroup.id)" +
" | summarize nicTags = any(tags), macAddress = any(macAddress), vnetId = any(vnetId), nsgId = any(nsgId), " +
"applicationSecurityGroupIds = make_list(appId), nicPublicIps = make_list(nicPublicIp), " +
"nicPrivateIps = make_list(nicPrivateIp) by id, name" +
" | project nicId = tolower(id), nicName = name, nicPublicIps, nicPrivateIps, vnetId, macAddress, " +
"nicTags, nsgId = tolower(nsgId), applicationSecurityGroupIds" +
" | mvexpand applicationSecurityGroup = applicationSecurityGroups" +
" | extend appSecurityGroupId = tolower(applicationSecurityGroup.id)" +
" | summarize applicationSecurityGroupIds = make_set(appSecurityGroupId), " +
"nicTags = any(tags), macAddress = any(macAddress), vnetId = any(vnetId), nsgId = any(nsgId), " +
"nicPublicIps = make_set(nicPublicIp), nicPrivateIps = make_set(nicPrivateIp) by id, name" +
" | project nicId = tolower(id), nicName = name, nsgId = tolower(nsgId), nicPublicIps, nicPrivateIps, vnetId, macAddress, " +
"nicTags, applicationSecurityGroupIds" +
") on nicId" +
"| extend networkInterfaceDetails = pack(\"id\", nicId, \"name\", nicName, \"macAddress\", macAddress, \"privateIps\"," +
"nicPrivateIps, \"publicIps\", nicPublicIps, \"tags\", nicTags, \"vnetId\", vnetId, \"nsgId\", nsgId, " +
Expand Down

0 comments on commit bda1f7f

Please sign in to comment.