Skip to content

Commit

Permalink
Merge pull request #515 from thapr0digy/fix-nil-pubips
Browse files Browse the repository at this point in the history
Fixed nil fields being dereferenced for public ips
  • Loading branch information
Ice3man543 authored Jun 4, 2024
2 parents e8b16a2 + 2210951 commit 49645e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/providers/azure/publicips.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (pip *publicIPProvider) GetResource(ctx context.Context) (*schema.Resources
}

for _, ip := range ips {
// The IPAddress field can be nil and so we want to prevent from dereferencing
// a nil field in the struct
if ip.IPAddress == nil {
continue
}
list.Append(&schema.Resource{
Provider: providerName,
PublicIPv4: *ip.IPAddress,
Expand Down
15 changes: 13 additions & 2 deletions pkg/providers/azure/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ func (d *vmProvider) GetResource(ctx context.Context) (*schema.Resources, error)
return nil, err
}
for _, ipConfig := range ipconfigList {
privateIP := *ipConfig.PrivateIPAddress
privateIP := ipConfig.PrivateIPAddress

// The PublicIPAddress field can be nil especially for SQL Server
// VMs that are pulled.
// In these cases, we just want to return an empty error
if ipConfig.PublicIPAddress == nil {
continue
}

res, err := azure.ParseResourceID(*ipConfig.PublicIPAddress.ID)
if err != nil {
Expand All @@ -61,11 +68,15 @@ func (d *vmProvider) GetResource(ctx context.Context) (*schema.Resources, error)
return nil, err
}

if publicIP.IPAddress == nil {
continue
}

list.Append(&schema.Resource{
Provider: providerName,
PublicIPv4: *publicIP.IPAddress,
ID: d.id,
PrivateIpv4: privateIP,
PrivateIpv4: *privateIP,
})
}
}
Expand Down

0 comments on commit 49645e6

Please sign in to comment.