Documentation ¶
Overview ¶
Package iptypes contains Terraform Plugin Framework Custom Type implementations for IPv4 and IPv6 address strings.
Index ¶
- type IPv4Address
- type IPv4AddressType
- func (t IPv4AddressType) Equal(o attr.Type) bool
- func (t IPv4AddressType) String() string
- func (t IPv4AddressType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics
- func (t IPv4AddressType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics)
- func (t IPv4AddressType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)
- func (t IPv4AddressType) ValueType(ctx context.Context) attr.Value
- type IPv6Address
- type IPv6AddressType
- func (t IPv6AddressType) Equal(o attr.Type) bool
- func (t IPv6AddressType) String() string
- func (t IPv6AddressType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics
- func (t IPv6AddressType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics)
- func (t IPv6AddressType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)
- func (t IPv6AddressType) ValueType(ctx context.Context) attr.Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPv4Address ¶
type IPv4Address struct {
basetypes.StringValue
}
IPv4Address represents a valid IPv4 address string (dotted decimal, no leading zeroes). No semantic equality logic is defined for IPv4Address, so it will follow Terraform's data-consistency rules for strings, which must match byte-for-byte.
func NewIPv4AddressNull ¶
func NewIPv4AddressNull() IPv4Address
NewIPv4AddressNull creates an IPv4Address with a null value. Determine whether the value is null via IsNull method.
func NewIPv4AddressPointerValue ¶
func NewIPv4AddressPointerValue(value *string) IPv4Address
NewIPv4AddressPointerValue creates an IPv4Address with a null value if nil or a known value. Access the value via ValueStringPointer method.
func NewIPv4AddressUnknown ¶
func NewIPv4AddressUnknown() IPv4Address
NewIPv4AddressUnknown creates an IPv4Address with an unknown value. Determine whether the value is unknown via IsUnknown method.
func NewIPv4AddressValue ¶
func NewIPv4AddressValue(value string) IPv4Address
NewIPv4AddressValue creates an IPv4Address with a known value. Access the value via ValueString method.
func (IPv4Address) Equal ¶
func (v IPv4Address) Equal(o attr.Value) bool
Equal returns true if the given value is equivalent.
func (IPv4Address) Type ¶
func (v IPv4Address) Type(_ context.Context) attr.Type
Type returns an IPv4AddressType.
func (IPv4Address) ValueIPv4Address ¶
func (v IPv4Address) ValueIPv4Address() (netip.Addr, diag.Diagnostics)
ValueIPv4Address calls netip.ParseAddr with the IPv4Address StringValue. A null or unknown value will produce an error diagnostic.
Example ¶
package main import ( "fmt" "github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes" ) type IPv4AddressResourceModel struct { IPv4Address iptypes.IPv4Address `tfsdk:"ipv4_address"` } func main() { // For example purposes, typically the data model would be populated automatically by Plugin Framework via Config, Plan or State. // https://developer.hashicorp.com/terraform/plugin/framework/handling-data/accessing-values data := IPv4AddressResourceModel{ IPv4Address: iptypes.NewIPv4AddressValue("127.0.0.1"), } // Check that the IPv4Address data is known and able to be converted to netip.Addr if !data.IPv4Address.IsNull() && !data.IPv4Address.IsUnknown() { ipAddr, diags := data.IPv4Address.ValueIPv4Address() if diags.HasError() { return } fmt.Printf("%t, %s\n", ipAddr.IsLoopback(), ipAddr) } }
Output: true, 127.0.0.1
type IPv4AddressType ¶
type IPv4AddressType struct {
basetypes.StringType
}
IPv4AddressType is an attribute type that represents a valid IPv4 address string (dotted decimal, no leading zeroes). No semantic equality logic is defined for IPv4AddressType, so it will follow Terraform's data-consistency rules for strings, which must match byte-for-byte.
func (IPv4AddressType) Equal ¶
func (t IPv4AddressType) Equal(o attr.Type) bool
Equal returns true if the given type is equivalent.
func (IPv4AddressType) String ¶
func (t IPv4AddressType) String() string
String returns a human readable string of the type name.
func (IPv4AddressType) Validate ¶
func (t IPv4AddressType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics
Validate implements type validation. This type requires the value provided to be a String value that is a valid IPv4 address. This utilizes the Go `net/netip` library for parsing so leading zeroes will be rejected as invalid.
func (IPv4AddressType) ValueFromString ¶
func (t IPv4AddressType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics)
ValueFromString returns a StringValuable type given a StringValue.
func (IPv4AddressType) ValueFromTerraform ¶
func (t IPv4AddressType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)
ValueFromTerraform returns a Value given a tftypes.Value. This is meant to convert the tftypes.Value into a more convenient Go type for the provider to consume the data with.
type IPv6Address ¶
type IPv6Address struct {
basetypes.StringValue
}
IPv6Address represents a valid IPv6 address string (RFC 4291). Semantic equality logic is defined for IPv6Address such that an address string with the zero bits `compressed` will be considered equivalent to the `non-compressed` string.
Examples:
- `0:0:0:0:0:0:0:0` is semantically equal to `::`
- `2001:DB8:0:0:8:800:200C:417A` is semantically equal to `2001:DB8::8:800:200C:417A`
- `FF01:0:0:0:0:0:0:101` is semantically equal to `FF01::101`
IPv6Address also supports IPv6 address strings with embedded IPv4 addresses, see RFC 4291 for more details: https://www.rfc-editor.org/rfc/rfc4291.html#section-2.5.5
func NewIPv6AddressNull ¶
func NewIPv6AddressNull() IPv6Address
NewIPv6AddressNull creates an IPv6Address with a null value. Determine whether the value is null via IsNull method.
func NewIPv6AddressPointerValue ¶
func NewIPv6AddressPointerValue(value *string) IPv6Address
NewIPv6AddressPointerValue creates an IPv6Address with a null value if nil or a known value. Access the value via ValueStringPointer method.
func NewIPv6AddressUnknown ¶
func NewIPv6AddressUnknown() IPv6Address
NewIPv6AddressUnknown creates an IPv6Address with an unknown value. Determine whether the value is unknown via IsUnknown method.
func NewIPv6AddressValue ¶
func NewIPv6AddressValue(value string) IPv6Address
NewIPv6AddressValue creates an IPv6Address with a known value. Access the value via ValueString method.
func (IPv6Address) Equal ¶
func (v IPv6Address) Equal(o attr.Value) bool
Equal returns true if the given value is equivalent.
func (IPv6Address) StringSemanticEquals ¶
func (v IPv6Address) StringSemanticEquals(_ context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics)
StringSemanticEquals returns true if the given IPv6 address string value is semantically equal to the current IPv6 address string value. This comparison utilizes netip.ParseAddr and then compares the resulting netip.Addr representations. This means `compressed` IPv6 address values are considered semantically equal to `non-compressed` IPv6 address values.
Examples:
- `0:0:0:0:0:0:0:0` is semantically equal to `::`
- `2001:DB8:0:0:8:800:200C:417A` is semantically equal to `2001:DB8::8:800:200C:417A`
- `FF01:0:0:0:0:0:0:101` is semantically equal to `FF01::101`
See RFC 4291 for more details on IPv6 string format: https://www.rfc-editor.org/rfc/rfc4291.html#section-2.2
func (IPv6Address) Type ¶
func (v IPv6Address) Type(_ context.Context) attr.Type
Type returns an IPv6AddressType.
func (IPv6Address) ValueIPv6Address ¶
func (v IPv6Address) ValueIPv6Address() (netip.Addr, diag.Diagnostics)
ValueIPv6Address calls netip.ParseAddr with the IPv6Address StringValue. A null or unknown value will produce an error diagnostic.
Example ¶
package main import ( "fmt" "github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes" ) type IPv6AddressResourceModel struct { IPv6Address iptypes.IPv6Address `tfsdk:"ipv6_address"` } func main() { // For example purposes, typically the data model would be populated automatically by Plugin Framework via Config, Plan or State. // https://developer.hashicorp.com/terraform/plugin/framework/handling-data/accessing-values data := IPv6AddressResourceModel{ IPv6Address: iptypes.NewIPv6AddressValue("::1"), } // Check that the IPv6Address data is known and able to be converted to netip.Addr if !data.IPv6Address.IsNull() && !data.IPv6Address.IsUnknown() { ipAddr, diags := data.IPv6Address.ValueIPv6Address() if diags.HasError() { return } fmt.Printf("%t, %s\n", ipAddr.IsLoopback(), ipAddr) } }
Output: true, ::1
type IPv6AddressType ¶
type IPv6AddressType struct {
basetypes.StringType
}
IPv6AddressType is an attribute type that represents a valid IPv6 address string (RFC 4291). Semantic equality logic is defined for IPv6AddressType such that an address string with the zero bits `compressed` will be considered equivalent to the `non-compressed` string.
Examples:
- `0:0:0:0:0:0:0:0` is semantically equal to `::`
- `2001:DB8:0:0:8:800:200C:417A` is semantically equal to `2001:DB8::8:800:200C:417A`
- `FF01:0:0:0:0:0:0:101` is semantically equal to `FF01::101`
IPv6AddressType also supports IPv6 address strings with embedded IPv4 addresses, see RFC 4291 for more details: https://www.rfc-editor.org/rfc/rfc4291.html#section-2.5.5
func (IPv6AddressType) Equal ¶
func (t IPv6AddressType) Equal(o attr.Type) bool
Equal returns true if the given type is equivalent.
func (IPv6AddressType) String ¶
func (t IPv6AddressType) String() string
String returns a human readable string of the type name.
func (IPv6AddressType) Validate ¶
func (t IPv6AddressType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics
Validate implements type validation. This type requires the value provided to be a String value that is a valid IPv6 address.
func (IPv6AddressType) ValueFromString ¶
func (t IPv6AddressType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics)
ValueFromString returns a StringValuable type given a StringValue.
func (IPv6AddressType) ValueFromTerraform ¶
func (t IPv6AddressType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)
ValueFromTerraform returns a Value given a tftypes.Value. This is meant to convert the tftypes.Value into a more convenient Go type for the provider to consume the data with.