-
Notifications
You must be signed in to change notification settings - Fork 61
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
Implement routeros_system_logging resource #261
Merged
vaerh
merged 4 commits into
terraform-routeros:main
from
jlpedrosa:routeros_system_logging
Sep 21, 2023
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# The ID can be found via API or the terminal | ||
# The command for the terminal is -> :put [/system/logging/print get [print show-ids]] | ||
|
||
terraform import routeros_system_logging.log_snmp_disk "*4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
resource "routeros_system_logging" "log_snmp_disk" { | ||
action = "disk" | ||
topics = ["snmp"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* { | ||
".id": "*4", | ||
"action": "echo", | ||
"default": "true", | ||
"disabled": "false", | ||
"invalid": "false", | ||
"prefix": "", | ||
"topics": "critical" | ||
} */ | ||
|
||
var validTopics = []string{ | ||
"account", " bfd", "caps", "ddns", "dns", "error", "gsm", "info", "iscsi", "l2tp", "manager", "ntp", "packet", | ||
"pppoe", "radvd", "rip", "script", "smb", "sstp", "system", "timer", "vrrp", "web-proxy", "async", "bgp", | ||
"certificate", "debug", "dot1x", "dude", "event", "hotspot", "interface", "isdn", "ldp", "mme", "ospf", "pim", | ||
"pptp", "raw", "route", "sertcp", "snmp", "state", "telephony", "upnp", "warning", "wireless", "backup", "calc", | ||
"critical", "dhcp", "e-mail", "firewall", "igmp-proxy", "ipsec", "kvm", "lte", "mpls", "ovpn", "ppp", "radius", | ||
"read", "rsvp", "simulator", "ssh", "store", "tftp", "ups", "watchdog", "write", | ||
} | ||
|
||
func ResourceSystemLogging() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/system/logging"), | ||
MetaId: PropId(Id), | ||
"action": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "specifies one of the system default actions or user specified action listed in actions menu", | ||
ValidateFunc: validation.StringInSlice([]string{"disk", "echo", "memory", "remote"}, false), | ||
}, | ||
"prefix": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "prefix added at the beginning of log messages", | ||
Default: "", | ||
}, | ||
KeyDisabled: { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
Description: "Whether or not this logging should be disabled", | ||
}, | ||
"invalid": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"topics": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Optional: true, | ||
Description: "prefix added at the beginning of log messages", | ||
}, | ||
} | ||
|
||
return &schema.Resource{ | ||
CreateContext: DefaultCreate(resSchema), | ||
ReadContext: DefaultRead(resSchema), | ||
UpdateContext: DefaultUpdate(resSchema), | ||
DeleteContext: DefaultDelete(resSchema), | ||
|
||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: resSchema, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
const testSystemSimpleLoggingTask = "routeros_system_logging.simple_logging" | ||
|
||
func TestAccSystemLoggingTest_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: testAccSystemLoggingConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckLoggingExists(testSystemSimpleLoggingTask), | ||
resource.TestCheckResourceAttr(testSystemSimpleLoggingTask, "action", "echo"), | ||
resource.TestCheckResourceAttr(testSystemSimpleLoggingTask, "disabled", "false"), | ||
resource.TestCheckResourceAttr(testSystemSimpleLoggingTask, "invalid", "false"), | ||
resource.TestCheckResourceAttr(testSystemSimpleLoggingTask, "prefix", "simple_prefix"), | ||
resource.TestCheckResourceAttr(testSystemSimpleLoggingTask, "topics.0", "snmp"), | ||
resource.TestCheckResourceAttr(testSystemSimpleLoggingTask, "topics.1", "gsm"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccCheckLoggingExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", name) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no id is set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccSystemLoggingConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_system_logging" "simple_logging" { | ||
action = "echo" | ||
prefix = "simple_prefix" | ||
topics = ["snmp", "gsm"] | ||
} | ||
` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you planning to do validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad: I implemented validation but terraform does not support validation for lists :( and I only found out after it was implemented (error message on the sdk), I deleted the function but not the slice.
I've just deleted the slice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I found a way to add the validation.