Copilot commented on code in PR #282:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/282#discussion_r2914167224
##########
cloudstack/resource_cloudstack_network.go:
##########
@@ -78,13 +78,26 @@ func resourceCloudStackNetwork() *schema.Resource {
ForceNew: true,
},
+ "ip6cidr": {
+ Type: schema.TypeString,
+ Optional: true,
+ ForceNew: true,
Review Comment:
`ip6cidr` is a user-supplied string that can be semantically identical but
textually different (e.g., `2001:0db8::/64` vs `2001:db8::/64`). Because it’s
`ForceNew` and not normalized, CloudStack/API canonicalization can cause
perpetual diffs/recreates. Consider adding a `StateFunc` (or
`DiffSuppressFunc`) that parses the CIDR and returns a canonical form (e.g.,
masked `ipnet.String()`), so equivalent IPv6 CIDRs don’t drift due to
formatting.
```suggestion
ForceNew: true,
StateFunc: func(v interface{}) string {
s, ok := v.(string)
if !ok {
return ""
}
// Leave empty value unchanged.
if s == "" {
return s
}
// Parse and canonicalize the IPv6
CIDR. If parsing fails,
// return the original string so
invalid input is not altered.
_, ipnet, err := net.ParseCIDR(s)
if err != nil {
return s
}
return ipnet.String()
},
```
##########
cloudstack/resource_cloudstack_network.go:
##########
@@ -471,3 +530,93 @@ func parseCIDR(d *schema.ResourceData, specifyiprange
bool) (map[string]string,
return m, nil
}
+
+// addToIPv6 adds an integer offset to an IPv6 address with proper carry
across all bytes.
+// Returns a new net.IP with the result.
+func addToIPv6(ip net.IP, offset uint64) net.IP {
+ result := make(net.IP, len(ip))
+ copy(result, ip)
+
+ carry := offset
+ // Start from the least significant byte (rightmost) and work backwards
+ for i := len(result) - 1; i >= 0 && carry > 0; i-- {
+ sum := uint64(result[i]) + carry
+ result[i] = byte(sum & 0xff)
+ carry = sum >> 8
+ }
+
+ return result
+}
+
+func parseCIDRv6(d *schema.ResourceData, specifyiprange bool)
(map[string]string, error) {
+ m := make(map[string]string, 4)
+
+ cidr := d.Get("ip6cidr").(string)
+ ip, ipnet, err := net.ParseCIDR(cidr)
+ if err != nil {
+ return nil, fmt.Errorf("Unable to parse cidr %s: %s", cidr, err)
+ }
Review Comment:
The error returned on CIDR parse failure says "Unable to parse cidr" without
indicating it’s the IPv6 CIDR field. Updating this message to reference
`ip6cidr` (and using consistent capitalization like “CIDR”) would make
diagnostics clearer when both IPv4 `cidr` and `ip6cidr` are present.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]