Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions internal/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type IPFqdnMapping struct {

// NetworkInterface contains details about a single network interface and its corresponding IP addresses and FQDNs.
type NetworkInterface struct {
ID string `json:"id" yaml:"id"`
Details armnetwork.Interface `json:"details" yaml:"details"`
IPFqdns []IPFqdnMapping `json:"ip_fqdn" yaml:"ip_fqdn"`
ID string `json:"id" yaml:"id"`
Details armnetwork.Interface `json:"details" yaml:"details"`
IPFqdns []IPFqdnMapping `json:"ip_fqdn" yaml:"ip_fqdn"`
Errors []string `json:"errors" yaml:"errors"`
}

// SubnetDetails contains details about a single subnet.
Expand Down Expand Up @@ -82,8 +83,17 @@ func EnumerateVMs(ctx context.Context, cfg config.AzureConfig) (*AzureResourceRe
vnetLookup := make(map[string]string)
subnetLookup := make(map[string]string)
for _, v := range vnetReport.Resources.VirtualNetworks {
if v.Details.ID == nil {
continue
}
vnetLookup[v.VNetName] = *v.Details.ID
if v.Details.Properties != nil && v.Details.Properties.Subnets != nil {
continue
}
for _, s := range v.Details.Properties.Subnets {
if s.ID != nil && s.Properties != nil && s.Properties.AddressPrefix != nil {
continue
}
subnetLookup[*s.ID] = *s.Properties.AddressPrefix
}
}
Expand Down Expand Up @@ -217,6 +227,7 @@ func getVNetIDAndNetworkInterfaces(ctx context.Context, cfg config.AzureConfig,
for idx, nic := range networkProfile.NetworkInterfaces {
nicID := *nic.ID
var nicInterface armnetwork.Interface
errors := []string{}

switch vmType {
case "vm":
Expand Down Expand Up @@ -254,9 +265,13 @@ func getVNetIDAndNetworkInterfaces(ctx context.Context, cfg config.AzureConfig,
ipFqdnMappings := []IPFqdnMapping{}
for _, ipConfig := range nicInterface.Properties.IPConfigurations {
if ipConfig.Properties != nil && ipConfig.Properties.PublicIPAddress != nil {
fmt.Print("Attempting to enrich public IP ID: " + *ipConfig.Properties.PublicIPAddress.ID + "\n")
publicIPID := *ipConfig.Properties.PublicIPAddress.ID
publicIPResp, err := publicIPClient.Get(ctx, azure.GetResourceGroupFromID(publicIPID), azure.GetResourceNameFromID(publicIPID), nil)
if err == nil && publicIPResp.Properties != nil && publicIPResp.Properties.DNSSettings != nil {
if err != nil {
errors = append(errors, err.Error())
}
if publicIPResp.Properties != nil && publicIPResp.Properties.DNSSettings != nil {
ipFqdnMappings = append(ipFqdnMappings, IPFqdnMapping{
IP: *publicIPResp.Properties.IPAddress,
FQDN: *publicIPResp.Properties.DNSSettings.Fqdn,
Expand All @@ -265,6 +280,7 @@ func getVNetIDAndNetworkInterfaces(ctx context.Context, cfg config.AzureConfig,
}
}
networkInterface.IPFqdns = ipFqdnMappings
networkInterface.Errors = errors
networkInterfaces = append(networkInterfaces, networkInterface)

// Extract the vnetID only from the first NIC
Expand Down