Skip to content

Commit

Permalink
feat: Add routeros_zerotier resource to manage ZeroTier instances
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Mar 26, 2024
1 parent b930215 commit f182f0c
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_zerotier/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 get [print show-ids]]
terraform import routeros_zerotier.zt1 '*1'
8 changes: 8 additions & 0 deletions examples/resources/routeros_zerotier/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "zerotier_identity" "identity" {}

resource "routeros_zerotier" "zt1" {
comment = "ZeroTier Central"
identity = zerotier_identity.identity.private_key
interfaces = ["all"]
name = "zt1"
}
3 changes: 3 additions & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ func Provider() *schema.Provider {
"routeros_wifi_provisioning": ResourceWifiProvisioning(),
"routeros_wifi_security": ResourceWifiSecurity(),
"routeros_wifi_steering": ResourceWifiSteering(),

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

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

/*
{
".id": "*1",
"comment": "ZeroTier Central controller - https://my.zerotier.com/",
"disabled": "false",
"identity": "...",
"identity.public": "...",
"interfaces": "all",
"name": "zt1",
"online": "true",
"port": "9993",
"route-distance": "1",
"state": "running"
}
*/

// https://help.mikrotik.com/docs/display/ROS/ZeroTier#ZeroTier-Parameters
func ResourceZerotier() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/zerotier"),
MetaId: PropId(Id),
MetaTransformSet: PropTransformSet(`"identity.public": "identity_public"`),

KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"identity": {
Type: schema.TypeString,
Optional: true,
Description: "The 40-bit unique instance address.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"identity_public": {
Type: schema.TypeString,
Computed: true,
Description: "The public identity of the ZeroTier instance.",
},
"interfaces": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The interfaces to discover ZeroTier peers by ARP and IP type connections.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyName: PropName("Name of the ZeroTier instance."),
"online": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the ZeroTier instance is currently online.",
},
"port": {
Type: schema.TypeInt,
Optional: true,
Default: 9993,
Description: "The port number the instance listens to.",
ValidateFunc: validation.IntBetween(1, 65535),
},
"route_distance": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
Description: "The route distance for routes obtained from the planet/moon server.",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "The state of the ZeroTier instance.",
},
}

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 f182f0c

Please sign in to comment.