diff --git a/examples/resources/routeros_system_led/import.sh b/examples/resources/routeros_system_led/import.sh new file mode 100644 index 00000000..252be8b9 --- /dev/null +++ b/examples/resources/routeros_system_led/import.sh @@ -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' diff --git a/examples/resources/routeros_system_led/resource.tf b/examples/resources/routeros_system_led/resource.tf new file mode 100644 index 00000000..df252d27 --- /dev/null +++ b/examples/resources/routeros_system_led/resource.tf @@ -0,0 +1,5 @@ +resource "routeros_system_led" "sfp1" { + interface = "sfp1" + leds = ["sfp-led"] + type = "interface-activity" +} diff --git a/routeros/provider.go b/routeros/provider.go index 92c99fb4..3abb0141 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -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(), diff --git a/routeros/resource_system_led.go b/routeros/resource_system_led.go new file mode 100644 index 00000000..832e92ea --- /dev/null +++ b/routeros/resource_system_led.go @@ -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, + } +}