-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vrf): Added routeros_ip_vrf resource (#443)
* 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
1 parent
044bf98
commit a091b7d
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
` | ||
} |