diff --git a/junos/func_resource_bgp.go b/junos/func_resource_bgp.go index a6b01b09..01cef23d 100644 --- a/junos/func_resource_bgp.go +++ b/junos/func_resource_bgp.go @@ -407,49 +407,51 @@ func setBgpOptsBfd(setPrefix string, bfdLivenessDetection []interface{}, setPrefixBfd := setPrefix + "bfd-liveness-detection " for _, v := range bfdLivenessDetection { - m := v.(map[string]interface{}) - if m["authentication_key_chain"].(string) != "" { - configSet = append(configSet, setPrefixBfd+"authentication key-chain "+m["authentication_key_chain"].(string)+"\n") - } - if m["authentication_algorithm"].(string) != "" { - configSet = append(configSet, setPrefixBfd+"authentication algorithm "+m["authentication_algorithm"].(string)+"\n") - } - if m["authentication_loose_check"].(bool) { - configSet = append(configSet, setPrefixBfd+"authentication loose-check\n") - } - if m["detection_time_threshold"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"detection-time threshold "+ - strconv.Itoa(m["detection_time_threshold"].(int))+"\n") - } - if m["transmit_interval_threshold"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"transmit-interval threshold "+ - strconv.Itoa(m["transmit_interval_threshold"].(int))+"\n") - } - if m["transmit_interval_minimum_interval"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"transmit-interval minimum-interval "+ - strconv.Itoa(m["transmit_interval_minimum_interval"].(int))+"\n") - } - if m["holddown_interval"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"holddown-interval "+ - strconv.Itoa(m["holddown_interval"].(int))+"\n") - } - if m["minimum_interval"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"minimum-interval "+ - strconv.Itoa(m["minimum_interval"].(int))+"\n") - } - if m["minimum_receive_interval"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"minimum-receive-interval "+ - strconv.Itoa(m["minimum_receive_interval"].(int))+"\n") - } - if m["multiplier"].(int) != 0 { - configSet = append(configSet, setPrefixBfd+"multiplier "+ - strconv.Itoa(m["multiplier"].(int))+"\n") - } - if m["session_mode"].(string) != "" { - configSet = append(configSet, setPrefixBfd+"session-mode "+m["session_mode"].(string)+"\n") - } - if m["version"].(string) != "" { - configSet = append(configSet, setPrefixBfd+"version "+m["version"].(string)+"\n") + if v != nil { + m := v.(map[string]interface{}) + if m["authentication_key_chain"].(string) != "" { + configSet = append(configSet, setPrefixBfd+"authentication key-chain "+m["authentication_key_chain"].(string)+"\n") + } + if m["authentication_algorithm"].(string) != "" { + configSet = append(configSet, setPrefixBfd+"authentication algorithm "+m["authentication_algorithm"].(string)+"\n") + } + if m["authentication_loose_check"].(bool) { + configSet = append(configSet, setPrefixBfd+"authentication loose-check\n") + } + if m["detection_time_threshold"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"detection-time threshold "+ + strconv.Itoa(m["detection_time_threshold"].(int))+"\n") + } + if m["transmit_interval_threshold"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"transmit-interval threshold "+ + strconv.Itoa(m["transmit_interval_threshold"].(int))+"\n") + } + if m["transmit_interval_minimum_interval"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"transmit-interval minimum-interval "+ + strconv.Itoa(m["transmit_interval_minimum_interval"].(int))+"\n") + } + if m["holddown_interval"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"holddown-interval "+ + strconv.Itoa(m["holddown_interval"].(int))+"\n") + } + if m["minimum_interval"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"minimum-interval "+ + strconv.Itoa(m["minimum_interval"].(int))+"\n") + } + if m["minimum_receive_interval"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"minimum-receive-interval "+ + strconv.Itoa(m["minimum_receive_interval"].(int))+"\n") + } + if m["multiplier"].(int) != 0 { + configSet = append(configSet, setPrefixBfd+"multiplier "+ + strconv.Itoa(m["multiplier"].(int))+"\n") + } + if m["session_mode"].(string) != "" { + configSet = append(configSet, setPrefixBfd+"session-mode "+m["session_mode"].(string)+"\n") + } + if m["version"].(string) != "" { + configSet = append(configSet, setPrefixBfd+"version "+m["version"].(string)+"\n") + } } } if len(configSet) > 0 { @@ -710,17 +712,19 @@ func setBgpOptsGrafefulRestart(setPrefix string, gracefulRestarts []interface{}, configSet := make([]string, 0) for _, v := range gracefulRestarts { - m := v.(map[string]interface{}) - if m["disable"].(bool) { - configSet = append(configSet, setPrefix+"graceful-restart disable\n") - } - if m["restart_time"].(int) != 0 { - configSet = append(configSet, setPrefix+"graceful-restart restart-time "+ - strconv.Itoa(m["restart_time"].(int))+"\n") - } - if m["stale_route_time"].(int) != 0 { - configSet = append(configSet, setPrefix+"graceful-restart stale-routes-time "+ - strconv.Itoa(m["stale_route_time"].(int))+"\n") + if v != nil { + m := v.(map[string]interface{}) + if m["disable"].(bool) { + configSet = append(configSet, setPrefix+"graceful-restart disable\n") + } + if m["restart_time"].(int) != 0 { + configSet = append(configSet, setPrefix+"graceful-restart restart-time "+ + strconv.Itoa(m["restart_time"].(int))+"\n") + } + if m["stale_route_time"].(int) != 0 { + configSet = append(configSet, setPrefix+"graceful-restart stale-routes-time "+ + strconv.Itoa(m["stale_route_time"].(int))+"\n") + } } } if len(configSet) > 0 { diff --git a/junos/resource_firewall_policer.go b/junos/resource_firewall_policer.go index 50a2cd9b..db6c74a4 100644 --- a/junos/resource_firewall_policer.go +++ b/junos/resource_firewall_policer.go @@ -267,22 +267,24 @@ func setFirewallPolicer(d *schema.ResourceData, m interface{}, jnprSess *Netconf " if-exceeding burst-size-limit "+ifExceedingMap["burst_size_limit"].(string)+"\n") } for _, then := range d.Get("then").([]interface{}) { - thenMap := then.(map[string]interface{}) - if thenMap["discard"].(bool) { - configSet = append(configSet, setPrefix+ - " then discard\n") - } - if thenMap["forwarding_class"].(string) != "" { - configSet = append(configSet, setPrefix+ - " then forwarding-class "+thenMap["forwarding_class"].(string)+"\n") - } - if thenMap["loss_priority"].(string) != "" { - configSet = append(configSet, setPrefix+ - " then loss-priority "+thenMap["loss_priority"].(string)+"\n") - } - if thenMap["out_of_profile"].(bool) { - configSet = append(configSet, setPrefix+ - " then out-of-profile\n") + if then != nil { + thenMap := then.(map[string]interface{}) + if thenMap["discard"].(bool) { + configSet = append(configSet, setPrefix+ + " then discard\n") + } + if thenMap["forwarding_class"].(string) != "" { + configSet = append(configSet, setPrefix+ + " then forwarding-class "+thenMap["forwarding_class"].(string)+"\n") + } + if thenMap["loss_priority"].(string) != "" { + configSet = append(configSet, setPrefix+ + " then loss-priority "+thenMap["loss_priority"].(string)+"\n") + } + if thenMap["out_of_profile"].(bool) { + configSet = append(configSet, setPrefix+ + " then out-of-profile\n") + } } } diff --git a/junos/resource_policyoptions_policy_statement.go b/junos/resource_policyoptions_policy_statement.go index 1107b10d..32ec2fa7 100644 --- a/junos/resource_policyoptions_policy_statement.go +++ b/junos/resource_policyoptions_policy_statement.go @@ -1014,36 +1014,44 @@ func setPolicyStatement(d *schema.ResourceData, m interface{}, jnprSess *Netconf configSet := make([]string, 0) setPrefix := "set policy-options policy-statement " + d.Get("name").(string) - mapRootOpts := make(map[string]interface{}) - for _, key := range []string{"from", "then"} { - mapRootOpts[key] = d.Get(key) - } for _, from := range d.Get("from").([]interface{}) { - configSetFrom := setPolicyStatementOptsFrom(setPrefix, from.(map[string]interface{})) - configSet = append(configSet, configSetFrom...) + if from != nil { + configSetFrom := setPolicyStatementOptsFrom(setPrefix, from.(map[string]interface{})) + configSet = append(configSet, configSetFrom...) + } } for _, then := range d.Get("then").([]interface{}) { - configSetThen := setPolicyStatementOptsThen(setPrefix, then.(map[string]interface{})) - configSet = append(configSet, configSetThen...) + if then != nil { + configSetThen := setPolicyStatementOptsThen(setPrefix, then.(map[string]interface{})) + configSet = append(configSet, configSetThen...) + } } for _, to := range d.Get("to").([]interface{}) { - configSetTo := setPolicyStatementOptsTo(setPrefix, to.(map[string]interface{})) - configSet = append(configSet, configSetTo...) + if to != nil { + configSetTo := setPolicyStatementOptsTo(setPrefix, to.(map[string]interface{})) + configSet = append(configSet, configSetTo...) + } } for _, term := range d.Get("term").([]interface{}) { termMap := term.(map[string]interface{}) setPrefixTerm := setPrefix + " term " + termMap["name"].(string) for _, from := range termMap["from"].([]interface{}) { - configSetFrom := setPolicyStatementOptsFrom(setPrefixTerm, from.(map[string]interface{})) - configSet = append(configSet, configSetFrom...) + if from != nil { + configSetFrom := setPolicyStatementOptsFrom(setPrefixTerm, from.(map[string]interface{})) + configSet = append(configSet, configSetFrom...) + } } for _, then := range termMap["then"].([]interface{}) { - configSetThen := setPolicyStatementOptsThen(setPrefixTerm, then.(map[string]interface{})) - configSet = append(configSet, configSetThen...) + if then != nil { + configSetThen := setPolicyStatementOptsThen(setPrefixTerm, then.(map[string]interface{})) + configSet = append(configSet, configSetThen...) + } } for _, to := range termMap["to"].([]interface{}) { - configSetTo := setPolicyStatementOptsTo(setPrefixTerm, to.(map[string]interface{})) - configSet = append(configSet, configSetTo...) + if to != nil { + configSetTo := setPolicyStatementOptsTo(setPrefixTerm, to.(map[string]interface{})) + configSet = append(configSet, configSetTo...) + } } } diff --git a/junos/resource_security_ike_gateway.go b/junos/resource_security_ike_gateway.go index fb31c463..ebc751a5 100644 --- a/junos/resource_security_ike_gateway.go +++ b/junos/resource_security_ike_gateway.go @@ -332,14 +332,16 @@ func setIkeGateway(d *schema.ResourceData, m interface{}, jnprSess *NetconfObjec if len(d.Get("dead_peer_detection").([]interface{})) != 0 { configSet = append(configSet, setPrefix+" dead-peer-detection\n") for _, v := range d.Get("dead_peer_detection").([]interface{}) { - deadPeerOptions := v.(map[string]interface{}) - if deadPeerOptions["interval"].(int) != 0 { - configSet = append(configSet, setPrefix+" dead-peer-detection interval "+ - strconv.Itoa(deadPeerOptions["interval"].(int))+"\n") - } - if deadPeerOptions["threshold"].(int) != 0 { - configSet = append(configSet, setPrefix+" dead-peer-detection threshold "+ - strconv.Itoa(deadPeerOptions["threshold"].(int))+"\n") + if v != nil { + deadPeerOptions := v.(map[string]interface{}) + if deadPeerOptions["interval"].(int) != 0 { + configSet = append(configSet, setPrefix+" dead-peer-detection interval "+ + strconv.Itoa(deadPeerOptions["interval"].(int))+"\n") + } + if deadPeerOptions["threshold"].(int) != 0 { + configSet = append(configSet, setPrefix+" dead-peer-detection threshold "+ + strconv.Itoa(deadPeerOptions["threshold"].(int))+"\n") + } } } } diff --git a/junos/resource_security_ipsec_vpn.go b/junos/resource_security_ipsec_vpn.go index 37e874d3..5dd85751 100644 --- a/junos/resource_security_ipsec_vpn.go +++ b/junos/resource_security_ipsec_vpn.go @@ -199,10 +199,12 @@ func resourceIpsecVpnRead(d *schema.ResourceData, m interface{}) error { // copy state vpn_monitor.0.source_interface_auto to struct if len(ipsecVpnOptions.vpnMonitor) > 0 { for _, v := range d.Get("vpn_monitor").([]interface{}) { - stateMonitor := v.(map[string]interface{}) - vpnMonitor := ipsecVpnOptions.vpnMonitor[0] - vpnMonitor["source_interface_auto"] = stateMonitor["source_interface_auto"].(bool) - ipsecVpnOptions.vpnMonitor = []map[string]interface{}{vpnMonitor} + if v != nil { + stateMonitor := v.(map[string]interface{}) + vpnMonitor := ipsecVpnOptions.vpnMonitor[0] + vpnMonitor["source_interface_auto"] = stateMonitor["source_interface_auto"].(bool) + ipsecVpnOptions.vpnMonitor = []map[string]interface{}{vpnMonitor} + } } } mutex.Unlock()