Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/resources/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ The following arguments are supported:

* `range` - (Required) The IPv6 range.

* `route_target` - (Optional) The public IPv6 address that the range is routed to.

* `vlan` - (Optional) Nested attributes object for a Linode VLAN interface. Exactly one of `public`, `vlan`, or `vpc` must be specified.

* `ipam_address` - (Optional) The VLAN interface's private IPv4 address in CIDR notation.
Expand Down
10 changes: 5 additions & 5 deletions linode/linodeinterface/framework_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ func (data *LinodeInterfaceModel) FlattenInterface(

data.VLAN = *flattenedVLAN
flattenedPublic := helper.KeepOrUpdateSingleNestedAttributesWithTypes(
ctx, data.Public, publicInterfaceSchema.GetType().(types.ObjectType).AttrTypes, preserveKnown, diags,
ctx, data.Public, resourcePublicInterfaceAttribute.GetType().(types.ObjectType).AttrTypes, preserveKnown, diags,
func(public *PublicAttrModel, isNull *bool, pk bool, d *diag.Diagnostics) {
if i.Public == nil {
*isNull = true
public.IPv4 = helper.KeepOrUpdateValue(public.IPv4, types.ObjectNull(publicIPv4Attribute.GetType().(types.ObjectType).AttrTypes), pk)
public.IPv6 = helper.KeepOrUpdateValue(public.IPv6, types.ObjectNull(publicIPv6Attribute.GetType().(types.ObjectType).AttrTypes), pk)
public.IPv4 = helper.KeepOrUpdateValue(public.IPv4, types.ObjectNull(resourcePublicIPv4Attribute.GetType().(types.ObjectType).AttrTypes), pk)
public.IPv6 = helper.KeepOrUpdateValue(public.IPv6, types.ObjectNull(resourcePublicIPv6Attribute.GetType().(types.ObjectType).AttrTypes), pk)
return
}
public.FlattenPublicInterface(ctx, *i.Public, pk, d)
Expand All @@ -201,10 +201,10 @@ func (data *LinodeInterfaceModel) FlattenInterface(
if i.VPC == nil {
*isNull = true
vpc.IPv4 = helper.KeepOrUpdateValue(
vpc.IPv4, types.ObjectNull(vpcIPv4Attribute.GetType().(types.ObjectType).AttrTypes), pk,
vpc.IPv4, types.ObjectNull(resourceVPCIPv4Attribute.GetType().(types.ObjectType).AttrTypes), pk,
)
vpc.IPv6 = helper.KeepOrUpdateValue(
vpc.IPv6, types.ObjectNull(vpcIPv6Attribute.GetType().(types.ObjectType).AttrTypes), pk,
vpc.IPv6, types.ObjectNull(resourceVPCIPv6Attribute.GetType().(types.ObjectType).AttrTypes), pk,
)
vpc.SubnetID = helper.KeepOrUpdateValue(vpc.SubnetID, types.Int64Null(), pk)
return
Expand Down
30 changes: 16 additions & 14 deletions linode/linodeinterface/framework_public_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ type PublicIPv4AddressAttrModel struct {
Primary types.Bool `tfsdk:"primary"`
}

// PublicIPv6RangeAttrModel is a shared model between `configuredPublicInterfaceIPv6Range` and
// `computedPublicInterfaceIPv6Range` schemas.
type PublicIPv6RangeAttrModel struct {
type ConfiguredPublicIPv6RangeAttrModel struct {
Range types.String `tfsdk:"range"`
}

type ComputedPublicIPv6RangeAttrModel struct {
Range types.String `tfsdk:"range"`
RouteTarget types.String `tfsdk:"route_target"`
}
Expand Down Expand Up @@ -161,9 +163,9 @@ func (data *PublicIPv6AttrModel) FlattenPublicIPv6(ctx context.Context, ipv6 lin
}

var newDiags diag.Diagnostics
assignedRanges := make([]PublicIPv6RangeAttrModel, len(ipv6.Ranges))
assignedRanges := make([]ComputedPublicIPv6RangeAttrModel, len(ipv6.Ranges))
for i, v := range ipv6.Ranges {
assignedRanges[i] = PublicIPv6RangeAttrModel{
assignedRanges[i] = ComputedPublicIPv6RangeAttrModel{
Range: types.StringValue(v.Range),
RouteTarget: types.StringPointerValue(v.RouteTarget),
}
Expand All @@ -176,9 +178,9 @@ func (data *PublicIPv6AttrModel) FlattenPublicIPv6(ctx context.Context, ipv6 lin
return
}

shared := make([]PublicIPv6RangeAttrModel, len(ipv6.Shared))
shared := make([]ComputedPublicIPv6RangeAttrModel, len(ipv6.Shared))
for i, v := range ipv6.Shared {
shared[i] = PublicIPv6RangeAttrModel{
shared[i] = ComputedPublicIPv6RangeAttrModel{
Range: types.StringValue(v.Range),
RouteTarget: types.StringPointerValue(v.RouteTarget),
}
Expand All @@ -200,7 +202,7 @@ func (data *PublicIPv6AttrModel) FlattenPublicIPv6(ctx context.Context, ipv6 lin
}

// `slaac` attribute is computed-only so it's always an unknown when the ipv6 is being flattened
data.SLAAC, newDiags = types.SetValueFrom(ctx, publicInterfaceIPv6SLAAC.Type(), slaac)
data.SLAAC, newDiags = types.SetValueFrom(ctx, resourcePublicInterfaceIPv6SLAAC.Type(), slaac)
diags.Append(newDiags...)
if diags.HasError() {
return
Expand All @@ -214,7 +216,7 @@ func (plan *PublicIPv6AttrModel) GetCreateOptions(ctx context.Context) (opts lin
length := len(plan.Ranges.Elements())

rangesOpts := make([]linodego.PublicInterfaceIPv6RangeCreateOptions, 0, length)
ranges := make([]PublicIPv6RangeAttrModel, 0, length)
ranges := make([]ConfiguredPublicIPv6RangeAttrModel, 0, length)

// Since `ranges` list is with a default value of empty list, we may safely assume
// its elements won't contain any unknown and null
Expand All @@ -237,8 +239,8 @@ func (plan *PublicIPv4AddressAttrModel) GetCreateOptions(ctx context.Context) (o
return opts
}

func (plan *PublicIPv6RangeAttrModel) GetCreateOptions(ctx context.Context) (opts linodego.PublicInterfaceIPv6RangeCreateOptions) {
tflog.Trace(ctx, "Enter PublicIPv6RangeAttrModel.GetCreateOptions")
func (plan *ConfiguredPublicIPv6RangeAttrModel) GetCreateOptions(ctx context.Context) (opts linodego.PublicInterfaceIPv6RangeCreateOptions) {
tflog.Trace(ctx, "Enter ConfiguredPublicIPv6RangeAttrModel.GetCreateOptions")

opts.Range = plan.Range.ValueString()
return opts
Expand All @@ -250,7 +252,7 @@ func (data *PublicAttrModel) FlattenPublicInterface(
tflog.Trace(ctx, "Enter PublicAttrModel.FlattenPublicInterface")

flattenedPublicIPv4 := helper.KeepOrUpdateSingleNestedAttributesWithTypes(
ctx, data.IPv4, publicIPv4Attribute.GetType().(types.ObjectType).AttrTypes, preserveKnown, diags,
ctx, data.IPv4, resourcePublicIPv4Attribute.GetType().(types.ObjectType).AttrTypes, preserveKnown, diags,
func(publicIPv4 *PublicIPv4AttrModel, isNull *bool, pk bool, d *diag.Diagnostics) {
if publicInterface.IPv4 == nil {
*isNull = true
Expand All @@ -276,7 +278,7 @@ func (data *PublicAttrModel) FlattenPublicInterface(
data.IPv4 = *flattenedPublicIPv4

flattenedPublicIPv6 := helper.KeepOrUpdateSingleNestedAttributesWithTypes(
ctx, data.IPv6, publicIPv6Attribute.GetType().(types.ObjectType).AttrTypes, preserveKnown, diags,
ctx, data.IPv6, resourcePublicIPv6Attribute.GetType().(types.ObjectType).AttrTypes, preserveKnown, diags,
func(publicIPv6 *PublicIPv6AttrModel, isNull *bool, pk bool, d *diag.Diagnostics) {
if publicInterface.IPv6 == nil {
*isNull = true
Expand All @@ -290,7 +292,7 @@ func (data *PublicAttrModel) FlattenPublicInterface(
publicIPv6.Shared, types.SetNull(computedPublicInterfaceIPv6Range.GetAttributes().Type()), pk,
)
publicIPv6.SLAAC = helper.KeepOrUpdateValue(
publicIPv6.SLAAC, types.SetNull(publicInterfaceIPv6SLAAC.GetAttributes().Type()), pk,
publicIPv6.SLAAC, types.SetNull(resourcePublicInterfaceIPv6SLAAC.GetAttributes().Type()), pk,
)
return
}
Expand Down
36 changes: 19 additions & 17 deletions linode/linodeinterface/framework_resource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package linodeinterface

import (
"github.com/hashicorp/terraform-plugin-framework-nettypes/cidrtypes"
"github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
Expand Down Expand Up @@ -58,26 +59,24 @@ var configuredPublicInterfaceIPv6Range = schema.NestedAttributeObject{
"range": schema.StringAttribute{
Required: true,
},
"route_target": schema.StringAttribute{
Description: "The public IPv6 address that the range is routed to.",
Optional: true,
},
},
}

var computedPublicInterfaceIPv6Range = schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"range": schema.StringAttribute{
Computed: true,
CustomType: cidrtypes.IPv6PrefixType{},
Computed: true,
},
"route_target": schema.StringAttribute{
Description: "The public IPv6 address that the range is routed to.",
CustomType: iptypes.IPv6AddressType{},
Computed: true,
},
},
}

var publicInterfaceIPv6SLAAC = schema.NestedAttributeObject{
var resourcePublicInterfaceIPv6SLAAC = schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"address": schema.StringAttribute{
PlanModifiers: []planmodifier.String{
Expand Down Expand Up @@ -160,10 +159,12 @@ var computedVPCInterfaceIPv6SLAAC = schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"range": schema.StringAttribute{
Description: "The IPv6 network range in CIDR notation.",
CustomType: cidrtypes.IPv6PrefixType{},
Computed: true,
},
"address": schema.StringAttribute{
Description: "The assigned IPv6 address within the range.",
CustomType: iptypes.IPv6AddressType{},
Computed: true,
},
},
Expand All @@ -184,12 +185,13 @@ var computedVPCInterfaceIPv6Range = schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"range": schema.StringAttribute{
Description: "The IPv6 network range in CIDR notation.",
CustomType: cidrtypes.IPv6PrefixType{},
Computed: true,
},
},
}

var publicIPv4Attribute = schema.SingleNestedAttribute{
var resourcePublicIPv4Attribute = schema.SingleNestedAttribute{
Description: "IPv4 addresses for this interface.",
Optional: true,
Computed: true,
Expand Down Expand Up @@ -226,7 +228,7 @@ var publicIPv4Attribute = schema.SingleNestedAttribute{
},
}

var publicIPv6Attribute = schema.SingleNestedAttribute{
var resourcePublicIPv6Attribute = schema.SingleNestedAttribute{
Description: "IPv6 addresses for this interface.",
Optional: true,
Computed: true,
Expand Down Expand Up @@ -267,12 +269,12 @@ var publicIPv6Attribute = schema.SingleNestedAttribute{
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
NestedObject: publicInterfaceIPv6SLAAC,
NestedObject: resourcePublicInterfaceIPv6SLAAC,
},
},
}

var publicInterfaceSchema = schema.SingleNestedAttribute{
var resourcePublicInterfaceAttribute = schema.SingleNestedAttribute{
Description: "Linode public interface.",
Optional: true,
Validators: []validator.Object{
Expand All @@ -282,12 +284,12 @@ var publicInterfaceSchema = schema.SingleNestedAttribute{
),
},
Attributes: map[string]schema.Attribute{
"ipv4": publicIPv4Attribute,
"ipv6": publicIPv6Attribute,
"ipv4": resourcePublicIPv4Attribute,
"ipv6": resourcePublicIPv6Attribute,
},
}

var vpcIPv4Attribute = schema.SingleNestedAttribute{
var resourceVPCIPv4Attribute = schema.SingleNestedAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Object{
Expand Down Expand Up @@ -333,7 +335,7 @@ var vpcIPv4Attribute = schema.SingleNestedAttribute{
},
}

var vpcIPv6Attribute = schema.SingleNestedAttribute{
var resourceVPCIPv6Attribute = schema.SingleNestedAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Object{
Expand Down Expand Up @@ -394,8 +396,8 @@ var vpcInterfaceSchema = schema.SingleNestedAttribute{
),
},
Attributes: map[string]schema.Attribute{
"ipv4": vpcIPv4Attribute,
"ipv6": vpcIPv6Attribute,
"ipv4": resourceVPCIPv4Attribute,
"ipv6": resourceVPCIPv6Attribute,
"subnet_id": schema.Int64Attribute{
Required: true,
Description: "The VPC subnet identifier for this interface.",
Expand Down Expand Up @@ -455,7 +457,7 @@ var frameworkResourceSchema = schema.Schema{
},
},
},
"public": publicInterfaceSchema,
"public": resourcePublicInterfaceAttribute,
"vlan": schema.SingleNestedAttribute{
Description: "Linode VLAN interface.",
Optional: true,
Expand Down
4 changes: 2 additions & 2 deletions linode/linodeinterface/framework_vpc_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (data *VPCAttrModel) FlattenVPCInterface(
data.SubnetID = helper.KeepOrUpdateInt64(data.SubnetID, int64(vpcInterface.SubnetID), preserveKnown)

flattenedIPv4 := helper.KeepOrUpdateSingleNestedAttributesWithTypes(
ctx, data.IPv4, vpcIPv4Attribute.GetType().(basetypes.ObjectType).AttrTypes, preserveKnown, diags,
ctx, data.IPv4, resourceVPCIPv4Attribute.GetType().(basetypes.ObjectType).AttrTypes, preserveKnown, diags,
func(ipv4 *VPCIPv4AttrModel, isNull *bool, pk bool, d *diag.Diagnostics) {
ipv4.FlattenVPCIPv4(ctx, vpcInterface.IPv4, pk, d)
},
Expand All @@ -219,7 +219,7 @@ func (data *VPCAttrModel) FlattenVPCInterface(
data.IPv4 = *flattenedIPv4

flattenedIPv6 := helper.KeepOrUpdateSingleNestedAttributesWithTypes(
ctx, data.IPv6, vpcIPv6Attribute.GetType().(basetypes.ObjectType).AttrTypes, preserveKnown, diags,
ctx, data.IPv6, resourceVPCIPv6Attribute.GetType().(basetypes.ObjectType).AttrTypes, preserveKnown, diags,
func(ipv6 *VPCIPv6AttrModel, isNull *bool, pk bool, d *diag.Diagnostics) {
ipv6.FlattenVPCIPv6(ctx, vpcInterface.IPv6, pk, d)
},
Expand Down