diff --git a/examples/resources/routeros_interface_6to4/import.sh b/examples/resources/routeros_interface_6to4/import.sh new file mode 100644 index 00000000..e9347eba --- /dev/null +++ b/examples/resources/routeros_interface_6to4/import.sh @@ -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" \ No newline at end of file diff --git a/examples/resources/routeros_interface_6to4/resource.tf b/examples/resources/routeros_interface_6to4/resource.tf new file mode 100644 index 00000000..990cb892 --- /dev/null +++ b/examples/resources/routeros_interface_6to4/resource.tf @@ -0,0 +1,4 @@ +resource "routeros_interface_6to4" "test" { + name = "6to4-tunnel1" + keepalive = "10,10" +} diff --git a/routeros/provider.go b/routeros/provider.go index 4aa9cefe..0587d715 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -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(), diff --git a/routeros/resource_interface_6to4.go b/routeros/resource_interface_6to4.go new file mode 100644 index 00000000..c968ff11 --- /dev/null +++ b/routeros/resource_interface_6to4.go @@ -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, + } +} diff --git a/routeros/resource_interface_6to4_test.go b/routeros/resource_interface_6to4_test.go new file mode 100644 index 00000000..d0babd9f --- /dev/null +++ b/routeros/resource_interface_6to4_test.go @@ -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) +}