Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions .web-docs/components/builder/linode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ This section outlines the fields configurable for a newer Linode interface objec

- `ipv4` (\*VPCInterfaceIPv4) - Interfaces can be configured with IPv4 addresses or ranges.

- `ipv6` (\*VPCInterfaceIPv6) - IPv6 configuration for this VPC interface.

<!-- End of code generated from the comments of the VPCInterface struct in builder/linode/linode_interfaces.go; -->


Expand Down Expand Up @@ -330,6 +332,43 @@ This section outlines the fields configurable for a newer Linode interface objec
<!-- End of code generated from the comments of the VPCInterfaceIPv4Range struct in builder/linode/linode_interfaces.go; -->


##### VPC Linode Interface IPv6 configuration object (VPCInterfaceIPv6)

###### Optional

<!-- Code generated from the comments of the VPCInterfaceIPv6 struct in builder/linode/linode_interfaces.go; DO NOT EDIT MANUALLY -->

- `slaac` ([]VPCInterfaceIPv6SLAAC) - IPv6 SLAAC settings for this VPC interface.

- `ranges` ([]VPCInterfaceIPv6Range) - IPv6 ranges for this VPC interface.

- `is_public` (\*bool) - Whether the IPv6 addresses are publicly routable.

<!-- End of code generated from the comments of the VPCInterfaceIPv6 struct in builder/linode/linode_interfaces.go; -->


##### VPC Linode Interface IPv6 SLAAC configuration object (VPCInterfaceIPv6SLAAC)

###### Required

<!-- Code generated from the comments of the VPCInterfaceIPv6SLAAC struct in builder/linode/linode_interfaces.go; DO NOT EDIT MANUALLY -->

- `range` (string) - The IPv6 SLAAC range for this VPC interface.

<!-- End of code generated from the comments of the VPCInterfaceIPv6SLAAC struct in builder/linode/linode_interfaces.go; -->


##### VPC Linode Interface IPv6 Range configuration object (VPCInterfaceIPv6Range)

###### Required

<!-- Code generated from the comments of the VPCInterfaceIPv6Range struct in builder/linode/linode_interfaces.go; DO NOT EDIT MANUALLY -->

- `range` (string) - The IPv6 range for this VPC interface.

<!-- End of code generated from the comments of the VPCInterfaceIPv6Range struct in builder/linode/linode_interfaces.go; -->


##### VLAN Linode Interface configuration object (VLANInterface)

###### Required
Expand Down
80 changes: 78 additions & 2 deletions builder/linode/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,71 @@ func TestBuilderPrepare_LinodeNetworkInterfaces(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}

config["linode_interface"] = []map[string]any{
{
"firewall_id": 123,
"default_route": map[string]any{
"ipv4": true,
"ipv6": true,
},
"public": map[string]any{
"ipv4": map[string]any{
"address": []map[string]any{
{
"address": "auto",
"primary": true,
},
},
},
"ipv6": map[string]any{
"ranges": []map[string]any{
{
"range": "/64",
},
},
},
},
},
{
"firewall_id": 123,
"default_route": map[string]any{
"ipv4": false,
"ipv6": false,
},
"vpc": map[string]any{
"subnet_id": 12345,
"ipv4": map[string]any{
"addresses": []map[string]any{
{"address": "auto", "primary": false, "nat_1_1_address": "auto"},
},
},
"ipv6": map[string]any{
"slaac": []map[string]any{
{
"range": "2600:3c03:e000:123::/64",
},
},
"ranges": []map[string]any{
{
"range": "2600:3c03:e000:123:1::/64",
},
},
"is_public": true,
},
},
},
{
"default_route": map[string]any{
"ipv4": false,
"ipv6": false,
},
"vlan": map[string]any{
"vlan_label": "vlan-1",
"ipam_address": "10.0.0.1/24",
},
},
}

