Skip to content

Commit

Permalink
fix terraform crash with an empty blocks-mode (no one required) (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremmfr authored Jan 3, 2020
1 parent 874f047 commit 09870e6
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 98 deletions.
112 changes: 58 additions & 54 deletions junos/func_resource_bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
34 changes: 18 additions & 16 deletions junos/resource_firewall_policer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand Down
40 changes: 24 additions & 16 deletions junos/resource_policyoptions_policy_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
}
}

Expand Down
18 changes: 10 additions & 8 deletions junos/resource_security_ike_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions junos/resource_security_ipsec_vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 09870e6

Please sign in to comment.