Handle network prefixes correctly (#753)
* wip * fix: corrected testcase * fix: change prefix to workaround bug in current environment * fix: made acceptance test more robust for randomized nameserver order * fix: updated documentation * fix: linter issue * fix: acceptance test still relied on a fixed order of nameservers * fix: fixed import acceptance testcase
This commit is contained in:
parent
6d49b2ff81
commit
c7ed274647
6 changed files with 280 additions and 68 deletions
|
|
@ -3,6 +3,7 @@ package network
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
|
@ -545,7 +546,6 @@ func mapFields(ctx context.Context, networkResp *iaas.Network, model *Model) err
|
|||
}
|
||||
|
||||
// IPv4
|
||||
|
||||
if networkResp.Nameservers == nil {
|
||||
model.Nameservers = types.ListNull(types.StringType)
|
||||
model.IPv4Nameservers = types.ListNull(types.StringType)
|
||||
|
|
@ -585,6 +585,17 @@ func mapFields(ctx context.Context, networkResp *iaas.Network, model *Model) err
|
|||
if diags.HasError() {
|
||||
return fmt.Errorf("map network prefixes: %w", core.DiagsToError(diags))
|
||||
}
|
||||
if len(respPrefixes) > 0 {
|
||||
model.IPv4Prefix = types.StringValue(respPrefixes[0])
|
||||
_, netmask, err := net.ParseCIDR(respPrefixes[0])
|
||||
if err != nil {
|
||||
// silently ignore parsing error for the netmask
|
||||
model.IPv4PrefixLength = types.Int64Null()
|
||||
} else {
|
||||
ones, _ := netmask.Mask.Size()
|
||||
model.IPv4PrefixLength = types.Int64Value(int64(ones))
|
||||
}
|
||||
}
|
||||
|
||||
model.Prefixes = prefixesTF
|
||||
model.IPv4Prefixes = prefixesTF
|
||||
|
|
@ -625,7 +636,17 @@ func mapFields(ctx context.Context, networkResp *iaas.Network, model *Model) err
|
|||
if diags.HasError() {
|
||||
return fmt.Errorf("map network IPv6 prefixes: %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
if len(respPrefixesV6) > 0 {
|
||||
model.IPv6Prefix = types.StringValue(respPrefixesV6[0])
|
||||
_, netmask, err := net.ParseCIDR(respPrefixesV6[0])
|
||||
if err != nil {
|
||||
// silently ignore parsing error for the netmask
|
||||
model.IPv6PrefixLength = types.Int64Null()
|
||||
} else {
|
||||
ones, _ := netmask.Mask.Size()
|
||||
model.IPv6PrefixLength = types.Int64Value(int64(ones))
|
||||
}
|
||||
}
|
||||
model.IPv6Prefixes = prefixesV6TF
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue