-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from mrhamburg/pr/mrhamburg/227
feat: OSPF resource
- Loading branch information
Showing
17 changed files
with
632 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> /routing/ospf/area/print show-ids | ||
terraform import routeros_routing_ospf_area.test_routing_ospf_area "*0" |
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,8 @@ | ||
resource "routeros_routing_ospf_instance" "test_routing_ospf_instance" { | ||
name = "test_routing_ospf_instance" | ||
} | ||
|
||
resource "routeros_routing_ospf_area" "test_routing_ospf_area" { | ||
name = "test_routing_ospf_area" | ||
instance = routeros_routing_ospf_instance.test_routing_ospf_instance.name | ||
} |
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,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> /routing/ospf/instance/print show-ids | ||
terraform import routeros_routing_ospf_instance.test_routing_ospf_instance "*0" |
3 changes: 3 additions & 0 deletions
3
examples/resources/routeros_routing_ospf_instance/resource.tf
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,3 @@ | ||
resource "routeros_routing_ospf_instance" "test_routing_ospf_instance" { | ||
name = "test_routing_ospf_instance" | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/resources/routeros_routing_ospf_interface_template/import.sh
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,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> /routing/ospf/interface-template/print show-ids | ||
terraform import routeros_routing_ospf_interface_template.test_routing_ospf_interface_template "*0" |
12 changes: 12 additions & 0 deletions
12
examples/resources/routeros_routing_ospf_interface_template/resource.tf
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,12 @@ | ||
resource "routeros_routing_ospf_instance" "test_routing_ospf_instance" { | ||
name = "test_routing_ospf_instance" | ||
} | ||
|
||
resource "routeros_routing_ospf_area" "test_routing_ospf_area" { | ||
name = "test_routing_ospf_area" | ||
instance = routeros_routing_ospf_instance.test_routing_ospf_instance.name | ||
} | ||
|
||
resource "routeros_routing_ospf_interface_template" "test_routing_ospf_interface_template" { | ||
area = routeros_routing_ospf_area.test_routing_ospf_area.name | ||
} |
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
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,78 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
{ | ||
".id": "*54", | ||
"name": "", | ||
"area-id": "", | ||
"default-cost": "", | ||
"instance": "", | ||
"no-summaries": "", | ||
"nssa-translate": "", | ||
"type": "", | ||
} | ||
*/ | ||
|
||
// ResourceRoutingOspfArea https://help.mikrotik.com/docs/display/ROS/OSPF | ||
func ResourceRoutingOspfArea() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/routing/ospf/area"), | ||
MetaId: PropId(Id), | ||
|
||
"area_id": { | ||
Type: schema.TypeString, | ||
Default: "0.0.0.0", | ||
Optional: true, | ||
Description: "OSPF area identifier.", | ||
}, | ||
KeyComment: PropCommentRw, | ||
"default_cost": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "Default cost of injected LSAs into the area.", | ||
}, | ||
KeyDisabled: PropDisabledRw, | ||
KeyInactive: PropInactiveRo, | ||
"instance": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the OSPF instance this area belongs to.", | ||
}, | ||
KeyName: PropNameForceNewRw, | ||
"no_summaries": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "If set then the area will not flood summary LSAs in the stub area.", | ||
}, | ||
"nssa_translate": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The parameter indicates which ABR will be used as a translator from type7 to type5 LSA.", | ||
ValidateFunc: validation.StringInSlice([]string{"no", "yes", "candidate"}, false), | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "default", | ||
Description: "The area type.", | ||
ValidateFunc: validation.StringInSlice([]string{"default", "nssa", "stub"}, false), | ||
}, | ||
} | ||
|
||
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,67 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
const testRoutingOspfArea = "routeros_routing_ospf_area.test_routing_ospf_area" | ||
|
||
func TestAccRoutingOspfInstanceArea_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("/routing/ospf/area", "routeros_routing_ospf_area"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckRoutingOspfAreaConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckRoutingOspfAreaExists(testRoutingOspfArea), | ||
resource.TestCheckResourceAttr(testRoutingOspfArea, "name", "test_routing_ospf_area"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccCheckRoutingOspfAreaExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", name) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no id is set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckRoutingOspfAreaConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_routing_ospf_instance" "test_routing_ospf_instance" { | ||
name = "test_routing_ospf_instance" | ||
disabled = false | ||
} | ||
resource "routeros_routing_ospf_area" "test_routing_ospf_area" { | ||
name = "test_routing_ospf_area" | ||
disabled = true | ||
instance = routeros_routing_ospf_instance.test_routing_ospf_instance.name | ||
} | ||
` | ||
} |
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,129 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
{ | ||
".id": "*54", | ||
"name": "", | ||
"domain-id": "", | ||
"domain-tag": "", | ||
"in-filter": "", | ||
"mpls-te-address": "", | ||
"mpls-te-area": "", | ||
"originate-default": "", | ||
"out-filter-chain": "", | ||
"out-filter-select": "", | ||
"redistribute": "", | ||
"router-id": "", | ||
"version": "", | ||
"vrf": "", | ||
"use-dn": "" // is not present in version 7.9 | ||
} | ||
*/ | ||
|
||
// ResourceRoutingOspfInstance https://help.mikrotik.com/docs/display/ROS/OSPF | ||
func ResourceRoutingOspfInstance() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/routing/ospf/instance"), | ||
MetaId: PropId(Id), | ||
|
||
KeyComment: PropCommentRw, | ||
KeyDisabled: PropDisabledRw, | ||
"domain_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "MPLS-related parameter.", | ||
}, | ||
"domain_tag": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "if set, then used in route redistribution (as route-tag in all external LSAs " + | ||
"generated by this router), and in route calculation (all external LSAs having this route " + | ||
"tag are ignored). Needed for interoperability with older Cisco systems. By default not set.", | ||
}, | ||
KeyInactive: PropInactiveRo, | ||
"in_filter_chain": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "name of the routing filter chain used for incoming prefixes", | ||
}, | ||
"mpls_te_address": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "the area used for MPLS traffic engineering.", | ||
}, | ||
"mpls_te_area": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "the area used for MPLS traffic engineering.", | ||
}, | ||
KeyName: PropNameForceNewRw, | ||
"originate_default": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specifies default route (0.0.0.0/0) distribution method.", | ||
ValidateFunc: validation.StringInSlice([]string{"always", "if-installed", "never"}, false), | ||
}, | ||
"out_filter_chain": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "name of the routing filter chain used for outgoing prefixes filtering.", | ||
}, | ||
"out_filter_select": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "name of the routing filter select chain, used for output selection.", | ||
}, | ||
"redistribute": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Description: "Enable redistribution of specific route types.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateDiagFunc: ValidationMultiValInSlice([]string{"bgp", "connected", "copy", "dhcp", "fantasy", "modem", | ||
"ospf", "rip", "static", "vpn"}, false, false), | ||
}, | ||
}, | ||
"router_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "main", | ||
Description: "OSPF Router ID. Can be set explicitly as an IP address, or as the name " + | ||
"of the router-id instance.", | ||
}, | ||
"routing_table": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Name of the routing table in use.", | ||
}, | ||
"version": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 2, | ||
Description: "OSPF version this instance will be running (v2 for IPv4, v3 for IPv6).", | ||
ValidateFunc: validation.IntBetween(2, 3), | ||
}, | ||
"vrf": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "main", | ||
Description: "The VRF table this OSPF instance operates on", | ||
}, | ||
} | ||
|
||
return &schema.Resource{ | ||
CreateContext: DefaultCreate(resSchema), | ||
ReadContext: DefaultRead(resSchema), | ||
UpdateContext: DefaultUpdate(resSchema), | ||
DeleteContext: DefaultDelete(resSchema), | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: resSchema, | ||
} | ||
} |
Oops, something went wrong.