Skip to content

Commit

Permalink
Merge pull request #597 from terraform-routeros/vaerh/issue596
Browse files Browse the repository at this point in the history
feat(ipv6): Add new resource `routeros_ipv6_settings`
  • Loading branch information
vaerh authored Nov 14, 2024
2 parents 76633b8 + 4410ddc commit 6b6d063
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/resources/routeros_ipv6_settings/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import routeros_ipv6_settings.settings .
3 changes: 3 additions & 0 deletions examples/resources/routeros_ipv6_settings/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "routeros_ipv6_settings" "settings" {
accept_redirects = "no"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func Provider() *schema.Provider {
"routeros_ipv6_neighbor_discovery": ResourceIPv6NeighborDiscovery(),
"routeros_ipv6_pool": ResourceIpv6Pool(),
"routeros_ipv6_route": ResourceIPv6Route(),
"routeros_ipv6_settings": ResourceIpv6Settings(),

// Aliases for IP objects to retain compatibility between original and fork
"routeros_dhcp_client": ResourceDhcpClient(),
Expand Down
83 changes: 83 additions & 0 deletions routeros/resource_ipv6_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package routeros

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

/*
{
"accept-redirects": "yes-if-forwarding-disabled",
"accept-router-advertisements": "yes-if-forwarding-disabled",
"disable-ipv6": "false",
"forward": "true",
"max-neighbor-entries": "8192"
}
*/

// https://help.mikrotik.com/docs/spaces/ROS/pages/103841817/IP+Settings#IPSettings-IPv6Settings
func ResourceIpv6Settings() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ipv6/settings"),
MetaId: PropId(Id),

"accept_redirects": {
Type: schema.TypeString,
Optional: true,
Description: "Whether to accept ICMP redirect messages. Typically should be enabled on the host and disabled " +
"on routers.",
ValidateFunc: validation.StringInSlice([]string{"no", "yes-if-forwarding-disabled"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"accept_router_advertisements": {
Type: schema.TypeString,
Optional: true,
Description: "Accept router advertisement (RA) messages. If enabled, the router will be able to get the " +
"address using stateless address configuration.",
ValidateFunc: validation.StringInSlice([]string{"no", "yes", "yes-if-forwarding-disabled"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"disable_ipv6": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable/disable system wide IPv6 settings (prevents LL address generation).",
},
"forward": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable/disable packet forwarding between interfaces.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"max_neighbor_entries": {
Type: schema.TypeInt,
Optional: true,
Description: "A maximum number or IPv6 neighbors. Since RouterOS version 7.1, the default value depends " +
"on the installed amount of RAM. It is possible to set a higher value than the default, but it increases " +
"the risk of out-of-memory condition. The default values for certain RAM sizes:\n * 1024 for 64 MB,\n * 2048 " +
"for 128 MB,\n * 4096 for 256 MB,\n * 8192 for 512 MB,\n * 16384 for 1024 MB or higher.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"multipath_hash_policy": {
Type: schema.TypeString,
Optional: true,
Description: "IPv6 Hash policy used for ECMP routing in `/ipv6/settings` menu\n * l3 -- layer-3 hashing of src " +
"IP, dst IP, flow label, IP protocol\n * l3-inner -- layer-3 hashing or inner layer-3 hashing if available" +
"\n * l4 -- layer-4 hashing of src IP, dst IP, IP protocol, src port, dst port.",
ValidateFunc: validation.StringInSlice([]string{"l3", "l4", "l3-inner"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
}

return &schema.Resource{
CreateContext: DefaultSystemCreate(resSchema),
ReadContext: DefaultSystemRead(resSchema),
UpdateContext: DefaultSystemUpdate(resSchema),
DeleteContext: DefaultSystemDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}
50 changes: 50 additions & 0 deletions routeros/resource_ipv6_settings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testIpv6Settings = "routeros_ipv6_settings.settings"

func TestAccIpv6SettingsTest_basic(t *testing.T) {
for _, name := range testNames {
t.Run(name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testSetTransportEnv(t, name)
},
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccIpv6SettingsConfig("no"),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpv6Settings),
resource.TestCheckResourceAttr(testIpv6Settings, "accept_redirects", "no"),
),
},
{
Config: testAccIpv6SettingsConfig("yes-if-forwarding-disabled"),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpv6Settings),
resource.TestCheckResourceAttr(testIpv6Settings, "accept_redirects", "yes-if-forwarding-disabled"),
),
},
},
})

})
}
}

func testAccIpv6SettingsConfig(param string) string {
return fmt.Sprintf(`%v
resource "routeros_ipv6_settings" "settings" {
accept_redirects = "%v"
}
`, providerConfig, param)
}

0 comments on commit 6b6d063

Please sign in to comment.