expectedLinodeInterfaces := []LinodeInterface{
{
FirewallID: linodego.Pointer(123),
Expand Down Expand Up @@ -611,6 +676,19 @@ func TestBuilderPrepare_LinodeNetworkInterfaces(t *testing.T) {
},
},
},
IPv6: &VPCInterfaceIPv6{
SLAAC: []VPCInterfaceIPv6SLAAC{
{
Range: "2600:3c03:e000:123::/64",
},
},
Ranges: []VPCInterfaceIPv6Range{
{
Range: "2600:3c03:e000:123:1::/64",
},
},
IsPublic: linodego.Pointer(true),
},
},
},
{
Expand All @@ -625,8 +703,6 @@ func TestBuilderPrepare_LinodeNetworkInterfaces(t *testing.T) {
},
}

// Test set
config["linode_interface"] = expectedLinodeInterfaces
b = Builder{}
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
Expand Down
27 changes: 26 additions & 1 deletion builder/linode/linode_interfaces.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type LinodeInterface,InterfaceDefaultRoute,PublicInterface,PublicInterfaceIPv4,PublicInterfaceIPv6,PublicInterfaceIPv4Address,PublicInterfaceIPv6Range,VPCInterface,VPCInterfaceIPv4,VPCInterfaceIPv4Address,VPCInterfaceIPv4Range,VLANInterface
//go:generate packer-sdc mapstructure-to-hcl2 -type LinodeInterface,InterfaceDefaultRoute,PublicInterface,PublicInterfaceIPv4,PublicInterfaceIPv6,PublicInterfaceIPv4Address,PublicInterfaceIPv6Range,VPCInterface,VPCInterfaceIPv4,VPCInterfaceIPv4Address,VPCInterfaceIPv4Range,VPCInterfaceIPv6,VPCInterfaceIPv6SLAAC,VPCInterfaceIPv6Range,VLANInterface
package linode

type LinodeInterface struct {
Expand Down Expand Up @@ -79,7 +79,11 @@ type VPCInterface struct {

// Interfaces can be configured with IPv4 addresses or ranges.
IPv4 *VPCInterfaceIPv4 `mapstructure:"ipv4" required:"false"`

// IPv6 configuration for this VPC interface.
IPv6 *VPCInterfaceIPv6 `mapstructure:"ipv6" required:"false"`
}

type VPCInterfaceIPv4 struct {
// IPv4 address settings for this VPC interface.
Addresses []VPCInterfaceIPv4Address `mapstructure:"addresses" required:"false"`
Expand Down Expand Up @@ -110,6 +114,27 @@ type VPCInterfaceIPv4Range struct {
Range string `mapstructure:"range" required:"true"`
}

type VPCInterfaceIPv6 struct {
// IPv6 SLAAC settings for this VPC interface.
SLAAC []VPCInterfaceIPv6SLAAC `mapstructure:"slaac" required:"false"`

// IPv6 ranges for this VPC interface.
Ranges []VPCInterfaceIPv6Range `mapstructure:"ranges" required:"false"`

// Whether the IPv6 addresses are publicly routable.
IsPublic *bool `mapstructure:"is_public" required:"false"`
}

type VPCInterfaceIPv6SLAAC struct {
// The IPv6 SLAAC range for this VPC interface.
Range string `mapstructure:"range" required:"true"`
}

type VPCInterfaceIPv6Range struct {
// The IPv6 range for this VPC interface.
Range string `mapstructure:"range" required:"true"`
}

type VLANInterface struct {
// The VLAN's unique label. VLAN interfaces on the same Linode must have a unique `vlan_label`.
VLANLabel string `mapstructure:"vlan_label" required:"true"`
Expand Down
75 changes: 75 additions & 0 deletions builder/linode/linode_interfaces.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions builder/linode/step_create_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ func flattenVPCInterface(vpc *VPCInterface) *linodego.VPCInterfaceCreateOptions
Ranges: linodego.Pointer(ranges),
}
}
if vpc.IPv6 != nil {
slaac := make([]linodego.VPCInterfaceIPv6SLAACCreateOptions, len(vpc.IPv6.SLAAC))
ranges := make([]linodego.VPCInterfaceIPv6RangeCreateOptions, len(vpc.IPv6.Ranges))
for i, s := range vpc.IPv6.SLAAC {
slaac[i] = linodego.VPCInterfaceIPv6SLAACCreateOptions{
Range: s.Range,
}
}
for i, r := range vpc.IPv6.Ranges {
ranges[i] = linodego.VPCInterfaceIPv6RangeCreateOptions{
Range: r.Range,
}
}
result.IPv6 = &linodego.VPCInterfaceIPv6CreateOptions{
SLAAC: linodego.Pointer(slaac),
Ranges: linodego.Pointer(ranges),
IsPublic: vpc.IPv6.IsPublic,
}
}
return result
}

