Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nil fields being dereferenced for public ips #515

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
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
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
Loading