Open ewbankkit opened 1 year ago
I also have this need.
The API I'm using has several endpoints with attributes like server_address
or destination_prefix
which work equally with IPv4 and IPv6 addresses, so cidrtypes.IPPrefix
and iptypes.IPAddress
would be helpful.
Even better if they (and the v4/v6 specific types) had methods which expose the underlying types (netip.Prefix) or facts about them: I'd really like to be able to invoke methods like: Is4()
, Is6()
, MaskBits()
, IsBroadcast()
, IsZeroAddr()
, etc...
The IsZeroAddr()
case is particularly useful for APIs which will accept values like 192.168.5.5/24
and then internally re-write them to 192.168.5.0/24
.
I've adjusted the issue title to mention addresses in addition to CIDRs, since both feature requests would be very closely related.
We had to implement our own version of this for Linode reverse DNS. https://github.com/linode/terraform-provider-linode/pull/1081
I hope we can migrate to HashiCorp's implementation at a later point.
@bflad May I help with the implementation?
If it would be following the pattern of IPv4 or IPv6 type, the implemenmtation should be very easy.
Only thing I concern about is naming. How can I name a custom type that support both IPv4 and IPv6? IPv4IPv6PrefixType
, IPv4Andv6PrefixType
, IPv4v6PrefixType
, NetIPPrefixType
? Any other suggestion?
The Terraform AWS Provider contains resources which have attributes that can represent an IPv4 or IPV6 CIDR block -- for example
aws_route53_cidr_location.cidr_blocks
- AWS Developer Guide. A custom type that represents either flavor of CIDR block would be useful.