diff --git a/CHANGELOG.md b/CHANGELOG.md index b3749010..ccadd94a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ENHANCEMENTS: +* resource/`junos_snmp`: add `engine_id` argument (Fixes parts of #339) + BUG FIXES: ## 1.24.1 (February 11, 2022) diff --git a/docs/resources/snmp.md b/docs/resources/snmp.md index 3e24a62e..8b0d9dde 100644 --- a/docs/resources/snmp.md +++ b/docs/resources/snmp.md @@ -36,6 +36,8 @@ The following arguments are supported: Contact information for administrator. - **description** (Optional, String) System description. +- **engine_id** (Optional, String) + SNMPv3 engine ID. - **filter_duplicates** (Optional, Boolean) Filter requests with duplicate source address/port and request ID. - **filter_interfaces** (Optional, Set of String) diff --git a/junos/resource_snmp.go b/junos/resource_snmp.go index 2025c3ca..47a8c9bf 100644 --- a/junos/resource_snmp.go +++ b/junos/resource_snmp.go @@ -3,6 +3,7 @@ package junos import ( "context" "fmt" + "regexp" "strconv" "strings" @@ -20,6 +21,7 @@ type snmpOptions struct { routingInstanceAccess bool contact string description string + engineID string location string filterInterfaces []string interFace []string @@ -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, @@ -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") } @@ -378,6 +390,7 @@ func delSnmp(m interface{}, jnprSess *NetconfObject) error { "arp", "contact", "description", + "engine-id", "filter-duplicates", "filter-interfaces", "health-monitor", @@ -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 "): @@ -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) } diff --git a/junos/resource_snmp_test.go b/junos/resource_snmp_test.go index 04597cbc..0bb3b38b 100644 --- a/junos/resource_snmp_test.go +++ b/junos/resource_snmp_test.go @@ -32,6 +32,7 @@ resource "junos_snmp" "testacc_snmp" { arp = true contact = "contact@example.com" description = "snmp description" + engine_id = "use-mac-address" filter_duplicates = true filter_interfaces = ["(ge|xe|ae).*\\.0", "fxp0"] filter_internal_interfaces = true @@ -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 }