From 92d966fd3b7fe89aaf8d86b53007d2014606fa15 Mon Sep 17 00:00:00 2001 From: Vaerh Date: Wed, 29 May 2024 08:18:38 +0300 Subject: [PATCH 1/4] fix(certificate-scep-server): Rename the resource from "routeros_certificate_scep_server" to "routeros_system_certificate_scep_server" Fixes: #473 --- .../import.sh | 2 +- .../resource.tf | 3 +- routeros/provider.go | 31 ++++++++++--------- ...esource_system_certificate_scep_server.go} | 0 ...ce_system_certificate_scep_server_test.go} | 0 .../resources/certificate_scep_server.md.tmpl | 5 +++ 6 files changed, 24 insertions(+), 17 deletions(-) rename examples/resources/{routeros_certificate_scep_server => routeros_system_certificate_scep_server}/import.sh (60%) rename examples/resources/{routeros_certificate_scep_server => routeros_system_certificate_scep_server}/resource.tf (70%) rename routeros/{resource_certificate_scep_server.go => resource_system_certificate_scep_server.go} (100%) rename routeros/{resource_certificate_scep_server_test.go => resource_system_certificate_scep_server_test.go} (100%) create mode 100644 templates/resources/certificate_scep_server.md.tmpl diff --git a/examples/resources/routeros_certificate_scep_server/import.sh b/examples/resources/routeros_system_certificate_scep_server/import.sh similarity index 60% rename from examples/resources/routeros_certificate_scep_server/import.sh rename to examples/resources/routeros_system_certificate_scep_server/import.sh index da6a9547..1b7d278f 100644 --- a/examples/resources/routeros_certificate_scep_server/import.sh +++ b/examples/resources/routeros_system_certificate_scep_server/import.sh @@ -1,3 +1,3 @@ # The ID can be found via API or the terminal # The command for the terminal is -> /certificate/scep-server/print show-ids -terraform import routeros_certificate_scep_server.example_scep_server "*1" +terraform import routeros_system_certificate_scep_server.example_scep_server "*1" diff --git a/examples/resources/routeros_certificate_scep_server/resource.tf b/examples/resources/routeros_system_certificate_scep_server/resource.tf similarity index 70% rename from examples/resources/routeros_certificate_scep_server/resource.tf rename to examples/resources/routeros_system_certificate_scep_server/resource.tf index 8b56adc5..42cd4828 100644 --- a/examples/resources/routeros_certificate_scep_server/resource.tf +++ b/examples/resources/routeros_system_certificate_scep_server/resource.tf @@ -7,7 +7,8 @@ resource "routeros_system_certificate" "example_root_ca" { } } -resource "routeros_certificate_scep_server" "example_scep_server" { +# You can also use the alias "routeros_certificate_scep_server" +resource "routeros_system_certificate_scep_server" "example_scep_server" { ca_cert = routeros_system_certificate.example_root_ca.name path = "/scep/example_scep_server" days_valid = 30 diff --git a/routeros/provider.go b/routeros/provider.go index 8d41a672..35d5c8a4 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -171,21 +171,22 @@ func Provider() *schema.Provider { "routeros_wireguard_peer": ResourceInterfaceWireguardPeer(), // System Objects - "routeros_ip_cloud": ResourceIpCloud(), - "routeros_ip_cloud_advanced": ResourceIpCloudAdvanced(), - "routeros_system_certificate": ResourceSystemCertificate(), - "routeros_certificate_scep_server": ResourceCertificateScepServer(), - "routeros_system_clock": ResourceSystemClock(), - "routeros_system_identity": ResourceSystemIdentity(), - "routeros_system_logging": ResourceSystemLogging(), - "routeros_system_ntp_client": ResourceSystemNtpClient(), - "routeros_system_ntp_server": ResourceSystemNtpServer(), - "routeros_system_scheduler": ResourceSystemScheduler(), - "routeros_system_script": ResourceSystemScript(), - "routeros_system_user": ResourceUser(), - "routeros_system_user_aaa": ResourceUserAaa(), - "routeros_system_user_group": ResourceUserGroup(), - "routeros_system_user_settings": ResourceSystemUserSettings(), + "routeros_ip_cloud": ResourceIpCloud(), + "routeros_ip_cloud_advanced": ResourceIpCloudAdvanced(), + "routeros_system_certificate": ResourceSystemCertificate(), + "routeros_system_certificate_scep_server": ResourceCertificateScepServer(), + "routeros_certificate_scep_server": ResourceCertificateScepServer(), + "routeros_system_clock": ResourceSystemClock(), + "routeros_system_identity": ResourceSystemIdentity(), + "routeros_system_logging": ResourceSystemLogging(), + "routeros_system_ntp_client": ResourceSystemNtpClient(), + "routeros_system_ntp_server": ResourceSystemNtpServer(), + "routeros_system_scheduler": ResourceSystemScheduler(), + "routeros_system_script": ResourceSystemScript(), + "routeros_system_user": ResourceUser(), + "routeros_system_user_aaa": ResourceUserAaa(), + "routeros_system_user_group": ResourceUserGroup(), + "routeros_system_user_settings": ResourceSystemUserSettings(), // Aliases for system objects to retain compatibility between original and fork "routeros_identity": ResourceSystemIdentity(), diff --git a/routeros/resource_certificate_scep_server.go b/routeros/resource_system_certificate_scep_server.go similarity index 100% rename from routeros/resource_certificate_scep_server.go rename to routeros/resource_system_certificate_scep_server.go diff --git a/routeros/resource_certificate_scep_server_test.go b/routeros/resource_system_certificate_scep_server_test.go similarity index 100% rename from routeros/resource_certificate_scep_server_test.go rename to routeros/resource_system_certificate_scep_server_test.go diff --git a/templates/resources/certificate_scep_server.md.tmpl b/templates/resources/certificate_scep_server.md.tmpl new file mode 100644 index 00000000..f93438a2 --- /dev/null +++ b/templates/resources/certificate_scep_server.md.tmpl @@ -0,0 +1,5 @@ +# {{.Name}} ({{.Type}}) +--- + +#### This is an alias for backwards compatibility between plugin versions. +Please see documentation for [routeros_system_certificate_scep_server](system_certificate_scep_server.md) From d18eab3c5116ea3e011425e9618810a1516bf3ec Mon Sep 17 00:00:00 2001 From: Vaerh Date: Wed, 29 May 2024 08:38:44 +0300 Subject: [PATCH 2/4] chore: Change issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 3 +++ .github/ISSUE_TEMPLATE/feature_request.md | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 88ac9dfe..f3b69cf7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -16,6 +16,9 @@ Steps to reproduce the behavior and the problem section from the TF file, withou **Expected behavior** A clear and concise description of what you expected to happen. +**Debug Information** +If needed, be ready to publish debug output of the provider (green lines after executing `TF_LOG=debug ROS_LOG_COLOR=1 terraform `). + **Stack Trace** If applicable, add the stack trace the crash produced. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 59094e26..a2efb13a 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -13,5 +13,8 @@ A clear and concise description of what the problem is. Ex. I'm always frustrate **Describe the solution you'd like** A clear and concise description of what you want to happen. +**Documentation** +If there is [documentation](https://help.mikrotik.com/docs/display/ROS/RouterOS) describing the new resource, add it. + **Additional context** -Add any other context or screenshots about the feature request here. +Add any other context or screenshots about the feature request here. \ No newline at end of file From 7c4d84341df031b624c393ef59b23c824ab4ca8f Mon Sep 17 00:00:00 2001 From: Vaerh Date: Wed, 29 May 2024 10:34:40 +0300 Subject: [PATCH 3/4] feat(logging-action): Support for logging actions setup Closes #477 --- routeros/provider.go | 1 + routeros/provider_schema_helpers.go | 2 +- routeros/resource_system_logging_actions.go | 156 ++++++++++++++++++ .../resource_system_logging_actions_test.go | 54 ++++++ 4 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 routeros/resource_system_logging_actions.go create mode 100644 routeros/resource_system_logging_actions_test.go diff --git a/routeros/provider.go b/routeros/provider.go index 35d5c8a4..d22a1d16 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -179,6 +179,7 @@ func Provider() *schema.Provider { "routeros_system_clock": ResourceSystemClock(), "routeros_system_identity": ResourceSystemIdentity(), "routeros_system_logging": ResourceSystemLogging(), + "routeros_system_logging_action": ResourceSystemLoggingAction(), "routeros_system_ntp_client": ResourceSystemNtpClient(), "routeros_system_ntp_server": ResourceSystemNtpServer(), "routeros_system_scheduler": ResourceSystemScheduler(), diff --git a/routeros/provider_schema_helpers.go b/routeros/provider_schema_helpers.go index 8521c907..12db2817 100644 --- a/routeros/provider_schema_helpers.go +++ b/routeros/provider_schema_helpers.go @@ -106,7 +106,7 @@ func PropDropByValue(s ...string) *schema.Schema { } } -// PropTransformSet +// PropTransformSet List of []string{"TF", "MT"} string pairs. func PropTransformSet(s ...string) *schema.Schema { return &schema.Schema{ Type: schema.TypeString, diff --git a/routeros/resource_system_logging_actions.go b/routeros/resource_system_logging_actions.go new file mode 100644 index 00000000..93477933 --- /dev/null +++ b/routeros/resource_system_logging_actions.go @@ -0,0 +1,156 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +/* + { + ".id": "*3", + "bsd-syslog": "false", + "default": "true", + "name": "remote", + "remote": "0.0.0.0", + "remote-port": "514", + "src-address": "0.0.0.0", + "syslog-facility": "daemon", + "syslog-severity": "auto", + "syslog-time-format": "bsd-syslog", + "target": "remote" + } +*/ + +// ResourceSystemLoggingActions https://help.mikrotik.com/docs/display/ROS/Log#Log-Actions +func ResourceSystemLoggingAction() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/system/logging/action"), + MetaId: PropId(Id), + + "bsd_syslog": { + Type: schema.TypeBool, + Optional: true, + Description: `Whether to use bsd-syslog as defined in RFC 3164.`, + }, + "default": { + Type: schema.TypeBool, + Computed: true, + Description: "This is a default action.", + }, + "disk_file_count": { + Type: schema.TypeInt, + Optional: true, + Description: "Specifies number of files used to store log messages, applicable only if `action=disk`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "disk_file_name": { + Type: schema.TypeString, + Optional: true, + Description: "Name of the file used to store log messages, applicable only if `action=disk`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "disk_lines_per_file": { + Type: schema.TypeInt, + Optional: true, + Description: "Specifies maximum size of file in lines, applicable only if `action=disk`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "disk_stop_on_full": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to stop to save log messages to disk after the specified disk-lines-per-file " + + "and disk-file-count number is reached, applicable only if `action=disk`.", + }, + "email_start_tls": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to use tls when sending email, applicable only if `action=email`.", + }, + "email_to": { + Type: schema.TypeString, + Optional: true, + Description: "Email address where logs are sent, applicable only if `action=email`.", + }, + "memory_lines": { + Type: schema.TypeInt, + Optional: true, + Description: "Number of records in local memory buffer, applicable only if `action=memory`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "memory_stop_on_full": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to stop to save log messages in local buffer after the specified memory-lines " + + "number is reached.", + }, + KeyName: PropName("Name of an action."), + "remember": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to keep log messages, which have not yet been displayed in console, applicable " + + "if `action=echo`.", + }, + "remote": { + Type: schema.TypeString, + Optional: true, + Description: "Remote logging server's IP/IPv6 address, applicable if `action=remote`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "remote_port": { + Type: schema.TypeInt, + Optional: true, + Description: "Remote logging server's UDP port, applicable if `action=remote`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "src_address": { + Type: schema.TypeString, + Optional: true, + Description: "Source address used when sending packets to remote server, applicable if `action=remote`.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "syslog_facility": { + Type: schema.TypeString, + Optional: true, + Description: "SYSLOG facility, applicable if `action=remote`.", + ValidateFunc: validation.StringInSlice([]string{"auth", "authpriv", "cron", "daemon", "ftp", + "kern", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "lpr", + "mail", "news", "ntp", "syslog", "user", "uucp"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "syslog_severity": { + Type: schema.TypeString, + Optional: true, + Description: "Severity level indicator defined in RFC 3164, applicable if `action=remote`.", + ValidateFunc: validation.StringInSlice([]string{"alert", "auto", "critical", "debug", "emergency", + "error", "info", "notice", "warning"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "syslog_time_format": { + Type: schema.TypeString, + Optional: true, + Description: "SYSLOG time format (`bsd-syslog` or `iso8601`).", + ValidateFunc: validation.StringInSlice([]string{"bsd-syslog", "iso8601"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "target": { + Type: schema.TypeString, + Required: true, + Description: "Storage facility or target of log messages.", + ValidateFunc: validation.StringInSlice([]string{"disk", "echo", "email", "memory", "remote"}, 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, + } +} diff --git a/routeros/resource_system_logging_actions_test.go b/routeros/resource_system_logging_actions_test.go new file mode 100644 index 00000000..fa89b1b2 --- /dev/null +++ b/routeros/resource_system_logging_actions_test.go @@ -0,0 +1,54 @@ +package routeros + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +const testSystemLoggingAction = "routeros_system_logging_action.action" + +func TestAccSystemLoggingActionTest_basic(t *testing.T) { + for _, name := range testNames { + t.Run(name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testSetTransportEnv(t, name) + }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSystemLoggingActionConfig(), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testSystemLoggingAction), + resource.TestCheckResourceAttr(testSystemLoggingAction, "name", "action1"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "default", "false"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "target", "remote"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "remote", "192.168.1.1"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "bsd_syslog", "true"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "syslog_facility", "user"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "syslog_severity", "notice"), + resource.TestCheckResourceAttr(testSystemLoggingAction, "syslog_time_format", "iso8601"), + ), + }, + }, + }) + + }) + } +} + +func testAccSystemLoggingActionConfig() string { + return providerConfig + ` +resource "routeros_system_logging_action" "action" { + name = "action1" + target = "remote" + remote = "192.168.1.1" + bsd_syslog = true + syslog_facility = "user" + syslog_severity = "notice" + syslog_time_format = "iso8601" +} +` +} From 808d35ab7b8d1aa36316a6cab8373569cb6bf53a Mon Sep 17 00:00:00 2001 From: Vaerh Date: Wed, 29 May 2024 10:57:49 +0300 Subject: [PATCH 4/4] test(firewall-raw): Fix resource name --- routeros/resource_ip_firewall_raw_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routeros/resource_ip_firewall_raw_test.go b/routeros/resource_ip_firewall_raw_test.go index 471c246a..b4448230 100644 --- a/routeros/resource_ip_firewall_raw_test.go +++ b/routeros/resource_ip_firewall_raw_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -const testIPFirewallRawAddress = "routeros_firewall_raw.rule" +const testIPFirewallRawAddress = "routeros_ip_firewall_raw.rule" func TestAccIPFirewallRawTest_basic(t *testing.T) { for _, name := range testNames { @@ -17,7 +17,7 @@ func TestAccIPFirewallRawTest_basic(t *testing.T) { testSetTransportEnv(t, name) }, ProviderFactories: testAccProviderFactories, - CheckDestroy: testCheckResourceDestroy("/ip/firewall/raw", "routeros_firewall_raw"), + CheckDestroy: testCheckResourceDestroy("/ip/firewall/raw", "routeros_ip_firewall_raw"), Steps: []resource.TestStep{ { Config: testAccIPFirewallRawConfig(), @@ -35,7 +35,7 @@ func TestAccIPFirewallRawTest_basic(t *testing.T) { func testAccIPFirewallRawConfig() string { return providerConfig + ` -resource "routeros_firewall_raw" "rule" { +resource "routeros_ip_firewall_raw" "rule" { action = "accept" chain = "prerouting" src_address = "10.0.0.1"