Skip to content

Commit

Permalink
r/snmp: add engine_id argument
Browse files Browse the repository at this point in the history
Fixes parts of #339
  • Loading branch information
jeremmfr committed Feb 15, 2022
1 parent 06107ee commit 363291c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

ENHANCEMENTS:

* resource/`junos_snmp`: add `engine_id` argument (Fixes parts of #339)

BUG FIXES:

## 1.24.1 (February 11, 2022)
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/snmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ The following arguments are supported:
Contact information for administrator.
- **description** (Optional, String)
System description.
- **engine_id** (Optional, String)
SNMPv3 engine ID.
Need to be `use-default-ip-address`, `use-mac-address` or `local ...`
- **filter_duplicates** (Optional, Boolean)
Filter requests with duplicate source address/port and request ID.
- **filter_interfaces** (Optional, Set of String)
Expand Down
18 changes: 18 additions & 0 deletions junos/resource_snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package junos
import (
"context"
"fmt"
"regexp"
"strconv"
"strings"

Expand All @@ -20,6 +21,7 @@ type snmpOptions struct {
routingInstanceAccess bool
contact string
description string
engineID string
location string
filterInterfaces []string
interFace []string
Expand Down Expand Up @@ -58,6 +60,13 @@ func resourceSnmp() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"engine_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(
`^(use-default-ip-address|use-mac-address|local .+)$`),
"must have 'use-default-ip-address', 'use-mac-address' or 'local ...'"),
},
"filter_duplicates": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -318,6 +327,9 @@ func setSnmp(d *schema.ResourceData, m interface{}, jnprSess *NetconfObject) err
if v := d.Get("description").(string); v != "" {
configSet = append(configSet, setPrefix+"description \""+v+"\"")
}
if v := d.Get("engine_id").(string); v != "" {
configSet = append(configSet, setPrefix+"engine-id "+v)
}
if d.Get("filter_duplicates").(bool) {
configSet = append(configSet, setPrefix+"filter-duplicates")
}
Expand Down Expand Up @@ -378,6 +390,7 @@ func delSnmp(m interface{}, jnprSess *NetconfObject) error {
"arp",
"contact",
"description",
"engine-id",
"filter-duplicates",
"filter-interfaces",
"health-monitor",
Expand Down Expand Up @@ -424,6 +437,8 @@ func readSnmp(m interface{}, jnprSess *NetconfObject) (snmpOptions, error) {
confRead.contact = strings.Trim(strings.TrimPrefix(itemTrim, "contact "), "\"")
case strings.HasPrefix(itemTrim, "description "):
confRead.description = strings.Trim(strings.TrimPrefix(itemTrim, "description "), "\"")
case strings.HasPrefix(itemTrim, "engine-id "):
confRead.engineID = strings.TrimPrefix(itemTrim, "engine-id ")
case itemTrim == "filter-duplicates":
confRead.filterDuplicates = true
case strings.HasPrefix(itemTrim, "filter-interfaces interfaces "):
Expand Down Expand Up @@ -523,6 +538,9 @@ func fillSnmp(d *schema.ResourceData, snmpOptions snmpOptions) {
if tfErr := d.Set("description", snmpOptions.description); tfErr != nil {
panic(tfErr)
}
if tfErr := d.Set("engine_id", snmpOptions.engineID); tfErr != nil {
panic(tfErr)
}
if tfErr := d.Set("filter_duplicates", snmpOptions.filterDuplicates); tfErr != nil {
panic(tfErr)
}
Expand Down
2 changes: 2 additions & 0 deletions junos/resource_snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ resource "junos_snmp" "testacc_snmp" {
arp = true
contact = "[email protected]"
description = "snmp description"
engine_id = "use-mac-address"
filter_duplicates = true
filter_interfaces = ["(ge|xe|ae).*\\.0", "fxp0"]
filter_internal_interfaces = true
Expand Down Expand Up @@ -65,6 +66,7 @@ resource "junos_snmp" "testacc_snmp" {
clean_on_destroy = true
arp = true
arp_host_name_resolution = true
engine_id = "local \"test#123\""
health_monitor {}
routing_instance_access = true
}
Expand Down

0 comments on commit 363291c

Please sign in to comment.