Skip to content

Commit

Permalink
feat(vrf): Added routeros_ip_vrf resource (#443)
Browse files Browse the repository at this point in the history
* added routeros_ip_vrf resource

Signed-off-by: dn <dn@nuvotex.de>

* fix(veth): Remove deprecated options

* test(vrf): Test with virtual interfaces

---------

Signed-off-by: dn <dn@nuvotex.de>
Co-authored-by: vaerh <64400271+vaerh@users.noreply.github.com>
Co-authored-by: Vaerh <vaerh@tutanota.com>
  • Loading branch information
3 people committed May 7, 2024
1 parent 044bf98 commit a091b7d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func Provider() *schema.Provider {
"routeros_ip_ssh_server": ResourceIpSSHServer(),
"routeros_ip_upnp": ResourceUPNPSettings(),
"routeros_ip_upnp_interfaces": ResourceUPNPInterfaces(),
"routeros_ip_vrf": ResourceIPVrf(),
"routeros_ipv6_address": ResourceIPv6Address(),
"routeros_ipv6_dhcp_client": ResourceIPv6DhcpClient(),
"routeros_ipv6_dhcp_client_option": ResourceIPv6DhcpClientOption(),
Expand Down
4 changes: 1 addition & 3 deletions routeros/resource_interface_veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ResourceInterfaceVeth() *schema.Resource {

"address": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "IP address.",
ValidateFunc: validation.IsCIDR,
},
Expand All @@ -36,14 +36,12 @@ func ResourceInterfaceVeth() *schema.Resource {
Optional: true,
Description: "Gateway IP address.",
ValidateFunc: validation.IsIPv4Address,
AtLeastOneOf: []string{"gateway", "gateway6"},
},
"gateway6": {
Type: schema.TypeString,
Optional: true,
Description: "Gateway IPv6 address.",
ValidateFunc: validation.IsIPv6Address,
AtLeastOneOf: []string{"gateway", "gateway6"},
},
KeyName: PropName("Interface name."),
KeyRunning: PropRunningRo,
Expand Down
37 changes: 37 additions & 0 deletions routeros/resource_ip_vrf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package routeros

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

// ResourceIPRoute https://wiki.mikrotik.com/wiki/Manual:Virtual_Routing_and_Forwarding
func ResourceIPVrf() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/vrf"),
MetaId: PropId(Id),

KeyDisabled: PropDisabledRw,
KeyComment: PropCommentRw,
KeyName: PropName("Unique name of the VRF."),
"interfaces": {
Type: schema.TypeSet,
Required: true,
Description: "At least one interface must be added to the VRF.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
MinItems: 1,
},
}
return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

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

import (
"testing"

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

func TestAccIpVrfTest_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,
CheckDestroy: testCheckResourceDestroy("/ip/vrf", "routeros_ip_vrf"),
Steps: []resource.TestStep{
{
Config: testAccIpVrfConfig(),
Check: resource.ComposeTestCheckFunc(
// A
testResourcePrimaryInstanceId("routeros_ip_vrf.test_vrf_a"),
resource.TestCheckResourceAttr("routeros_ip_vrf.test_vrf_a", "disabled", "true"),
resource.TestCheckResourceAttr("routeros_ip_vrf.test_vrf_a", "name", "vrf_1"),
),
},
},
})

})
}
}

func testAccIpVrfConfig() string {
return providerConfig + `
resource "routeros_interface_veth" "veth1" {
name = "veth1"
}
resource "routeros_interface_veth" "veth2" {
name = "veth2"
}
resource "routeros_ip_vrf" "test_vrf_a" {
disabled = true
name = "vrf_1"
interfaces = ["veth1", "veth2"]
depends_on = [routeros_interface_veth.veth1, routeros_interface_veth.veth2]
}
`
}

0 comments on commit a091b7d

Please sign in to comment.