Skip to content

Commit

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

resource "zerotier_network" "network" {
name = "test"
}

resource "zerotier_member" "member" {
authorized = true
member_id = zerotier_identity.identity.id
name = "test"
network_id = zerotier_network.network.id
hidden = false
allow_ethernet_bridging = true
no_auto_assign_ips = true
}

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

resource "routeros_zerotier_interface" "zerotier1" {
allow_default = false
allow_global = false
allow_managed = false
instance = routeros_zerotier.zt1.name
name = "zerotier1"
network = zerotier_network.network.id
}
3 changes: 2 additions & 1 deletion routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func Provider() *schema.Provider {
"routeros_wifi_steering": ResourceWifiSteering(),

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

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

/*
{
".id": "*1",
"allow-default": "false",
"allow-global": "false",
"allow-managed": "false",
"arp-timeout": "auto",
"bridge": "true",
"dhcp": "false",
"disabled": "false",
"instance": "zt1",
"mac-address": "00:00:00:00:00:00",
"mtu": "2800",
"name": "zerotier1",
"network": "a00000000aa00a00",
"network-name": "something",
"running": "true",
"status": "OK",
"type": "PRIVATE"
}
*/

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

"allow_default": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option to override the default route.",
},
"allow_global": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option to allow overlapping public IP space by the ZeroTier routes. .",
},
"allow_managed": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option to allow assignment of managed IPs.",
},
KeyArpTimeout: PropArpTimeoutRw,
"bridge": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the ZeroTier interface is bridged.",
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"disable_running_check": {
Type: schema.TypeBool,
Optional: true,
Description: "An option to force the `running` property to true.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"dhcp": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the ZeroTier interface obtained an IP address.",
},
"instance": {
Type: schema.TypeString,
Required: true,
Description: "The ZeroTier instance name.",
},
KeyMacAddress: PropMacAddressRo,
KeyMtu: PropL2MtuRo,
KeyName: PropName("Name of the ZeroTier interface."),
"network": {
Type: schema.TypeString,
Required: true,
Description: "The ZeroTier network identifier.",
},
"network_name": {
Type: schema.TypeString,
Computed: true,
Description: "The ZeroTier network name.",
},
KeyRunning: PropRunningRo,
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of the ZeroTier connection.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The ZeroTier network type.",
},
}

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 481709c

Please sign in to comment.