Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vaerh/2905 #478

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command>`).

**Stack Trace**
If applicable, add the stack trace the crash produced.

Expand Down
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,23 @@ 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_logging_action": ResourceSystemLoggingAction(),
"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(),
Expand Down
2 changes: 1 addition & 1 deletion routeros/provider_schema_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions routeros/resource_ip_firewall_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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"
Expand Down
156 changes: 156 additions & 0 deletions routeros/resource_system_logging_actions.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
54 changes: 54 additions & 0 deletions routeros/resource_system_logging_actions_test.go
Original file line number Diff line number Diff line change
@@ -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"
}
`
}
5 changes: 5 additions & 0 deletions templates/resources/certificate_scep_server.md.tmpl
Original file line number Diff line number Diff line change
@@ -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)