Skip to content

Commit

Permalink
fix(server): invalid ipv6_address nil1 when no IPv6 is used (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
apricote committed Jun 13, 2023
1 parent daacca3 commit 2912f45
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/server/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,6 @@ func getServerAttributes(d *schema.ResourceData, s *hcloud.Server) map[string]in
"status": s.Status,
"server_type": s.ServerType.Name,
"ipv4_address": s.PublicNet.IPv4.IP.String(),
"ipv6_address": s.PublicNet.IPv6.IP.String() + "1",
"ipv6_network": s.PublicNet.IPv6.Network.String(),
"backup_window": s.BackupWindow,
"backups": s.BackupWindow != "",
Expand All @@ -1109,6 +1108,14 @@ func getServerAttributes(d *schema.ResourceData, s *hcloud.Server) map[string]in
"firewall_ids": firewallIDs,
}

if len(s.PublicNet.IPv6.IP) == 0 {
// No IPv6 Primary IP assigned
res["ipv6_address"] = s.PublicNet.IPv6.IP.String() // Will be just "<nil>"
} else {
// Set first IP in assigned subnet range
res["ipv6_address"] = s.PublicNet.IPv6.IP.String() + "1"
}

if s.Image != nil {
if s.Image.Name != "" && strconv.Itoa(s.Image.ID) != d.Get("image") {
// Only use the image name if the image is official (Name != "")
Expand Down

0 comments on commit 2912f45

Please sign in to comment.