Expand Down
38 changes: 38 additions & 0 deletions builder/linode/step_create_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@ func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) {
}
}

func TestFlattenVPCInterface_IPv6Fields(t *testing.T) {
vpc := &VPCInterface{
SubnetID: 12345,
IPv6: &VPCInterfaceIPv6{
SLAAC: []VPCInterfaceIPv6SLAAC{
{Range: "2600:3c03:e000:123::/64"},
},
Ranges: []VPCInterfaceIPv6Range{
{Range: "2600:3c03:e000:123:1::/64"},
},
IsPublic: linodego.Pointer(true),
},
}

got := flattenVPCInterface(vpc)
if got == nil {
t.Fatal("flattenVPCInterface() returned nil")
}
if got.IPv6 == nil {
t.Fatal("flattenVPCInterface().IPv6 returned nil")
}
if got.IPv6.SLAAC == nil || len(*got.IPv6.SLAAC) != 1 {
t.Fatalf("slaac = %v, want one slaac range", got.IPv6.SLAAC)
}
if (*got.IPv6.SLAAC)[0].Range != "2600:3c03:e000:123::/64" {
t.Fatalf("slaac range = %q, want 2600:3c03:e000:123::/64", (*got.IPv6.SLAAC)[0].Range)
}
if got.IPv6.Ranges == nil || len(*got.IPv6.Ranges) != 1 {
t.Fatalf("ranges = %v, want one ipv6 range", got.IPv6.Ranges)
}
if (*got.IPv6.Ranges)[0].Range != "2600:3c03:e000:123:1::/64" {
t.Fatalf("range = %q, want 2600:3c03:e000:123:1::/64", (*got.IPv6.Ranges)[0].Range)
}
if got.IPv6.IsPublic == nil || !*got.IPv6.IsPublic {
t.Fatalf("is_public = %v, want true", got.IPv6.IsPublic)
}
}

func TestFlattenConfigInterface_AllFields(t *testing.T) {
vpcIP := &InterfaceIPv4{VPC: "10.0.0.2", NAT1To1: linodego.Pointer("198.51.100.2")}
iface := Interface{
Expand Down
18 changes: 18 additions & 0 deletions docs/builders/linode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ This section outlines the fields configurable for a newer Linode interface objec

@include 'builder/linode/VPCInterfaceIPv4Range-required.mdx'

##### VPC Linode Interface IPv6 configuration object (VPCInterfaceIPv6)

###### Optional

@include 'builder/linode/VPCInterfaceIPv6-not-required.mdx'

##### VPC Linode Interface IPv6 SLAAC configuration object (VPCInterfaceIPv6SLAAC)

###### Required

@include 'builder/linode/VPCInterfaceIPv6SLAAC-required.mdx'

##### VPC Linode Interface IPv6 Range configuration object (VPCInterfaceIPv6Range)

###### Required

@include 'builder/linode/VPCInterfaceIPv6Range-required.mdx'

##### VLAN Linode Interface configuration object (VLANInterface)

###### Required
Expand Down
Loading