Skip to content

Commit

Permalink
feat(ipv6): Add new resource routeros_interface_6to4
Browse files Browse the repository at this point in the history
Fixes #593
  • Loading branch information
vaerh committed Nov 12, 2024
1 parent 32ee5bc commit 742e6bd
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/resources/routeros_interface_6to4/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/6to4 get [print show-ids]]
terraform import routeros_interface_6to4.test *3
#Or you can import a resource using one of its attributes
terraform import routeros_interface_6to4.test "name=6to4-tunnel1"
4 changes: 4 additions & 0 deletions examples/resources/routeros_interface_6to4/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_interface_6to4" "test" {
name = "6to4-tunnel1"
keepalive = "10,10"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func Provider() *schema.Provider {
"routeros_dns_record": ResourceDnsRecord(),

// Interface Objects
"routeros_interface_6to4": ResourceInterface6to4(),
"routeros_interface_bonding": ResourceInterfaceBonding(),
"routeros_interface_bridge_port": ResourceInterfaceBridgePort(),
"routeros_interface_bridge_settings": ResourceInterfaceBridgeSettings(),
Expand Down
56 changes: 56 additions & 0 deletions routeros/resource_interface_6to4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package routeros

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

/*
{
".id": "*3",
"actual-mtu": "1480",
"clamp-tcp-mss": "true",
"disabled": "false",
"dont-fragment": "no",
"dscp": "inherit",
"local-address": "0.0.0.0",
"mtu": "auto",
"name": "6to4-tunnel1",
"remote-address": "unspecified",
"running": "true"
}
*/

// https://help.mikrotik.com/docs/spaces/ROS/pages/135004174/6to4
func ResourceInterface6to4() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/6to4"),
MetaId: PropId(Id),

KeyActualMtu: PropActualMtuRo,
KeyClampTcpMss: PropClampTcpMssRw,
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
KeyDontFragment: PropDontFragmentRw,
KeyDscp: PropDscpRw,
KeyIpsecSecret: PropIpsecSecretRw,
KeyKeepalive: PropKeepaliveRw,
KeyLocalAddress: PropLocalAddressRw,
KeyMtu: PropMtuRw(),
KeyName: PropName("Interface name."),
KeyRemoteAddress: PropRemoteAddressRw,
KeyRunning: PropRunningRo,
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: ImportStateCustomContext(resSchema),
},

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

import (
"fmt"
"testing"

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

const testInterface6to4 = "routeros_interface_6to4.test"

func TestAccInterface6to4Test_basic(t *testing.T) {
t.Parallel()
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,
CheckDestroy: testCheckResourceDestroy("/interface/6to4", "routeros_interface_6to4"),
Steps: []resource.TestStep{
{
Config: testAccInterface6to4Config(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testInterface6to4),
resource.TestCheckResourceAttr(testInterface6to4, "name", "6to4-tunnel1"),
resource.TestCheckResourceAttr(testInterface6to4, "keepalive", "10s,10"),
),
},
},
})

})
}
}

func testAccInterface6to4Config() string {
return fmt.Sprintf(`%v
resource "routeros_interface_6to4" "test" {
name = "6to4-tunnel1"
keepalive = "10,10"
}
`, providerConfig)
}

0 comments on commit 742e6bd

Please sign in to comment.