Skip to content

Commit

Permalink
feat: Add routeros_zerotier_controller resource to manage ZeroTier …
Browse files Browse the repository at this point in the history
…controller
  • Loading branch information
dokmic authored and vaerh committed Mar 26, 2024
1 parent 481709c commit 68cb99a
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_zerotier_controller/import.sh
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 -> :put [/zerotier/controller get [print show-ids]]
terraform import routeros_zerotier_controller.test '*1'
15 changes: 15 additions & 0 deletions examples/resources/routeros_zerotier_controller/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "zerotier_identity" "identity" {}

resource "routeros_zerotier" "zt1" {
comment = "ZeroTier Central"
identity = zerotier_identity.identity.private_key
interfaces = ["all"]
name = "zt1"
}

resource "routeros_zerotier_controller" "test" {
instance = routeros_zerotier.zt1.name
name = "test"
network = "1234567812345678"
private = true
}
5 changes: 3 additions & 2 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ func Provider() *schema.Provider {
"routeros_wifi_steering": ResourceWifiSteering(),

// ZeroTier
"routeros_zerotier": ResourceZerotier(),
"routeros_zerotier_interface": ResourceZerotierInterface(),
"routeros_zerotier": ResourceZerotier(),
"routeros_zerotier_controller": ResourceZerotierController(),
"routeros_zerotier_interface": ResourceZerotierInterface(),
},
DataSourcesMap: map[string]*schema.Resource{
"routeros_firewall": DatasourceFirewall(),
Expand Down
113 changes: 113 additions & 0 deletions routeros/resource_zerotier_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package routeros

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

/*
{
".id": "*1",
"broadcast": "false",
"comment": "Something",
"disabled": "false",
"inactive": "true",
"instance": "zt1",
"ip-range": "192.168.88.200-192.168.88.220",
"ip6-6plane": "false",
"ip6-range": "fd00:feed:feed:beef::-fd00:feed:feed:beef:ffff:ffff:ffff:ffff",
"ip6-rfc4193": "false",
"mtu": "1598",
"multicast-limit": "32",
"name": "test",
"network": "1234567812345678",
"private": "true",
"routes": "192.168.88.0/24@192.168.88.1,0.0.0.0/0@192.168.88.1"
}
*/

// https://help.mikrotik.com/docs/display/ROS/ZeroTier#ZeroTier-Parameters.1
func ResourceZerotierController() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/zerotier/controller"),
MetaId: PropId(Id),

"broadcast": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "An option to allow receiving broadcast packets.",
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"inactive": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the ZeroTier network is inactive.",
},
"instance": {
Type: schema.TypeString,
Required: true,
Description: "The ZeroTier instance name.",
},
"ip_range": {
Type: schema.TypeString,
Optional: true,
Description: "The IP range of the ZeroTier network.",
},
"ip6_6plane": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option to assign every member a `/80` address within a `/40` network with using NDP emulation.",
},
"ip6_range": {
Type: schema.TypeString,
Optional: true,
Description: "The IPv6 range of the ZeroTier network.",
},
"ip6_rfc4193": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option to assign every member a `/128` address within a `/88` network.",
},
KeyMtu: PropL2MtuRw,
"multicast_limit": {
Type: schema.TypeInt,
Optional: true,
Default: 32,
Description: "An option to limit the maximum recipients of a multicast packet.",
},
KeyName: PropName("Name of the ZeroTier controller."),
"network": {
Type: schema.TypeString,
Required: true,
Description: "The ZeroTier network identifier.",
},
"private": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "The ZeroTier network access control.",
},
"routes": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The routes list that will be pushed to the client.",
},
}

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

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}

0 comments on commit 68cb99a

Please sign in to comment.