Skip to content

Commit

Permalink
feat: Add the routeros_system_led resource to manage LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Aug 19, 2024
1 parent 82434f8 commit 5131156
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_system_led/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 [/system/leds get [print show-ids]]
terraform import routeros_system_led.sfp1 '*1'
5 changes: 5 additions & 0 deletions examples/resources/routeros_system_led/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "routeros_system_led" "sfp1" {
interface = "sfp1"
leds = ["sfp-led"]
type = "interface-activity"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func Provider() *schema.Provider {
"routeros_certificate_scep_server": ResourceCertificateScepServer(),
"routeros_system_clock": ResourceSystemClock(),
"routeros_system_identity": ResourceSystemIdentity(),
"routeros_system_led": ResourceSystemLed(),
"routeros_system_led_settings": ResourceSystemLedSettings(),
"routeros_system_logging": ResourceSystemLogging(),
"routeros_system_logging_action": ResourceSystemLoggingAction(),
Expand Down
77 changes: 77 additions & 0 deletions routeros/resource_system_led.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package routeros

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

/*
{
".id": "*1",
"default": "true",
"disabled": "false",
"interface": "sfp1",
"leds": "sfp-led",
"type": "interface-activity"
}
*/

// https://help.mikrotik.com/docs/display/ROS/LEDs
func ResourceSystemLed() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/system/leds"),
MetaId: PropId(Id),

"default": {
Type: schema.TypeBool,
Computed: true,
},
KeyDisabled: PropDisabledRw,
"interface": {
Type: schema.TypeString,
Optional: true,
Description: "An option to set the interface to which the LED is connected.",
ValidateFunc: validation.StringIsNotWhiteSpace,
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"leds": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "An option to set the LED name.",
},
"modem_signal_treshold": {
Type: schema.TypeInt,
Optional: true,
Description: "An option to set the signal strength threshold for the modem LED.",
ValidateFunc: validation.IntBetween(-113, -51),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "An option to set the LED type.",
ValidateFunc: validation.StringInSlice([]string{
"align-down", "align-left", "align-right", "align-up", "ap-cap", "fan-fault", "flash-access",
"interface-activity", "interface-receive", "interface-speed", "interface-speed-1G",
"interface-speed-25G", "interface-status", "interface-transmit",
"modem-signal", "modem-technology", "off", "on", "poe-fault", "poe-out",
"wireless-signal-strength", "wireless-status",
}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
}

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 5131156

Please sign in to comment.