From 5db0fe1f485106e38c6e31fab6ae1d78b94623c0 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 11 Jun 2024 13:24:24 +0200 Subject: [PATCH 1/2] r/*: providerfwk: adjust code lines in same way for - show config command lines - set/delete prefix definition lines - set/read routing_instance value --- internal/junos/constants.go | 4 +- .../providerfwk/resource_aggregate_route.go | 21 +-- internal/providerfwk/resource_application.go | 5 +- .../providerfwk/resource_application_set.go | 4 +- internal/providerfwk/resource_bgp_group.go | 91 +++++----- internal/providerfwk/resource_bgp_neighbor.go | 102 +++++------- .../providerfwk/resource_bridge_domain.go | 103 +++++------- .../resource_eventoptions_destination.go | 4 +- .../resource_eventoptions_generate_event.go | 4 +- .../resource_eventoptions_policy.go | 15 +- internal/providerfwk/resource_evpn.go | 57 +++---- .../providerfwk/resource_firewall_filter.go | 4 +- .../providerfwk/resource_firewall_policer.go | 6 +- .../resource_forwardingoptions_evpn_vxlan.go | 9 +- .../resource_forwardingoptions_sampling.go | 27 ++- ...rce_forwardingoptions_sampling_instance.go | 47 +++--- ...forwardingoptions_storm_control_profile.go | 6 +- .../providerfwk/resource_generate_route.go | 22 ++- internal/providerfwk/resource_iccp.go | 6 +- internal/providerfwk/resource_iccp_peer.go | 4 +- .../providerfwk/resource_interface_logical.go | 12 +- .../resource_interface_physical.go | 3 +- internal/providerfwk/resource_multichassis.go | 6 +- .../resource_multichassis_protection_peer.go | 5 +- .../resource_oam_gretunnel_interface.go | 5 +- internal/providerfwk/resource_ospf.go | 44 ++--- internal/providerfwk/resource_ospf_area.go | 155 +++++++----------- .../resource_policyoptions_as_path.go | 4 +- .../resource_policyoptions_as_path_group.go | 4 +- .../resource_policyoptions_community.go | 4 +- ...resource_policyoptions_policy_statement.go | 6 +- .../resource_policyoptions_prefix_list.go | 4 +- .../providerfwk/resource_routing_instance.go | 10 +- internal/providerfwk/resource_security.go | 26 ++- .../resource_security_address_book.go | 4 +- .../resource_security_global_policy.go | 4 +- .../resource_security_ike_gateway.go | 6 +- .../resource_security_ike_policy.go | 4 +- .../resource_security_ike_proposal.go | 4 +- .../resource_security_ipsec_policy.go | 4 +- .../resource_security_ipsec_proposal.go | 4 +- .../resource_security_ipsec_vpn.go | 4 +- .../resource_security_nat_destination_pool.go | 1 + .../resource_security_nat_static.go | 4 +- .../resource_security_nat_static_rule.go | 1 + .../providerfwk/resource_security_policy.go | 4 +- ...urce_security_policy_tunnel_pair_policy.go | 4 +- .../providerfwk/resource_security_zone.go | 5 +- .../resource_security_zone_book_address.go | 4 +- ...resource_security_zone_book_address_set.go | 4 +- ...rce_services_flowmonitoring_v9_template.go | 4 +- ...services_flowmonitoring_vipfix_template.go | 4 +- internal/providerfwk/resource_snmp.go | 7 +- .../providerfwk/resource_snmp_clientlist.go | 5 +- .../providerfwk/resource_snmp_community.go | 6 +- .../providerfwk/resource_snmp_v3_community.go | 5 +- .../providerfwk/resource_snmp_v3_usm_user.go | 99 +++++------ .../resource_snmp_v3_vacm_accessgroup.go | 6 +- .../resource_snmp_v3_vacm_securitytogroup.go | 4 +- internal/providerfwk/resource_snmp_view.go | 6 +- internal/providerfwk/resource_static_route.go | 23 +-- .../providerfwk/resource_switch_options.go | 4 +- internal/providerfwk/resource_system.go | 6 +- .../resource_system_radius_server.go | 7 +- .../resource_system_syslog_file.go | 4 +- .../resource_system_syslog_host.go | 4 +- .../resource_system_syslog_user.go | 4 +- .../resource_system_tacplus_server.go | 7 +- .../providerfwk/resource_virtual_chassis.go | 9 +- internal/providerfwk/resource_vlan.go | 6 +- internal/providerfwk/resourcedata_bgp.go | 4 + .../providerfwk/upgradestate_bridge_domain.go | 8 +- internal/providersdk/constants.go | 7 + ...resource_access_address_assignment_pool.go | 4 +- .../resource_forwardingoptions_dhcprelay.go | 6 +- ...ource_forwardingoptions_dhcprelay_group.go | 6 +- ...forwardingoptions_dhcprelay_servergroup.go | 6 +- .../resource_igmp_snooping_vlan.go | 4 +- internal/providersdk/resource_rip_group.go | 4 +- internal/providersdk/resource_rip_neighbor.go | 4 +- ..._system_services_dhcp_localserver_group.go | 6 +- 81 files changed, 499 insertions(+), 670 deletions(-) diff --git a/internal/junos/constants.go b/internal/junos/constants.go index 377cb058..8ac8049a 100644 --- a/internal/junos/constants.go +++ b/internal/junos/constants.go @@ -13,9 +13,7 @@ const ( PipeDisplaySet = " | display set" PipeDisplaySetRelative = PipeDisplaySet + " relative" - RoutingInstancesWS = "routing-instances " // routing-instances word + space - SetRoutingInstances = SetLS + RoutingInstancesWS - DelRoutingInstances = DeleteLS + RoutingInstancesWS + RoutingInstancesWS = "routing-instances " // routing-instances word + space RoutingOptionsWS = "routing-options " RibInet60WS = "rib inet6.0 " diff --git a/internal/providerfwk/resource_aggregate_route.go b/internal/providerfwk/resource_aggregate_route.go index 15f26955..ad898524 100644 --- a/internal/providerfwk/resource_aggregate_route.go +++ b/internal/providerfwk/resource_aggregate_route.go @@ -493,7 +493,7 @@ func (rsc *aggregateRoute) ImportState( func checkAggregateRouteExists( _ context.Context, destination, routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showPrefix := junos.CmdShowConfig switch routingInstance { @@ -508,11 +508,11 @@ func checkAggregateRouteExists( showPrefix += "rib " + routingInstance + ".inet6.0 " } } - showConfig, err := junSess.Command(showPrefix + "aggregate route " + destination + junos.PipeDisplaySet) + showConfig, err := junSess.Command(showPrefix + + "aggregate route " + destination + junos.PipeDisplaySet) if err != nil { return false, err } - if showConfig == junos.EmptyW { return false, nil } @@ -551,6 +551,7 @@ func (rscData *aggregateRouteData) set( } } setPrefix += "aggregate route " + rscData.Destination.ValueString() + " " + configSet := []string{ setPrefix, } @@ -603,9 +604,7 @@ func (rscData *aggregateRouteData) set( func (rscData *aggregateRouteData) read( _ context.Context, destination, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig switch routingInstance { case junos.DefaultW, "": @@ -619,16 +618,17 @@ func (rscData *aggregateRouteData) read( showPrefix += "rib " + routingInstance + ".inet6.0 " } } - showConfig, err := junSess.Command(showPrefix + "aggregate route " + destination + junos.PipeDisplaySetRelative) + showConfig, err := junSess.Command(showPrefix + + "aggregate route " + destination + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { rscData.Destination = types.StringValue(destination) - rscData.RoutingInstance = types.StringValue(routingInstance) - if rscData.RoutingInstance.ValueString() == "" { + if routingInstance == "" { rscData.RoutingInstance = types.StringValue(junos.DefaultW) + } else { + rscData.RoutingInstance = types.StringValue(routingInstance) } rscData.fillID() for _, item := range strings.Split(showConfig, "\n") { @@ -700,6 +700,7 @@ func (rscData *aggregateRouteData) del( delPrefix += "rib " + routingInstance + ".inet6.0 " } } + configSet := []string{ delPrefix + "aggregate route " + rscData.Destination.ValueString(), } diff --git a/internal/providerfwk/resource_application.go b/internal/providerfwk/resource_application.go index dc8cbf61..de049e4e 100644 --- a/internal/providerfwk/resource_application.go +++ b/internal/providerfwk/resource_application.go @@ -692,6 +692,7 @@ func (block *applicationBlockTerm) configSet( error, // error ) { setPrefix += "term " + block.Name.ValueString() + " " + configSet := []string{ setPrefix, setPrefix + "protocol " + block.Protocol.ValueString(), @@ -742,9 +743,7 @@ func (block *applicationBlockTerm) configSet( func (rscData *applicationData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "applications application " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_application_set.go b/internal/providerfwk/resource_application_set.go index 84e20346..6dba3b5f 100644 --- a/internal/providerfwk/resource_application_set.go +++ b/internal/providerfwk/resource_application_set.go @@ -358,9 +358,7 @@ func (rscData *applicationSetData) set( func (rscData *applicationSetData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "applications application-set " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_bgp_group.go b/internal/providerfwk/resource_bgp_group.go index ee7f76a9..01d2738d 100644 --- a/internal/providerfwk/resource_bgp_group.go +++ b/internal/providerfwk/resource_bgp_group.go @@ -888,7 +888,7 @@ func (rsc *bgpGroup) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("advertise_peer_as"), tfdiag.ConflictConfigErrSummary, - "advertise_peer_as and no_advertise_peer_as can't be true in same time ", + "advertise_peer_as and no_advertise_peer_as can't be true in same time", ) } if !config.KeepAll.IsNull() && !config.KeepAll.IsUnknown() && @@ -896,7 +896,7 @@ func (rsc *bgpGroup) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("keep_all"), tfdiag.ConflictConfigErrSummary, - "keep_all and keep_none can't be true in same time ", + "keep_all and keep_none can't be true in same time", ) } if !config.AuthenticationKey.IsNull() && !config.AuthenticationKey.IsUnknown() { @@ -1084,7 +1084,7 @@ func (rsc *bgpGroup) ValidateConfig( path.Root("family_evpn").AtListIndex(i).AtName("accepted_prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in accepted_prefix_limit block in family_evpn block ", + " in accepted_prefix_limit block in family_evpn block", ) } } @@ -1104,7 +1104,7 @@ func (rsc *bgpGroup) ValidateConfig( path.Root("family_evpn").AtListIndex(i).AtName("prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in prefix_limit block family_evpn block ", + " in prefix_limit block family_evpn block", ) } } @@ -1147,7 +1147,7 @@ func (rsc *bgpGroup) ValidateConfig( path.Root("family_inet").AtListIndex(i).AtName("accepted_prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in accepted_prefix_limit block in family_inet block ", + " in accepted_prefix_limit block in family_inet block", ) } } @@ -1167,7 +1167,7 @@ func (rsc *bgpGroup) ValidateConfig( path.Root("family_inet").AtListIndex(i).AtName("prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in prefix_limit block family_inet block ", + " in prefix_limit block family_inet block", ) } } @@ -1210,7 +1210,7 @@ func (rsc *bgpGroup) ValidateConfig( path.Root("family_inet6").AtListIndex(i).AtName("accepted_prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in accepted_prefix_limit block in family_inet6 block ", + " in accepted_prefix_limit block in family_inet6 block", ) } } @@ -1230,7 +1230,7 @@ func (rsc *bgpGroup) ValidateConfig( path.Root("family_inet6").AtListIndex(i).AtName("prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in prefix_limit block family_inet6 block ", + " in prefix_limit block family_inet6 block", ) } } @@ -1537,22 +1537,16 @@ func checkBgpGroupExists( routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { - var showConfig string - if routingInstance == "" || routingInstance == junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols bgp group \"" + name + "\"" + junos.PipeDisplaySet) - if err != nil { - return false, err - } - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "protocols bgp group \"" + name + "\"" + junos.PipeDisplaySet) - if err != nil { - return false, err - } + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " + } + showConfig, err := junSess.Command(showPrefix + + "protocols bgp group \"" + name + "\"" + junos.PipeDisplaySet) + if err != nil { + return false, err } if showConfig == junos.EmptyW { return false, nil @@ -1578,11 +1572,12 @@ func (rscData *bgpGroupData) set( ) ( path.Path, error, ) { - setPrefix := "set protocols bgp group \"" + rscData.Name.ValueString() + "\" " + setPrefix := junos.SetLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + v + - " protocols bgp group \"" + rscData.Name.ValueString() + "\" " + setPrefix += junos.RoutingInstancesWS + v + " " } + setPrefix += "protocols bgp group \"" + rscData.Name.ValueString() + "\" " + configSet := []string{ setPrefix + "type " + rscData.Type.ValueString(), } @@ -1789,23 +1784,15 @@ func (rscData *bgpGroupData) set( func (rscData *bgpGroupData) read( _ context.Context, name, routingInstance string, junSess *junos.Session, -) ( - err error, -) { - var showConfig string - if routingInstance == "" || routingInstance == junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols bgp group \"" + name + "\"" + junos.PipeDisplaySetRelative) - if err != nil { - return err - } - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "protocols bgp group \"" + name + "\"" + junos.PipeDisplaySetRelative) - if err != nil { - return err - } +) error { + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " + } + showConfig, err := junSess.Command(showPrefix + + "protocols bgp group \"" + name + "\"" + junos.PipeDisplaySetRelative) + if err != nil { + return err } if showConfig != junos.EmptyW { rscData.Name = types.StringValue(name) @@ -2020,11 +2007,11 @@ func (rscData *bgpGroupData) delOpts( _ context.Context, junSess *junos.Session, ) error { configSet := make([]string, 0) - delPrefix := "delete protocols bgp group \"" + rscData.Name.ValueString() + "\" " + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + v + - " protocols bgp group \"" + rscData.Name.ValueString() + "\" " + delPrefix += junos.RoutingInstancesWS + v + " " } + delPrefix += "protocols bgp group \"" + rscData.Name.ValueString() + "\" " configSet = append(configSet, delPrefix+"accept-remote-nexthop", @@ -2073,13 +2060,13 @@ func (rscData *bgpGroupData) delOpts( func (rscData *bgpGroupData) del( _ context.Context, junSess *junos.Session, ) error { - configSet := make([]string, 1) + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - configSet[0] = junos.DelRoutingInstances + v + - " protocols bgp group \"" + rscData.Name.ValueString() + "\"" - } else { - configSet[0] = junos.DeleteW + - " protocols bgp group \"" + rscData.Name.ValueString() + "\"" + delPrefix += junos.RoutingInstancesWS + v + " " + } + + configSet := []string{ + delPrefix + "protocols bgp group \"" + rscData.Name.ValueString() + "\"", } return junSess.ConfigSet(configSet) diff --git a/internal/providerfwk/resource_bgp_neighbor.go b/internal/providerfwk/resource_bgp_neighbor.go index 24dbbdcd..0936be5b 100644 --- a/internal/providerfwk/resource_bgp_neighbor.go +++ b/internal/providerfwk/resource_bgp_neighbor.go @@ -887,7 +887,7 @@ func (rsc *bgpNeighbor) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("advertise_peer_as"), tfdiag.ConflictConfigErrSummary, - "advertise_peer_as and no_advertise_peer_as can't be true in same time ", + "advertise_peer_as and no_advertise_peer_as can't be true in same time", ) } if !config.KeepAll.IsNull() && !config.KeepAll.IsUnknown() && @@ -895,7 +895,7 @@ func (rsc *bgpNeighbor) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("keep_all"), tfdiag.ConflictConfigErrSummary, - "keep_all and keep_none can't be true in same time ", + "keep_all and keep_none can't be true in same time", ) } if !config.AuthenticationKey.IsNull() && !config.AuthenticationKey.IsUnknown() { @@ -1083,7 +1083,7 @@ func (rsc *bgpNeighbor) ValidateConfig( path.Root("family_evpn").AtListIndex(i).AtName("accepted_prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in accepted_prefix_limit block in family_evpn block ", + " in accepted_prefix_limit block in family_evpn block", ) } } @@ -1103,7 +1103,7 @@ func (rsc *bgpNeighbor) ValidateConfig( path.Root("family_evpn").AtListIndex(i).AtName("prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in prefix_limit block family_evpn block ", + " in prefix_limit block family_evpn block", ) } } @@ -1146,7 +1146,7 @@ func (rsc *bgpNeighbor) ValidateConfig( path.Root("family_inet").AtListIndex(i).AtName("accepted_prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in accepted_prefix_limit block in family_inet block ", + " in accepted_prefix_limit block in family_inet block", ) } } @@ -1166,7 +1166,7 @@ func (rsc *bgpNeighbor) ValidateConfig( path.Root("family_inet").AtListIndex(i).AtName("prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in prefix_limit block family_inet block ", + " in prefix_limit block family_inet block", ) } } @@ -1209,7 +1209,7 @@ func (rsc *bgpNeighbor) ValidateConfig( path.Root("family_inet6").AtListIndex(i).AtName("accepted_prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in accepted_prefix_limit block in family_inet6 block ", + " in accepted_prefix_limit block in family_inet6 block", ) } } @@ -1229,7 +1229,7 @@ func (rsc *bgpNeighbor) ValidateConfig( path.Root("family_inet6").AtListIndex(i).AtName("prefix_limit").AtName("teardown_idle_timeout"), tfdiag.ConflictConfigErrSummary, "teardown_idle_timeout and teardown_idle_timeout_forever cannot be configured together"+ - " in prefix_limit block family_inet6 block ", + " in prefix_limit block family_inet6 block", ) } } @@ -1573,24 +1573,16 @@ func checkBgpNeighborExists( group string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { - var showConfig string - if routingInstance == junos.DefaultW || routingInstance == "" { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols bgp group \"" + group + "\"" + - " neighbor " + ip + junos.PipeDisplaySet) - if err != nil { - return false, err - } - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "protocols bgp group \"" + group + "\"" + - " neighbor " + ip + junos.PipeDisplaySet) - if err != nil { - return false, err - } + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " + } + showConfig, err := junSess.Command(showPrefix + + "protocols bgp group \"" + group + "\" neighbor " + ip + junos.PipeDisplaySet) + if err != nil { + return false, err } if showConfig == junos.EmptyW { return false, nil @@ -1624,13 +1616,12 @@ func (rscData *bgpNeighborData) set( ) ( path.Path, error, ) { - setPrefix := "set protocols bgp group \"" + rscData.Group.ValueString() + "\"" + - " neighbor " + rscData.IP.ValueString() + " " + setPrefix := junos.SetLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + v + - " protocols bgp group \"" + rscData.Group.ValueString() + "\"" + - " neighbor " + rscData.IP.ValueString() + " " + setPrefix += junos.RoutingInstancesWS + v + " " } + setPrefix += "protocols bgp group \"" + rscData.Group.ValueString() + "\" neighbor " + rscData.IP.ValueString() + " " + configSet := []string{ setPrefix, } @@ -1841,25 +1832,15 @@ func (rscData *bgpNeighborData) read( routingInstance, group string, junSess *junos.Session, -) ( - err error, -) { - var showConfig string - if routingInstance == junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols bgp group \"" + group + "\"" + - " neighbor " + ip + junos.PipeDisplaySetRelative) - if err != nil { - return err - } - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "protocols bgp group \"" + group + "\"" + - " neighbor " + ip + junos.PipeDisplaySetRelative) - if err != nil { - return err - } +) error { + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " + } + showConfig, err := junSess.Command(showPrefix + + "protocols bgp group \"" + group + "\" neighbor " + ip + junos.PipeDisplaySetRelative) + if err != nil { + return err } if showConfig != junos.EmptyW { rscData.IP = types.StringValue(ip) @@ -2073,14 +2054,11 @@ func (rscData *bgpNeighborData) delOpts( _ context.Context, junSess *junos.Session, ) error { configSet := make([]string, 0) - delPrefix := junos.DeleteW + - " protocols bgp group \"" + rscData.Group.ValueString() + "\"" + - " neighbor " + rscData.IP.ValueString() + " " + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + v + - " protocols bgp group \"" + rscData.Group.ValueString() + "\"" + - " neighbor " + rscData.IP.ValueString() + " " + delPrefix += junos.RoutingInstancesWS + v + " " } + delPrefix += "protocols bgp group \"" + rscData.Group.ValueString() + "\" neighbor " + rscData.IP.ValueString() + " " configSet = append(configSet, delPrefix+"accept-remote-nexthop", @@ -2129,15 +2107,13 @@ func (rscData *bgpNeighborData) delOpts( func (rscData *bgpNeighborData) del( _ context.Context, junSess *junos.Session, ) error { - configSet := make([]string, 1) + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - configSet[0] = junos.DelRoutingInstances + v + - " protocols bgp group \"" + rscData.Group.ValueString() + "\"" + - " neighbor " + rscData.IP.ValueString() - } else { - configSet[0] = junos.DeleteW + - " protocols bgp group \"" + rscData.Group.ValueString() + "\"" + - " neighbor " + rscData.IP.ValueString() + delPrefix += junos.RoutingInstancesWS + v + " " + } + + configSet := []string{ + delPrefix + "protocols bgp group \"" + rscData.Group.ValueString() + "\" neighbor " + rscData.IP.ValueString(), } return junSess.ConfigSet(configSet) diff --git a/internal/providerfwk/resource_bridge_domain.go b/internal/providerfwk/resource_bridge_domain.go index 48cd2921..a0e1cbc7 100644 --- a/internal/providerfwk/resource_bridge_domain.go +++ b/internal/providerfwk/resource_bridge_domain.go @@ -219,6 +219,13 @@ func (rsc *bridgeDomain) Schema( int64validator.Between(0, 16777214), }, }, + "vni_extend_evpn": schema.BoolAttribute{ + Optional: true, + Description: "Extend VNI to EVPN.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, "decapsulate_accept_inner_vlan": schema.BoolAttribute{ Optional: true, Description: "Accept VXLAN packets with inner VLAN.", @@ -261,13 +268,6 @@ func (rsc *bridgeDomain) Schema( int64validator.Between(300, 1800), }, }, - "vni_extend_evpn": schema.BoolAttribute{ - Optional: true, - Description: "Extend VNI to EVPN.", - Validators: []validator.Bool{ - tfvalidator.BoolTrue(), - }, - }, }, PlanModifiers: []planmodifier.Object{ tfplanmodifier.BlockRemoveNull(), @@ -316,14 +316,14 @@ func (rscConfig *bridgeDomainConfig) isEmpty() bool { } type bridgeDomainBlockVXLAN struct { - VNI types.Int64 `tfsdk:"vni"` + Vni types.Int64 `tfsdk:"vni"` + VniExtendEvpn types.Bool `tfsdk:"vni_extend_evpn"` DecapsulateAcceptInnerVlan types.Bool `tfsdk:"decapsulate_accept_inner_vlan"` EncapsulateInnerVlan types.Bool `tfsdk:"encapsulate_inner_vlan"` IngressNodeReplication types.Bool `tfsdk:"ingress_node_replication"` MulticastGroup types.String `tfsdk:"multicast_group"` OvsdbManaged types.Bool `tfsdk:"ovsdb_managed"` UnreachableVtepAgingTimer types.Int64 `tfsdk:"unreachable_vtep_aging_timer"` - VNIExtendEvpn types.Bool `tfsdk:"vni_extend_evpn"` } func (rsc *bridgeDomain) ValidateConfig( @@ -352,7 +352,7 @@ func (rsc *bridgeDomain) ValidateConfig( ) } if config.VXLAN != nil { - if config.VXLAN.VNI.IsNull() { + if config.VXLAN.Vni.IsNull() { resp.Diagnostics.AddAttributeError( path.Root("vxlan").AtName("vni"), tfdiag.MissingConfigErrSummary, @@ -554,17 +554,17 @@ func (rsc *bridgeDomain) ImportState( func checkBridgeDomainExists( _ context.Context, name, routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - showConfig, err := junSess.Command(showPrefix + "bridge-domains \"" + name + "\"" + junos.PipeDisplaySet) + showConfig, err := junSess.Command(showPrefix + + "bridge-domains \"" + name + "\"" + junos.PipeDisplaySet) if err != nil { return false, err } - if showConfig == junos.EmptyW { return false, nil } @@ -590,12 +590,11 @@ func (rscData *bridgeDomainData) set( path.Path, error, ) { configSet := make([]string, 0) - setPrefix := junos.SetLS - routingInstance := rscData.RoutingInstance.ValueString() - if routingInstance != "" && routingInstance != junos.DefaultW { - setPrefix += junos.RoutingInstancesWS + routingInstance + " " + if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { + setPrefix += junos.RoutingInstancesWS + v + " " } + setPrefixProtocolsEvpn := setPrefix + "protocols evpn " setPrefix += "bridge-domains \"" + rscData.Name.ValueString() + "\" " for _, v := range rscData.CommunityVlans { @@ -634,16 +633,11 @@ func (rscData *bridgeDomainData) set( } if rscData.VXLAN != nil { configSet = append(configSet, setPrefix+"vxlan vni "+ - utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - - if rscData.VXLAN.VNIExtendEvpn.ValueBool() { - if routingInstance != "" && routingInstance != junos.DefaultW { - configSet = append(configSet, junos.SetRoutingInstances+routingInstance+" protocols evpn extended-vni-list "+ - utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - } else { - configSet = append(configSet, "set protocols evpn extended-vni-list "+ - utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - } + utils.ConvI64toa(rscData.VXLAN.Vni.ValueInt64())) + + if rscData.VXLAN.VniExtendEvpn.ValueBool() { + configSet = append(configSet, setPrefixProtocolsEvpn+"extended-vni-list "+ + utils.ConvI64toa(rscData.VXLAN.Vni.ValueInt64())) } if rscData.VXLAN.DecapsulateAcceptInnerVlan.ValueBool() { configSet = append(configSet, setPrefix+"vxlan decapsulate-accept-inner-vlan") @@ -671,18 +665,16 @@ func (rscData *bridgeDomainData) set( func (rscData *bridgeDomainData) read( _ context.Context, name, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - showConfig, err := junSess.Command(showPrefix + "bridge-domains \"" + name + "\"" + junos.PipeDisplaySetRelative) + showConfig, err := junSess.Command(showPrefix + + "bridge-domains \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { rscData.Name = types.StringValue(name) if routingInstance == "" { @@ -738,19 +730,14 @@ func (rscData *bridgeDomainData) read( } switch { case balt.CutPrefixInString(&itemTrim, "vni "): - rscData.VXLAN.VNI, err = tfdata.ConvAtoi64Value(itemTrim) + rscData.VXLAN.Vni, err = tfdata.ConvAtoi64Value(itemTrim) if err != nil { return err } - showPrefixEvpn := junos.CmdShowConfig - if routingInstance != "" && routingInstance != junos.DefaultW { - showPrefixEvpn += junos.RoutingInstancesWS + routingInstance + " " - } - showConfigEvpn, err := junSess.Command(showPrefixEvpn + "protocols evpn" + junos.PipeDisplaySetRelative) + showConfigEvpn, err := junSess.Command(showPrefix + "protocols evpn" + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfigEvpn != junos.EmptyW { for _, itemEvpn := range strings.Split(showConfigEvpn, "\n") { if strings.Contains(itemEvpn, junos.XMLStartTagConfigOut) { @@ -760,7 +747,7 @@ func (rscData *bridgeDomainData) read( break } if strings.HasPrefix(itemEvpn, junos.SetLS+"extended-vni-list "+itemTrim) { - rscData.VXLAN.VNIExtendEvpn = types.BoolValue(true) + rscData.VXLAN.VniExtendEvpn = types.BoolValue(true) break } @@ -794,8 +781,9 @@ func (rscData *bridgeDomainData) delOpts( ) error { delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + v + " " + delPrefix += junos.RoutingInstancesWS + v + " " } + delPrefixProtocolsEvpn := delPrefix + "protocols evpn " delPrefix += "bridge-domains \"" + rscData.Name.ValueString() + "\" " configSet := []string{ @@ -814,14 +802,9 @@ func (rscData *bridgeDomainData) delOpts( configSet = append(configSet, delPrefix+"interface "+v.ValueString()) } if rscData.VXLAN != nil { - if rscData.VXLAN.VNIExtendEvpn.ValueBool() { - if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - configSet = append(configSet, junos.DelRoutingInstances+v+" "+ - "protocols evpn extended-vni-list "+utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - } else { - configSet = append(configSet, junos.DeleteLS+ - "protocols evpn extended-vni-list "+utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - } + if rscData.VXLAN.VniExtendEvpn.ValueBool() { + configSet = append(configSet, delPrefixProtocolsEvpn+ + "extended-vni-list "+utils.ConvI64toa(rscData.VXLAN.Vni.ValueInt64())) } } @@ -831,22 +814,18 @@ func (rscData *bridgeDomainData) delOpts( func (rscData *bridgeDomainData) del( _ context.Context, junSess *junos.Session, ) error { - configSet := make([]string, 0, 1) + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - configSet = append(configSet, junos.DelRoutingInstances+v+ - " bridge-domains \""+rscData.Name.ValueString()+"\"") - } else { - configSet = append(configSet, "delete bridge-domains \""+rscData.Name.ValueString()+"\"") + delPrefix += junos.RoutingInstancesWS + v + " " + } + + configSet := []string{ + delPrefix + "bridge-domains \"" + rscData.Name.ValueString() + "\"", } if rscData.VXLAN != nil { - if rscData.VXLAN.VNIExtendEvpn.ValueBool() { - if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - configSet = append(configSet, junos.DelRoutingInstances+v+" "+ - "protocols evpn extended-vni-list "+utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - } else { - configSet = append(configSet, junos.DeleteLS+ - "protocols evpn extended-vni-list "+utils.ConvI64toa(rscData.VXLAN.VNI.ValueInt64())) - } + if rscData.VXLAN.VniExtendEvpn.ValueBool() { + configSet = append(configSet, delPrefix+ + "protocols evpn extended-vni-list "+utils.ConvI64toa(rscData.VXLAN.Vni.ValueInt64())) } } diff --git a/internal/providerfwk/resource_eventoptions_destination.go b/internal/providerfwk/resource_eventoptions_destination.go index fc8c5b88..5669b1f6 100644 --- a/internal/providerfwk/resource_eventoptions_destination.go +++ b/internal/providerfwk/resource_eventoptions_destination.go @@ -389,9 +389,7 @@ func (rscData *eventoptionsDestinationData) set( func (rscData *eventoptionsDestinationData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "event-options destinations \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_eventoptions_generate_event.go b/internal/providerfwk/resource_eventoptions_generate_event.go index 98056b00..3646f2e0 100644 --- a/internal/providerfwk/resource_eventoptions_generate_event.go +++ b/internal/providerfwk/resource_eventoptions_generate_event.go @@ -368,9 +368,7 @@ func (rscData *eventoptionsGenerateEventData) set( func (rscData *eventoptionsGenerateEventData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "event-options generate-event \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_eventoptions_policy.go b/internal/providerfwk/resource_eventoptions_policy.go index e5065336..071d3a4c 100644 --- a/internal/providerfwk/resource_eventoptions_policy.go +++ b/internal/providerfwk/resource_eventoptions_policy.go @@ -1316,8 +1316,8 @@ func (block *eventoptionsPolicyBlockThen) configSet( path.Path, // pathErr error, // error ) { - setPrefix += "then " configSet := make([]string, 0) + setPrefix += "then " if block.Ignore.ValueBool() { configSet = append(configSet, setPrefix+"ignore") @@ -1389,8 +1389,8 @@ func (block *eventoptionsPolicyBlockThenBlockChangeConfigurtion) configSet( path.Path, // pathErr error, // error ) { - setPrefix += "change-configuration " configSet := make([]string, 0, len(block.Commands)) + setPrefix += "change-configuration " for _, v := range block.Commands { configSet = append(configSet, setPrefix+"commands \""+v.ValueString()+"\"") @@ -1443,6 +1443,7 @@ func (block *eventoptionsPolicyBlockThenBlockEventScript) configSet( error, // error ) { setPrefix += "event-script \"" + block.Filename.ValueString() + "\" " + configSet := []string{ setPrefix, } @@ -1486,8 +1487,8 @@ func (block *eventoptionsPolicyBlockThenBlockExecuteCommands) configSet( path.Path, // pathErr error, // error ) { - setPrefix += "execute-commands " configSet := make([]string, 0, len(block.Commands)) + setPrefix += "execute-commands " for _, v := range block.Commands { configSet = append(configSet, setPrefix+"commands \""+v.ValueString()+"\"") @@ -1521,6 +1522,7 @@ func (block *eventoptionsPolicyBlockThenBlockUpload) configSet( ) { setPrefix += "upload filename \"" + block.Filename.ValueString() + "\"" + " destination \"" + block.Destination.ValueString() + "\" " + configSet := []string{ setPrefix, } @@ -1558,6 +1560,7 @@ func (block *eventoptionsPolicyBlockThenBlockDestination) configSet( error, // error ) { setPrefix += "destination \"" + block.Name.ValueString() + "\" " + configSet := []string{ setPrefix, } @@ -1591,8 +1594,8 @@ func (block *eventoptionsPolicyBlockWithin) configSet( path.Path, // pathErr error, // error ) { - setPrefix += "within " + utils.ConvI64toa(block.TimeInterval.ValueInt64()) + " " configSet := make([]string, 0) + setPrefix += "within " + utils.ConvI64toa(block.TimeInterval.ValueInt64()) + " " for _, v := range block.Events { configSet = append(configSet, setPrefix+"events \""+v.ValueString()+"\"") @@ -1619,9 +1622,7 @@ func (block *eventoptionsPolicyBlockWithin) configSet( func (rscData *eventoptionsPolicyData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "event-options policy \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_evpn.go b/internal/providerfwk/resource_evpn.go index 387bdddb..cdd9ddc2 100644 --- a/internal/providerfwk/resource_evpn.go +++ b/internal/providerfwk/resource_evpn.go @@ -581,7 +581,11 @@ func (rsc *evpn) ImportState( } func (rscData *evpnData) fillID() { - rscData.ID = types.StringValue(rscData.RoutingInstance.ValueString()) + if v := rscData.RoutingInstance.ValueString(); v != "" { + rscData.ID = types.StringValue(v) + } else { + rscData.ID = types.StringValue(junos.DefaultW) + } } func (rscData *evpnData) nullID() bool { @@ -593,6 +597,7 @@ func (rscData *evpnData) set( ) ( path.Path, error, ) { + configSet := make([]string, 0) setPrefix := junos.SetLS setSwitchRIPrefix := junos.SetLS switch routingInstance := rscData.RoutingInstance.ValueString(); routingInstance { @@ -609,14 +614,12 @@ func (rscData *evpnData) set( return path.Root("default_gateway"), fmt.Errorf("default_gateway cannot be configured when routing_instance = %q", junos.DefaultW) } - setPrefix += "protocols evpn " setSwitchRIPrefix += "switch-options " default: - setPrefix += junos.RoutingInstancesWS + routingInstance + " protocols evpn " + setPrefix += junos.RoutingInstancesWS + routingInstance + " " setSwitchRIPrefix += junos.RoutingInstancesWS + routingInstance + " " } - - configSet := make([]string, 0) + setPrefix += "protocols evpn " if rscData.RoutingInstanceEvpn.ValueBool() { if rscData.SwitchOrRIOptions == nil { @@ -686,31 +689,30 @@ func (rscData *evpnData) set( func (rscData *evpnData) read( _ context.Context, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig - showSwitchRIPrefix := junos.CmdShowConfig - switch routingInstance { - case junos.DefaultW, "": - showPrefix += "protocols evpn" - showSwitchRIPrefix += "switch-options" - default: - showPrefix += junos.RoutingInstancesWS + routingInstance + " protocols evpn" - showSwitchRIPrefix += junos.RoutingInstancesWS + routingInstance - } - - showConfig, err := junSess.Command(showPrefix + junos.PipeDisplaySetRelative) + showSwitchRI := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " + showSwitchRI += junos.RoutingInstancesWS + routingInstance + } else { + showSwitchRI += "switch-options" + } + showConfig, err := junSess.Command(showPrefix + + "protocols evpn" + junos.PipeDisplaySetRelative) if err != nil { return err } - showConfigSwitchRI, err := junSess.Command(showSwitchRIPrefix + junos.PipeDisplaySetRelative) + showConfigSwitchRI, err := junSess.Command(showSwitchRI + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { - rscData.RoutingInstance = types.StringValue(routingInstance) + if routingInstance == "" { + rscData.RoutingInstance = types.StringValue(junos.DefaultW) + } else { + rscData.RoutingInstance = types.StringValue(routingInstance) + } rscData.fillID() for _, item := range strings.Split(showConfig, "\n") { if strings.Contains(item, junos.XMLStartTagConfigOut) { @@ -801,12 +803,12 @@ func (rscData *evpnData) delOpts( delSwitchRIPrefix := junos.DeleteLS switch routingInstance := rscData.RoutingInstance.ValueString(); routingInstance { case junos.DefaultW, "": - delPrefix += "protocols evpn " delSwitchRIPrefix += "switch-options " default: - delPrefix += junos.RoutingInstancesWS + routingInstance + " protocols evpn " + delPrefix += junos.RoutingInstancesWS + routingInstance + " " delSwitchRIPrefix += junos.RoutingInstancesWS + routingInstance + " " } + delPrefix += "protocols evpn " configSet := []string{ delPrefix + "default-gateway", @@ -835,19 +837,18 @@ func (rscData *evpnData) delOpts( func (rscData *evpnData) del( _ context.Context, junSess *junos.Session, ) error { - delLine := junos.DeleteLS + delPrefix := junos.DeleteLS delSwitchRIPrefix := junos.DeleteLS switch routingInstance := rscData.RoutingInstance.ValueString(); routingInstance { case junos.DefaultW, "": - delLine += "protocols evpn" delSwitchRIPrefix += "switch-options " default: - delLine += junos.RoutingInstancesWS + routingInstance + " protocols evpn" + delPrefix += junos.RoutingInstancesWS + routingInstance + " " delSwitchRIPrefix += junos.RoutingInstancesWS + routingInstance + " " } configSet := []string{ - delLine, + delPrefix + "protocols evpn", } if rscData.RoutingInstanceEvpn.ValueBool() { diff --git a/internal/providerfwk/resource_firewall_filter.go b/internal/providerfwk/resource_firewall_filter.go index 52cbb59d..5a0cb512 100644 --- a/internal/providerfwk/resource_firewall_filter.go +++ b/internal/providerfwk/resource_firewall_filter.go @@ -1989,9 +1989,7 @@ func (block *firewallFilterBlockTermBlockThen) configSet(setPrefix string) []str func (rscData *firewallFilterData) read( _ context.Context, name, family string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "firewall family " + family + " filter \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_firewall_policer.go b/internal/providerfwk/resource_firewall_policer.go index 79d637b9..f0a137a0 100644 --- a/internal/providerfwk/resource_firewall_policer.go +++ b/internal/providerfwk/resource_firewall_policer.go @@ -547,7 +547,7 @@ func (rsc *firewallPolicer) ImportState( func checkFirewallPolicerExists( _ context.Context, name string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showConfig, err := junSess.Command(junos.CmdShowConfig + "firewall policer \"" + name + "\"" + junos.PipeDisplaySet) @@ -629,9 +629,7 @@ func (rscData *firewallPolicerData) set( func (rscData *firewallPolicerData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "firewall policer \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_forwardingoptions_evpn_vxlan.go b/internal/providerfwk/resource_forwardingoptions_evpn_vxlan.go index acad3e33..8ac3d290 100644 --- a/internal/providerfwk/resource_forwardingoptions_evpn_vxlan.go +++ b/internal/providerfwk/resource_forwardingoptions_evpn_vxlan.go @@ -311,7 +311,7 @@ func (rscData *forwardingoptionsEvpnVxlanData) set( configSet := make([]string, 0) setPrefix := junos.SetLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + v + " " + setPrefix += junos.RoutingInstancesWS + v + " " } setPrefix += "forwarding-options evpn-vxlan " @@ -324,14 +324,11 @@ func (rscData *forwardingoptionsEvpnVxlanData) set( func (rscData *forwardingoptionsEvpnVxlanData) read( _ context.Context, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - showConfig, err := junSess.Command(showPrefix + "forwarding-options evpn-vxlan" + junos.PipeDisplaySetRelative) if err != nil { @@ -366,7 +363,7 @@ func (rscData *forwardingoptionsEvpnVxlanData) del( ) error { delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + v + " " + delPrefix += junos.RoutingInstancesWS + v + " " } delPrefix += "forwarding-options evpn-vxlan " diff --git a/internal/providerfwk/resource_forwardingoptions_sampling.go b/internal/providerfwk/resource_forwardingoptions_sampling.go index 3ef7b648..d7bba663 100644 --- a/internal/providerfwk/resource_forwardingoptions_sampling.go +++ b/internal/providerfwk/resource_forwardingoptions_sampling.go @@ -1377,11 +1377,11 @@ func (rscData *forwardingoptionsSamplingData) set( path.Path, error, ) { configSet := make([]string, 0) - setPrefix := "set forwarding-options sampling " - + setPrefix := junos.SetLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + v + " forwarding-options sampling " + setPrefix += junos.RoutingInstancesWS + v + " " } + setPrefix += "forwarding-options sampling " if rscData.Disable.ValueBool() { configSet = append(configSet, setPrefix+"disable") @@ -1824,18 +1824,13 @@ func (block *forwardingoptionsSamplingBlockOutputBlockInterface) configSet(setPr func (rscData *forwardingoptionsSamplingData) read( _ context.Context, routingInstance string, junSess *junos.Session, -) ( - err error, -) { - var showConfig string +) error { + showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "forwarding-options sampling" + junos.PipeDisplaySetRelative) - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "forwarding-options sampling" + junos.PipeDisplaySetRelative) + showPrefix += junos.RoutingInstancesWS + routingInstance + " " } + showConfig, err := junSess.Command(showPrefix + + "forwarding-options sampling" + junos.PipeDisplaySetRelative) if err != nil { return err } @@ -2246,10 +2241,12 @@ func (block *forwardingoptionsSamplingBlockOutputBlockInterface) read(itemTrim s func (rscData *forwardingoptionsSamplingData) del( _ context.Context, junSess *junos.Session, ) error { - delPrefix := "delete forwarding-options sampling " + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + v + " forwarding-options sampling " + delPrefix += junos.RoutingInstancesWS + v + " " } + delPrefix += "forwarding-options sampling " + configSet := []string{ delPrefix + junos.DisableW, delPrefix + "pre-rewrite-tos", diff --git a/internal/providerfwk/resource_forwardingoptions_sampling_instance.go b/internal/providerfwk/resource_forwardingoptions_sampling_instance.go index 0dffa07a..26f6b597 100644 --- a/internal/providerfwk/resource_forwardingoptions_sampling_instance.go +++ b/internal/providerfwk/resource_forwardingoptions_sampling_instance.go @@ -1292,17 +1292,14 @@ func (rsc *forwardingoptionsSamplingInstance) ImportState( func checkForwardingoptionsSamplingInstanceExists( _ context.Context, name, routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { - var showConfig string + showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "forwarding-options sampling instance \"" + name + "\"" + junos.PipeDisplaySet) - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "forwarding-options sampling instance \"" + name + "\"" + junos.PipeDisplaySet) + showPrefix += junos.RoutingInstancesWS + routingInstance + " " } + showConfig, err := junSess.Command(showPrefix + + "forwarding-options sampling instance \"" + name + "\"" + junos.PipeDisplaySet) if err != nil { return false, err } @@ -1331,12 +1328,11 @@ func (rscData *forwardingoptionsSamplingInstanceData) set( path.Path, error, ) { configSet := make([]string, 0) - setPrefix := "set forwarding-options sampling instance \"" + rscData.Name.ValueString() + "\" " - + setPrefix := junos.SetLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + v + - " forwarding-options sampling instance \"" + rscData.Name.ValueString() + "\" " + setPrefix += junos.RoutingInstancesWS + v + " " } + setPrefix += "forwarding-options sampling instance \"" + rscData.Name.ValueString() + "\" " if rscData.Disable.ValueBool() { configSet = append(configSet, setPrefix+"disable") @@ -1762,18 +1758,13 @@ func (block *forwardingoptionsSamplingInstanceBlockOutputBlockInterface) configS func (rscData *forwardingoptionsSamplingInstanceData) read( _ context.Context, name, routingInstance string, junSess *junos.Session, -) ( - err error, -) { - var showConfig string +) error { + showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - junos.RoutingInstancesWS + routingInstance + " " + - "forwarding-options sampling instance \"" + name + "\"" + junos.PipeDisplaySetRelative) - } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "forwarding-options sampling instance \"" + name + "\"" + junos.PipeDisplaySetRelative) + showPrefix += junos.RoutingInstancesWS + routingInstance + " " } + showConfig, err := junSess.Command(showPrefix + + "forwarding-options sampling instance \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { return err } @@ -2153,13 +2144,13 @@ func (block *forwardingoptionsSamplingInstanceBlockOutputBlockInterface) read(it func (rscData *forwardingoptionsSamplingInstanceData) del( _ context.Context, junSess *junos.Session, ) error { - configSet := make([]string, 1) + delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - configSet[0] = junos.DelRoutingInstances + v + - " forwarding-options sampling instance \"" + rscData.Name.ValueString() + "\"" - } else { - configSet[0] = junos.DeleteW + - " forwarding-options sampling instance \"" + rscData.Name.ValueString() + "\"" + delPrefix += junos.RoutingInstancesWS + v + " " + } + + configSet := []string{ + delPrefix + "forwarding-options sampling instance \"" + rscData.Name.ValueString() + "\"", } return junSess.ConfigSet(configSet) diff --git a/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go b/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go index 01b677ec..ff4258d0 100644 --- a/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go +++ b/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go @@ -394,7 +394,7 @@ func (rsc *forwardingoptionsStormControlProfile) ImportState( func checkForwardingoptionsStormControlProfileExists( _ context.Context, name string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showConfig, err := junSess.Command(junos.CmdShowConfig + "forwarding-options storm-control-profiles \"" + name + "\"" + junos.PipeDisplaySet) @@ -464,9 +464,7 @@ func (rscData *forwardingoptionsStormControlProfileData) set( func (rscData *forwardingoptionsStormControlProfileData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "forwarding-options storm-control-profiles \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_generate_route.go b/internal/providerfwk/resource_generate_route.go index 0eaa1e00..d6a936a5 100644 --- a/internal/providerfwk/resource_generate_route.go +++ b/internal/providerfwk/resource_generate_route.go @@ -511,7 +511,7 @@ func (rsc *generateRoute) ImportState( func checkGenerateRouteExists( _ context.Context, destination, routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showPrefix := junos.CmdShowConfig switch routingInstance { @@ -526,11 +526,11 @@ func checkGenerateRouteExists( showPrefix += "rib " + routingInstance + ".inet6.0 " } } - showConfig, err := junSess.Command(showPrefix + "generate route " + destination + junos.PipeDisplaySet) + showConfig, err := junSess.Command(showPrefix + + "generate route " + destination + junos.PipeDisplaySet) if err != nil { return false, err } - if showConfig == junos.EmptyW { return false, nil } @@ -569,6 +569,7 @@ func (rscData *generateRouteData) set( } } setPrefix += "generate route " + rscData.Destination.ValueString() + " " + configSet := []string{ setPrefix, } @@ -624,9 +625,7 @@ func (rscData *generateRouteData) set( func (rscData *generateRouteData) read( _ context.Context, destination, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig switch routingInstance { case junos.DefaultW, "": @@ -640,14 +639,18 @@ func (rscData *generateRouteData) read( showPrefix += "rib " + routingInstance + ".inet6.0 " } } - showConfig, err := junSess.Command(showPrefix + "generate route " + destination + junos.PipeDisplaySetRelative) + showConfig, err := junSess.Command(showPrefix + + "generate route " + destination + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { rscData.Destination = types.StringValue(destination) - rscData.RoutingInstance = types.StringValue(routingInstance) + if routingInstance == "" { + rscData.RoutingInstance = types.StringValue(junos.DefaultW) + } else { + rscData.RoutingInstance = types.StringValue(routingInstance) + } rscData.fillID() for _, item := range strings.Split(showConfig, "\n") { if strings.Contains(item, junos.XMLStartTagConfigOut) { @@ -720,6 +723,7 @@ func (rscData *generateRouteData) del( delPrefix += "rib " + routingInstance + ".inet6.0 " } } + configSet := []string{ delPrefix + "generate route " + rscData.Destination.ValueString(), } diff --git a/internal/providerfwk/resource_iccp.go b/internal/providerfwk/resource_iccp.go index b6f3c7bd..4f653541 100644 --- a/internal/providerfwk/resource_iccp.go +++ b/internal/providerfwk/resource_iccp.go @@ -223,6 +223,7 @@ func (rscData *iccpData) set( path.Path, error, ) { setPrefix := "set protocols iccp " + configSet := []string{ setPrefix + "local-ip-addr " + rscData.LocalIPAddr.ValueString(), } @@ -240,15 +241,12 @@ func (rscData *iccpData) set( func (rscData *iccpData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "protocols iccp" + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { rscData.fillID() for _, item := range strings.Split(showConfig, "\n") { diff --git a/internal/providerfwk/resource_iccp_peer.go b/internal/providerfwk/resource_iccp_peer.go index c00a9be4..ced93360 100644 --- a/internal/providerfwk/resource_iccp_peer.go +++ b/internal/providerfwk/resource_iccp_peer.go @@ -518,9 +518,7 @@ func (rscData *iccpPeerData) set( func (rscData *iccpPeerData) read( _ context.Context, ipAddress string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "protocols iccp peer " + ipAddress + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_interface_logical.go b/internal/providerfwk/resource_interface_logical.go index da9f5062..b95a46de 100644 --- a/internal/providerfwk/resource_interface_logical.go +++ b/internal/providerfwk/resource_interface_logical.go @@ -2291,6 +2291,7 @@ func (rscData *interfaceLogicalData) set( } setPrefix := "set interfaces " + rscData.Name.ValueString() + " " + configSet := []string{ setPrefix, } @@ -2405,7 +2406,7 @@ func (rscData *interfaceLogicalData) set( } } if v := rscData.RoutingInstance.ValueString(); v != "" { - configSet = append(configSet, junos.SetRoutingInstances+v+" interface "+rscData.Name.ValueString()) + configSet = append(configSet, junos.SetLS+junos.RoutingInstancesWS+v+" interface "+rscData.Name.ValueString()) } if securityZone := rscData.SecurityZone.ValueString(); securityZone != "" { configSet = append(configSet, "set security zones security-zone "+securityZone+ @@ -2466,6 +2467,7 @@ func (block *interfaceLogicalBlockFamilyInetBlockAddress) configSet( error, // error ) { setPrefix += "family inet address " + block.CidrIP.ValueString() + configSet := []string{ setPrefix, } @@ -2569,6 +2571,7 @@ func (block *interfaceLogicalBlockFamilyInet6BlockAddress) configSet( error, // error ) { setPrefix += "family inet6 address " + block.CidrIP.ValueString() + configSet := []string{ setPrefix, } @@ -2668,6 +2671,7 @@ func (block *interfaceLogicalBlockFamilyInetBlockDhcp) configSet(setPrefix strin } else { setPrefix += " " } + configSet := []string{ setPrefix, } @@ -2736,6 +2740,7 @@ func (block *interfaceLogicalBlockFamilyInetBlockDhcp) configSet(setPrefix strin func (block *interfaceLogicalBlockFamilyInet6BlockDhcpV6Client) configSet(setPrefix string) []string { setPrefix += "family inet6 dhcpv6-client " + configSet := []string{ setPrefix + "client-identifier duid-type " + block.ClientIdentifierDuidType.ValueString(), setPrefix + "client-type " + block.ClientType.ValueString(), @@ -2786,7 +2791,6 @@ func (rscData *interfaceLogicalData) read( if err != nil { return err } - rscData.Name = types.StringValue(name) rscData.fillID() if showConfig != junos.EmptyW { @@ -3288,7 +3292,6 @@ func (rscData *interfaceLogicalData) readSecurityZoneInboundTraffic( if err != nil { return err } - if showConfig != junos.EmptyW { for _, item := range strings.Split(showConfig, "\n") { if strings.Contains(item, junos.XMLStartTagConfigOut) { @@ -3345,6 +3348,7 @@ func (rscData *interfaceLogicalData) delOpts( _ context.Context, junSess *junos.Session, ) error { delPrefix := "delete interfaces " + rscData.Name.ValueString() + " " + configSet := []string{ delPrefix + "description", delPrefix + "disable", @@ -3372,7 +3376,7 @@ func (rscData *interfaceLogicalData) delRoutingInstance( _ context.Context, junSess *junos.Session, ) error { configSet := []string{ - junos.DelRoutingInstances + rscData.RoutingInstance.ValueString() + + junos.DeleteLS + junos.RoutingInstancesWS + rscData.RoutingInstance.ValueString() + " interface " + rscData.Name.ValueString(), } diff --git a/internal/providerfwk/resource_interface_physical.go b/internal/providerfwk/resource_interface_physical.go index 6736cdb5..8b8e6662 100644 --- a/internal/providerfwk/resource_interface_physical.go +++ b/internal/providerfwk/resource_interface_physical.go @@ -1770,6 +1770,7 @@ func (rscData *interfacePhysicalData) set( path.Path, error, ) { setPrefix := "set interfaces " + rscData.Name.ValueString() + " " + configSet := []string{ setPrefix, } @@ -1962,7 +1963,6 @@ func (block *interfacePhysicalBlockParentEtherOpts) configSet( error, // error ) { configSet := make([]string, 0) - switch { case strings.HasPrefix(interfaceName, "ae"): setPrefix += "aggregated-ether-options " @@ -2162,7 +2162,6 @@ func (rscData *interfacePhysicalData) read( if err != nil { return err } - rscData.Name = types.StringValue(name) rscData.fillID() if showConfig != junos.EmptyW { diff --git a/internal/providerfwk/resource_multichassis.go b/internal/providerfwk/resource_multichassis.go index 816d101d..8ccd64d0 100644 --- a/internal/providerfwk/resource_multichassis.go +++ b/internal/providerfwk/resource_multichassis.go @@ -264,6 +264,7 @@ func (rscData *multichassisData) set( path.Path, error, ) { setPrefix := "set multi-chassis " + configSet := []string{ setPrefix, } @@ -281,15 +282,12 @@ func (rscData *multichassisData) set( func (rscData *multichassisData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "multi-chassis" + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { rscData.fillID() for _, item := range strings.Split(showConfig, "\n") { diff --git a/internal/providerfwk/resource_multichassis_protection_peer.go b/internal/providerfwk/resource_multichassis_protection_peer.go index dbb2e8ef..72c22fce 100644 --- a/internal/providerfwk/resource_multichassis_protection_peer.go +++ b/internal/providerfwk/resource_multichassis_protection_peer.go @@ -287,6 +287,7 @@ func (rscData *multichassisProtectionPeerData) set( path.Path, error, ) { setPrefix := "set multi-chassis multi-chassis-protection " + rscData.IPAddress.ValueString() + " " + configSet := []string{ setPrefix, setPrefix + "interface " + rscData.Interface.ValueString(), @@ -302,9 +303,7 @@ func (rscData *multichassisProtectionPeerData) set( func (rscData *multichassisProtectionPeerData) read( _ context.Context, ipAddress string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "multi-chassis multi-chassis-protection " + ipAddress + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_oam_gretunnel_interface.go b/internal/providerfwk/resource_oam_gretunnel_interface.go index 97d1c64e..7e46566f 100644 --- a/internal/providerfwk/resource_oam_gretunnel_interface.go +++ b/internal/providerfwk/resource_oam_gretunnel_interface.go @@ -313,6 +313,7 @@ func (rscData *oamGretunnelInterfaceData) set( path.Path, error, ) { setPrefix := "set protocols oam gre-tunnel interface " + rscData.Name.ValueString() + " " + configSet := []string{ setPrefix, } @@ -331,9 +332,7 @@ func (rscData *oamGretunnelInterfaceData) set( func (rscData *oamGretunnelInterfaceData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "protocols oam gre-tunnel interface " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_ospf.go b/internal/providerfwk/resource_ospf.go index 8762ebaf..31f1482f 100644 --- a/internal/providerfwk/resource_ospf.go +++ b/internal/providerfwk/resource_ospf.go @@ -806,10 +806,9 @@ func (rscData *ospfData) set( ) { configSet := make([]string, 0) setPrefix := junos.SetLS - routingInstance := rscData.RoutingInstance.ValueString() if routingInstance != "" && routingInstance != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + routingInstance + " " + setPrefix += junos.RoutingInstancesWS + routingInstance + " " } ospfVersion := junos.OspfV2 if rscData.Version.ValueString() == "v3" { @@ -910,6 +909,7 @@ func (rscData *ospfData) set( func (block *ospfBlockDatabaseProtection) configSet(setPrefix string) []string { setPrefix += "database-protection " + configSet := []string{ setPrefix + "maximum-lsa " + utils.ConvI64toa(block.MaximumLsa.ValueInt64()), } @@ -978,6 +978,7 @@ func (block *ospfBlockGracefulRestart) configSet( func (block *ospfBlockOverload) configSet(setPrefix string) []string { setPrefix += "overload " + configSet := []string{ setPrefix, } @@ -1024,30 +1025,30 @@ func (block *ospfBlockSpfOptions) configSet(setPrefix string) []string { func (rscData *ospfData) read( _ context.Context, version, routingInstance string, junSess *junos.Session, -) ( - err error, -) { - var showConfig string +) error { ospfVersion := junos.OspfV2 if version == "v3" { ospfVersion = junos.OspfV3 } - if routingInstance == junos.DefaultW { - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols " + ospfVersion + junos.PipeDisplaySetRelative) - if err != nil { - return err - } + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " + } + showConfig, err := junSess.Command(showPrefix + + "protocols " + ospfVersion + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if version == "v3" { + rscData.Version = types.StringValue(version) } else { - showConfig, err = junSess.Command(junos.CmdShowConfig + junos.RoutingInstancesWS + routingInstance + " " + - "protocols " + ospfVersion + junos.PipeDisplaySetRelative) - if err != nil { - return err - } + rscData.Version = types.StringValue("v2") + } + if routingInstance == "" { + rscData.RoutingInstance = types.StringValue(junos.DefaultW) + } else { + rscData.RoutingInstance = types.StringValue(routingInstance) } - - rscData.Version = types.StringValue(version) - rscData.RoutingInstance = types.StringValue(routingInstance) rscData.fillID() if showConfig != junos.EmptyW { for _, item := range strings.Split(showConfig, "\n") { @@ -1259,7 +1260,7 @@ func (rscData *ospfData) del( } delPrefix := junos.DeleteLS if v := rscData.RoutingInstance.ValueString(); v != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + v + " " + delPrefix += junos.RoutingInstancesWS + v + " " } delPrefix += "protocols " + ospfVersion + " " @@ -1284,6 +1285,7 @@ func (rscData *ospfData) del( "sham-link", "spf-options", } + configSet := make([]string, len(listLinesToDelete)) for k, line := range listLinesToDelete { configSet[k] = delPrefix + line diff --git a/internal/providerfwk/resource_ospf_area.go b/internal/providerfwk/resource_ospf_area.go index c004a06f..fb47c516 100644 --- a/internal/providerfwk/resource_ospf_area.go +++ b/internal/providerfwk/resource_ospf_area.go @@ -1697,41 +1697,28 @@ func (rsc *ospfArea) ImportState( func checkOspfAreaExists( _ context.Context, areaID, version, realm, routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { - var showConfig string - ospfVersion := junos.OspfV2 - if version == "v3" { - ospfVersion = junos.OspfV3 - } else if realm != "" { - return false, errors.New("realm can't set if version != v3") + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - switch { - case (routingInstance == junos.DefaultW || routingInstance == "") && realm == "": - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols " + ospfVersion + " area " + areaID + junos.PipeDisplaySet) - if err != nil { - return false, err - } - case (routingInstance == junos.DefaultW || routingInstance == "") && realm != "": - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols " + ospfVersion + " realm " + realm + " area " + areaID + junos.PipeDisplaySet) - if err != nil { - return false, err - } - case realm != "": - showConfig, err = junSess.Command(junos.CmdShowConfig + junos.RoutingInstancesWS + routingInstance + " " + - "protocols " + ospfVersion + " realm " + realm + " area " + areaID + junos.PipeDisplaySet) - if err != nil { - return false, err - } - default: - showConfig, err = junSess.Command(junos.CmdShowConfig + junos.RoutingInstancesWS + routingInstance + " " + - "protocols " + ospfVersion + " area " + areaID + junos.PipeDisplaySet) - if err != nil { - return false, err + if version == "v3" { + showPrefix += "protocols " + junos.OspfV3 + " " + } else { + showPrefix += "protocols " + junos.OspfV2 + " " + if realm != "" { + return false, errors.New("realm can't set if version != v3") } } + if realm != "" { + showPrefix += "realm " + realm + " " + } + showConfig, err := junSess.Command(showPrefix + + "area " + areaID + junos.PipeDisplaySet) + if err != nil { + return false, err + } if showConfig == junos.EmptyW { return false, nil } @@ -1772,15 +1759,16 @@ func (rscData *ospfAreaData) set( configSet := make([]string, 0) setPrefix := junos.SetLS if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + v + " " + setPrefix += junos.RoutingInstancesWS + v + " " } - ospfVersion := junos.OspfV2 if rscData.Version.ValueString() == "v3" { - ospfVersion = junos.OspfV3 - } else if rscData.Realm.ValueString() != "" { - return path.Root("realm"), errors.New("realm can't set if version != v3") + setPrefix += "protocols " + junos.OspfV3 + " " + } else { + setPrefix += "protocols " + junos.OspfV2 + " " + if rscData.Realm.ValueString() != "" { + return path.Root("realm"), errors.New("realm can't set if version != v3") + } } - setPrefix += "protocols " + ospfVersion + " " if v := rscData.Realm.ValueString(); v != "" { setPrefix += "realm " + v + " " } @@ -1876,6 +1864,7 @@ func (block *ospfAreaBlockInterface) configSet( error, // error ) { setPrefix += "interface " + block.Name.ValueString() + " " + configSet := []string{ setPrefix, } @@ -2135,6 +2124,7 @@ func (block *ospfAreaBlockInterfaceBlockBfdLivenessDetection) configSet(setPrefi func (block *ospfAreaBlockAreaRange) configSet(setPrefix string) []string { setPrefix += "area-range " + block.Range.ValueString() + " " + configSet := []string{ setPrefix, } @@ -2161,6 +2151,7 @@ func (block *ospfAreaBlockNssa) configSet( error, // error ) { setPrefix += "nssa " + configSet := []string{ setPrefix, } @@ -2208,6 +2199,7 @@ func (block *ospfAreaBlockVirtualLink) configSet(setPrefix string) []string { " neighbor-id " + block.NeighborID.ValueString() + " transit-area " + block.TransitArea.ValueString() + " " + configSet := []string{ setPrefix, } @@ -2250,43 +2242,27 @@ func (block *ospfAreaBlockVirtualLink) configSet(setPrefix string) []string { func (rscData *ospfAreaData) read( _ context.Context, areaID, version, realm, routingInstance string, junSess *junos.Session, -) ( - err error, -) { - var showConfig string - ospfVersion := junos.OspfV2 - if version == "v3" { - ospfVersion = junos.OspfV3 - } else if realm != "" { - return errors.New("realm can't set if version != v3") +) error { + showPrefix := junos.CmdShowConfig + if routingInstance != "" && routingInstance != junos.DefaultW { + showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - switch { - case (routingInstance == junos.DefaultW || routingInstance == "") && realm == "": - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols " + ospfVersion + " area " + areaID + junos.PipeDisplaySetRelative) - if err != nil { - return err - } - case (routingInstance == junos.DefaultW || routingInstance == "") && realm != "": - showConfig, err = junSess.Command(junos.CmdShowConfig + - "protocols " + ospfVersion + " realm " + realm + " area " + areaID + junos.PipeDisplaySetRelative) - if err != nil { - return err - } - case realm != "": - showConfig, err = junSess.Command(junos.CmdShowConfig + junos.RoutingInstancesWS + routingInstance + " " + - "protocols " + ospfVersion + " realm " + realm + " area " + areaID + junos.PipeDisplaySetRelative) - if err != nil { - return err - } - default: - showConfig, err = junSess.Command(junos.CmdShowConfig + junos.RoutingInstancesWS + routingInstance + " " + - "protocols " + ospfVersion + " area " + areaID + junos.PipeDisplaySetRelative) - if err != nil { - return err + if version == "v3" { + showPrefix += "protocols " + junos.OspfV3 + " " + } else { + showPrefix += "protocols " + junos.OspfV2 + " " + if realm != "" { + return errors.New("realm can't set if version != v3") } } - + if realm != "" { + showPrefix += "realm " + realm + " " + } + showConfig, err := junSess.Command(showPrefix + + "area " + areaID + junos.PipeDisplaySetRelative) + if err != nil { + return err + } if showConfig != junos.EmptyW { rscData.AreaID = types.StringValue(areaID) if version == "v3" { @@ -2707,31 +2683,24 @@ func (block *ospfAreaBlockNssa) read(itemTrim string) (err error) { func (rscData *ospfAreaData) del( _ context.Context, junSess *junos.Session, ) error { - configSet := make([]string, 0, 1) - ospfVersion := junos.OspfV2 + delPrefix := junos.DeleteLS + if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW { + delPrefix += junos.RoutingInstancesWS + v + " " + } if rscData.Version.ValueString() == "v3" { - ospfVersion = junos.OspfV3 - } else if rscData.Realm.ValueString() != "" { - return errors.New("realm can't set if version != v3") + delPrefix += "protocols " + junos.OspfV3 + " " + } else { + delPrefix += "protocols " + junos.OspfV2 + " " + if rscData.Realm.ValueString() != "" { + return errors.New("realm can't set if version != v3") + } } - routingInstance := junos.DefaultW - if v := rscData.RoutingInstance.ValueString(); v != "" { - routingInstance = v + if v := rscData.Realm.ValueString(); v != "" { + delPrefix += "realm " + v + " " } - realm := rscData.Realm.ValueString() - switch { - case (routingInstance == junos.DefaultW || routingInstance == "") && realm == "": - configSet = append(configSet, junos.DeleteW+ - " protocols "+ospfVersion+" area "+rscData.AreaID.ValueString()) - case (routingInstance == junos.DefaultW || routingInstance == "") && realm != "": - configSet = append(configSet, junos.DeleteW+ - " protocols "+ospfVersion+" realm "+realm+" area "+rscData.AreaID.ValueString()) - case realm != "": - configSet = append(configSet, junos.DelRoutingInstances+routingInstance+ - " protocols "+ospfVersion+" realm "+realm+" area "+rscData.AreaID.ValueString()) - default: - configSet = append(configSet, junos.DelRoutingInstances+routingInstance+ - " protocols "+ospfVersion+" area "+rscData.AreaID.ValueString()) + + configSet := []string{ + delPrefix + "area " + rscData.AreaID.ValueString(), } return junSess.ConfigSet(configSet) diff --git a/internal/providerfwk/resource_policyoptions_as_path.go b/internal/providerfwk/resource_policyoptions_as_path.go index 9a4b809f..8a52df50 100644 --- a/internal/providerfwk/resource_policyoptions_as_path.go +++ b/internal/providerfwk/resource_policyoptions_as_path.go @@ -318,9 +318,7 @@ func (rscData *policyoptionsASPathData) set( func (rscData *policyoptionsASPathData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "policy-options as-path \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_policyoptions_as_path_group.go b/internal/providerfwk/resource_policyoptions_as_path_group.go index f6b3c119..930647c5 100644 --- a/internal/providerfwk/resource_policyoptions_as_path_group.go +++ b/internal/providerfwk/resource_policyoptions_as_path_group.go @@ -385,9 +385,7 @@ func (rscData *policyoptionsASPathGroupData) set( func (rscData *policyoptionsASPathGroupData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "policy-options as-path-group \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_policyoptions_community.go b/internal/providerfwk/resource_policyoptions_community.go index 3e1c57be..1599b9bd 100644 --- a/internal/providerfwk/resource_policyoptions_community.go +++ b/internal/providerfwk/resource_policyoptions_community.go @@ -351,9 +351,7 @@ func (rscData *policyoptionsCommunityData) set( func (rscData *policyoptionsCommunityData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "policy-options community \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_policyoptions_policy_statement.go b/internal/providerfwk/resource_policyoptions_policy_statement.go index c8d8f825..e0301523 100644 --- a/internal/providerfwk/resource_policyoptions_policy_statement.go +++ b/internal/providerfwk/resource_policyoptions_policy_statement.go @@ -1804,7 +1804,7 @@ func (rsc *policyoptionsPolicyStatement) ImportState( func checkPolicyoptionsPolicyStatementExists( _ context.Context, name string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showConfig, err := junSess.Command(junos.CmdShowConfig + "policy-options policy-statement \"" + name + "\"" + junos.PipeDisplaySet) @@ -2236,9 +2236,7 @@ func (block *policyoptionsPolicyStatementBlockThen) configSet( func (rscData *policyoptionsPolicyStatementData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "policy-options policy-statement \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_policyoptions_prefix_list.go b/internal/providerfwk/resource_policyoptions_prefix_list.go index a564606c..fa004294 100644 --- a/internal/providerfwk/resource_policyoptions_prefix_list.go +++ b/internal/providerfwk/resource_policyoptions_prefix_list.go @@ -317,9 +317,7 @@ func (rscData *policyoptionsPrefixListData) set( func (rscData *policyoptionsPrefixListData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "policy-options prefix-list \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_routing_instance.go b/internal/providerfwk/resource_routing_instance.go index c0da3dbc..a187d131 100644 --- a/internal/providerfwk/resource_routing_instance.go +++ b/internal/providerfwk/resource_routing_instance.go @@ -536,7 +536,7 @@ func (rscData *routingInstanceData) set( path.Path, error, ) { configSet := make([]string, 0) - setPrefix := junos.SetRoutingInstances + rscData.Name.ValueString() + " " + setPrefix := junos.SetLS + junos.RoutingInstancesWS + rscData.Name.ValueString() + " " if rscData.ConfigureTypeSingly.ValueBool() { if rscData.Type.ValueString() != "" { @@ -595,9 +595,7 @@ func (rscData *routingInstanceData) set( func (rscData *routingInstanceData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + junos.RoutingInstancesWS + name + junos.PipeDisplaySetRelative) if err != nil { @@ -661,7 +659,7 @@ func (rscData *routingInstanceData) delOpts( _ context.Context, junSess *junos.Session, ) error { configSet := make([]string, 0) - setPrefix := junos.DelRoutingInstances + rscData.Name.ValueString() + " " + setPrefix := junos.DeleteLS + junos.RoutingInstancesWS + rscData.Name.ValueString() + " " configSet = append(configSet, setPrefix+"description", setPrefix+junos.RoutingOptionsWS+"autonomous-system", @@ -689,7 +687,7 @@ func (rscData *routingInstanceData) del( _ context.Context, junSess *junos.Session, ) error { configSet := []string{ - junos.DelRoutingInstances + rscData.Name.ValueString(), + junos.DeleteLS + junos.RoutingInstancesWS + rscData.Name.ValueString(), } return junSess.ConfigSet(configSet) diff --git a/internal/providerfwk/resource_security.go b/internal/providerfwk/resource_security.go index 0b08a0c3..8b4196c0 100644 --- a/internal/providerfwk/resource_security.go +++ b/internal/providerfwk/resource_security.go @@ -2094,8 +2094,8 @@ func (rscData *securityData) set( ) ( path.Path, error, ) { - setPrefix := "set security " configSet := make([]string, 0) + setPrefix := "set security " if rscData.Alg != nil { if rscData.Alg.isEmpty() { @@ -2217,8 +2217,8 @@ func (rscData *securityData) set( } func (block *securityBlockAlg) configSet() []string { - setPrefix := "set security alg " configSet := make([]string, 0) + setPrefix := "set security alg " if block.DNSDisable.ValueBool() { configSet = append(configSet, setPrefix+"dns disable") @@ -2271,8 +2271,8 @@ func (block *securityBlockFlow) configSet() ( path.Path, // pathErr error, // error ) { - setPrefix := "set security flow " configSet := make([]string, 0) + setPrefix := "set security flow " if block.AdvancedOptions != nil { if block.AdvancedOptions.isEmpty() { @@ -2449,8 +2449,8 @@ func (block *securityBlockFlow) configSet() ( } func (block *securityBlockForwardingOptions) configSet() []string { - setPrefix := "set security forwarding-options " configSet := make([]string, 0) + setPrefix := "set security forwarding-options " if v := block.Inet6Mode.ValueString(); v != "" { configSet = append(configSet, setPrefix+"family inet6 mode "+v) @@ -2466,8 +2466,8 @@ func (block *securityBlockForwardingOptions) configSet() []string { } func (block *securityBlockIdpSecurityPackage) configSet() []string { - setPrefix := "set security idp security-package " configSet := make([]string, 0) + setPrefix := "set security idp security-package " if block.AutomaticEnable.ValueBool() { configSet = append(configSet, setPrefix+"automatic enable") @@ -2496,8 +2496,8 @@ func (block *securityBlockIdpSecurityPackage) configSet() []string { } func (block *securityBlockIdpSensorConfiguration) configSet() []string { - setPrefix := "set security idp sensor-configuration " configSet := make([]string, 0) + setPrefix := "set security idp sensor-configuration " if !block.LogCacheSize.IsNull() { configSet = append(configSet, setPrefix+"log cache-size "+ @@ -2563,8 +2563,8 @@ func (block *securityBlockIkeTraceoptions) configSet() ( path.Path, // pathErr error, // error ) { - setPrefix := "set security ike traceoptions " configSet := make([]string, 0) + setPrefix := "set security ike traceoptions " if block.File != nil { if block.File.isEmpty() { @@ -2618,8 +2618,8 @@ func (block *securityBlockLog) configSet() ( path.Path, // pathErr error, // error ) { - setPrefix := "set security log " configSet := make([]string, 0) + setPrefix := "set security log " if block.Disable.ValueBool() { configSet = append(configSet, setPrefix+"disable") @@ -2697,8 +2697,8 @@ func (block *securityBlockLog) configSet() ( } func (block *securityBlockNatSource) configSet() []string { - setPrefix := "set security nat source " configSet := make([]string, 0) + setPrefix := "set security nat source " if block.AddressPersistent.ValueBool() { configSet = append(configSet, setPrefix+"address-persistent") @@ -2749,8 +2749,8 @@ func (block *securityBlockNatSource) configSet() []string { } func (block *securityBlockUserIdentificationAuthSource) configSet() []string { - setPrefix := "set security user-identification authentication-source " configSet := make([]string, 0) + setPrefix := "set security user-identification authentication-source " if !block.ADAuthPriority.IsNull() { configSet = append(configSet, setPrefix+"active-directory-authentication-table priority "+ @@ -2777,8 +2777,8 @@ func (block *securityBlockUserIdentificationAuthSource) configSet() []string { } func (block *securityBlockUtm) configSet() []string { - setPrefix := "set security utm " configSet := make([]string, 0) + setPrefix := "set security utm " if v := block.FeatureProfileWebFilteringType.ValueString(); v != "" { configSet = append(configSet, setPrefix+"feature-profile web-filtering type "+v) @@ -2807,9 +2807,7 @@ func (block *securityBlockUtm) configSet() []string { func (rscData *securityData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_address_book.go b/internal/providerfwk/resource_security_address_book.go index c6c93d16..da88bce3 100644 --- a/internal/providerfwk/resource_security_address_book.go +++ b/internal/providerfwk/resource_security_address_book.go @@ -832,9 +832,7 @@ func (rscData *securityAddressBookData) set( func (rscData *securityAddressBookData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security address-book \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_global_policy.go b/internal/providerfwk/resource_security_global_policy.go index dc399b59..c68100eb 100644 --- a/internal/providerfwk/resource_security_global_policy.go +++ b/internal/providerfwk/resource_security_global_policy.go @@ -691,9 +691,7 @@ func (rscData *securityGlobalPolicyData) set( func (rscData *securityGlobalPolicyData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security policies global" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_ike_gateway.go b/internal/providerfwk/resource_security_ike_gateway.go index da9a42ab..d9bd2279 100644 --- a/internal/providerfwk/resource_security_ike_gateway.go +++ b/internal/providerfwk/resource_security_ike_gateway.go @@ -565,7 +565,7 @@ func (rsc *securityIkeGateway) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("aaa").AtName("access_profile"), tfdiag.ConflictConfigErrSummary, - "only one of access_profile or client_username/client_password must be specifiedin aaa block ", + "only one of access_profile or client_username/client_password must be specifiedin aaa block", ) } if config.Aaa.ClientUsername.IsNull() && !config.Aaa.ClientPassword.IsNull() { @@ -954,9 +954,7 @@ func (rscData *securityIkeGatewayData) set( func (rscData *securityIkeGatewayData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security ike gateway \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_ike_policy.go b/internal/providerfwk/resource_security_ike_policy.go index f70a23aa..345f5f43 100644 --- a/internal/providerfwk/resource_security_ike_policy.go +++ b/internal/providerfwk/resource_security_ike_policy.go @@ -431,9 +431,7 @@ func (rscData *securityIkePolicyData) set( func (rscData *securityIkePolicyData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security ike policy \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_ike_proposal.go b/internal/providerfwk/resource_security_ike_proposal.go index c65b650d..a035dd68 100644 --- a/internal/providerfwk/resource_security_ike_proposal.go +++ b/internal/providerfwk/resource_security_ike_proposal.go @@ -361,9 +361,7 @@ func (rscData *securityIkeProposalData) set( func (rscData *securityIkeProposalData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security ike proposal \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_ipsec_policy.go b/internal/providerfwk/resource_security_ipsec_policy.go index d7612673..c96a9e4d 100644 --- a/internal/providerfwk/resource_security_ipsec_policy.go +++ b/internal/providerfwk/resource_security_ipsec_policy.go @@ -373,9 +373,7 @@ func (rscData *securityIpsecPolicyData) set( func (rscData *securityIpsecPolicyData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security ipsec policy " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_ipsec_proposal.go b/internal/providerfwk/resource_security_ipsec_proposal.go index 0175ea7b..6cfd629a 100644 --- a/internal/providerfwk/resource_security_ipsec_proposal.go +++ b/internal/providerfwk/resource_security_ipsec_proposal.go @@ -358,9 +358,7 @@ func (rscData *securityIpsecProposalData) set( func (rscData *securityIpsecProposalData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security ipsec proposal " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_ipsec_vpn.go b/internal/providerfwk/resource_security_ipsec_vpn.go index 8cff07d2..37eb09e4 100644 --- a/internal/providerfwk/resource_security_ipsec_vpn.go +++ b/internal/providerfwk/resource_security_ipsec_vpn.go @@ -1010,9 +1010,7 @@ func (rscData *securityIpsecVpnData) set( func (rscData *securityIpsecVpnData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security ipsec vpn \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_nat_destination_pool.go b/internal/providerfwk/resource_security_nat_destination_pool.go index 88cb76ac..024a39d9 100644 --- a/internal/providerfwk/resource_security_nat_destination_pool.go +++ b/internal/providerfwk/resource_security_nat_destination_pool.go @@ -341,6 +341,7 @@ func (rscData *securityNatDestinationPoolData) set( path.Path, error, ) { setPrefix := "set security nat destination pool " + rscData.Name.ValueString() + " " + configSet := []string{ setPrefix + "address " + rscData.Address.ValueString(), } diff --git a/internal/providerfwk/resource_security_nat_static.go b/internal/providerfwk/resource_security_nat_static.go index 1b782ce1..b43d4149 100644 --- a/internal/providerfwk/resource_security_nat_static.go +++ b/internal/providerfwk/resource_security_nat_static.go @@ -898,9 +898,7 @@ func (rscData *securityNatStaticData) set( func (rscData *securityNatStaticData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security nat static rule-set " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_nat_static_rule.go b/internal/providerfwk/resource_security_nat_static_rule.go index 045fa464..a251eed7 100644 --- a/internal/providerfwk/resource_security_nat_static_rule.go +++ b/internal/providerfwk/resource_security_nat_static_rule.go @@ -589,6 +589,7 @@ func (rscData *securityNatStaticRuleData) set( setPrefix := "set security nat static " + "rule-set " + rscData.RuleSet.ValueString() + " rule " + rscData.Name.ValueString() + " " + configSet := []string{ setPrefix, } diff --git a/internal/providerfwk/resource_security_policy.go b/internal/providerfwk/resource_security_policy.go index 4c1debb4..601e0c8f 100644 --- a/internal/providerfwk/resource_security_policy.go +++ b/internal/providerfwk/resource_security_policy.go @@ -945,9 +945,7 @@ func (block *securityPolicyBlockPolicyBlockPermitApplicationServices) configSet( func (rscData *securityPolicyData) read( _ context.Context, fromZone, toZone string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security policies from-zone " + fromZone + " to-zone " + toZone + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_policy_tunnel_pair_policy.go b/internal/providerfwk/resource_security_policy_tunnel_pair_policy.go index 3831bd32..221b6353 100644 --- a/internal/providerfwk/resource_security_policy_tunnel_pair_policy.go +++ b/internal/providerfwk/resource_security_policy_tunnel_pair_policy.go @@ -397,9 +397,7 @@ func (rscData *securityPolicyTunnelPairPolicyData) set( func (rscData *securityPolicyTunnelPairPolicyData) read( _ context.Context, zoneA, policyAtoB, zoneB, policyBtoA string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security policies from-zone " + zoneA + " to-zone " + zoneB + " policy " + policyAtoB + " then permit tunnel pair-policy" + junos.PipeDisplaySet) diff --git a/internal/providerfwk/resource_security_zone.go b/internal/providerfwk/resource_security_zone.go index f8d45f8b..cf08bc73 100644 --- a/internal/providerfwk/resource_security_zone.go +++ b/internal/providerfwk/resource_security_zone.go @@ -995,9 +995,7 @@ func (rscData *securityZoneData) set( func (rscData *securityZoneData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security zones security-zone " + name + junos.PipeDisplaySetRelative) if err != nil { @@ -1155,6 +1153,7 @@ func (rscData *securityZoneData) delOpts( listLinesToDelete = append(listLinesToDelete, "address-book") } delPrefix := "delete security zones security-zone " + rscData.Name.ValueString() + " " + configSet := make([]string, len(listLinesToDelete)) for k, line := range listLinesToDelete { configSet[k] = delPrefix + line diff --git a/internal/providerfwk/resource_security_zone_book_address.go b/internal/providerfwk/resource_security_zone_book_address.go index 0428e437..28c424fe 100644 --- a/internal/providerfwk/resource_security_zone_book_address.go +++ b/internal/providerfwk/resource_security_zone_book_address.go @@ -518,9 +518,7 @@ func (rscData *securityZoneBookAddressData) set( func (rscData *securityZoneBookAddressData) read( _ context.Context, zone, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security zones security-zone " + zone + " address-book address " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_security_zone_book_address_set.go b/internal/providerfwk/resource_security_zone_book_address_set.go index df934d47..255df734 100644 --- a/internal/providerfwk/resource_security_zone_book_address_set.go +++ b/internal/providerfwk/resource_security_zone_book_address_set.go @@ -411,9 +411,7 @@ func (rscData *securityZoneBookAddressSetData) set( func (rscData *securityZoneBookAddressSetData) read( _ context.Context, zone, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "security zones security-zone " + zone + " address-book address-set " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_services_flowmonitoring_v9_template.go b/internal/providerfwk/resource_services_flowmonitoring_v9_template.go index 42fe06bf..59492429 100644 --- a/internal/providerfwk/resource_services_flowmonitoring_v9_template.go +++ b/internal/providerfwk/resource_services_flowmonitoring_v9_template.go @@ -624,9 +624,7 @@ func (rscData *servicesFlowMonitoringV9TemplateData) set( func (rscData *servicesFlowMonitoringV9TemplateData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "services flow-monitoring version9 template \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_services_flowmonitoring_vipfix_template.go b/internal/providerfwk/resource_services_flowmonitoring_vipfix_template.go index e22c8101..774f3405 100644 --- a/internal/providerfwk/resource_services_flowmonitoring_vipfix_template.go +++ b/internal/providerfwk/resource_services_flowmonitoring_vipfix_template.go @@ -620,9 +620,7 @@ func (rscData *servicesFlowMonitoringVIPFixTemplateData) set( func (rscData *servicesFlowMonitoringVIPFixTemplateData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "services flow-monitoring version-ipfix template \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_snmp.go b/internal/providerfwk/resource_snmp.go index 44613a76..76b626e4 100644 --- a/internal/providerfwk/resource_snmp.go +++ b/internal/providerfwk/resource_snmp.go @@ -482,8 +482,8 @@ func (rscData *snmpData) set( ) ( path.Path, error, ) { - setPrefix := "set snmp " configSet := make([]string, 0) + setPrefix := "set snmp " if rscData.ARP.ValueBool() { configSet = append(configSet, setPrefix+"arp") @@ -561,9 +561,7 @@ func (rscData *snmpData) set( func (rscData *snmpData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp" + junos.PipeDisplaySetRelative) if err != nil { @@ -662,6 +660,7 @@ func (rscData *snmpData) del( _ context.Context, junSess *junos.Session, ) error { delPrefix := "delete snmp " + configSet := []string{ delPrefix + "arp", delPrefix + "contact", diff --git a/internal/providerfwk/resource_snmp_clientlist.go b/internal/providerfwk/resource_snmp_clientlist.go index 24d182dd..d4186f15 100644 --- a/internal/providerfwk/resource_snmp_clientlist.go +++ b/internal/providerfwk/resource_snmp_clientlist.go @@ -288,6 +288,7 @@ func (rscData *snmpClientlistData) set( path.Path, error, ) { setPrefix := "set snmp client-list \"" + rscData.Name.ValueString() + "\" " + configSet := []string{ setPrefix, } @@ -301,9 +302,7 @@ func (rscData *snmpClientlistData) set( func (rscData *snmpClientlistData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp client-list \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_snmp_community.go b/internal/providerfwk/resource_snmp_community.go index cfeda98e..a18463a7 100644 --- a/internal/providerfwk/resource_snmp_community.go +++ b/internal/providerfwk/resource_snmp_community.go @@ -448,8 +448,8 @@ func (rscData *snmpCommunityData) set( ) ( path.Path, error, ) { - setPrefix := "set snmp community \"" + rscData.Name.ValueString() + "\" " configSet := make([]string, 0) + setPrefix := "set snmp community \"" + rscData.Name.ValueString() + "\" " if rscData.AuthorizationReadOnly.ValueBool() { configSet = append(configSet, setPrefix+"authorization read-only") @@ -498,9 +498,7 @@ func (rscData *snmpCommunityData) set( func (rscData *snmpCommunityData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp community \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_snmp_v3_community.go b/internal/providerfwk/resource_snmp_v3_community.go index 322f46c2..b96c650f 100644 --- a/internal/providerfwk/resource_snmp_v3_community.go +++ b/internal/providerfwk/resource_snmp_v3_community.go @@ -313,6 +313,7 @@ func (rscData *snmpV3CommunityData) set( path.Path, error, ) { setPrefix := "set snmp v3 snmp-community \"" + rscData.CommunityIndex.ValueString() + "\" " + configSet := []string{ setPrefix + "security-name \"" + rscData.SecurityName.ValueString() + "\"", } @@ -332,9 +333,7 @@ func (rscData *snmpV3CommunityData) set( func (rscData *snmpV3CommunityData) read( _ context.Context, communityIndex string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp v3 snmp-community \"" + communityIndex + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_snmp_v3_usm_user.go b/internal/providerfwk/resource_snmp_v3_usm_user.go index 887d420f..96d1c70e 100644 --- a/internal/providerfwk/resource_snmp_v3_usm_user.go +++ b/internal/providerfwk/resource_snmp_v3_usm_user.go @@ -261,7 +261,7 @@ func (rsc *snmpV3UsmUser) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("authentication_type"), tfdiag.MissingConfigErrSummary, - "authentication_key or authentication_password must be specified when authentication_type != authentication-none ", + "authentication_key or authentication_password must be specified when authentication_type != authentication-none", ) } } else if config.AuthenticationType.IsNull() || config.AuthenticationType.ValueString() == "authentication-none" { @@ -294,7 +294,7 @@ func (rsc *snmpV3UsmUser) ValidateConfig( resp.Diagnostics.AddAttributeError( path.Root("privacy_type"), tfdiag.MissingConfigErrSummary, - "privacy_key or privacy_password must be specified when privacy_type != privacy-none ", + "privacy_key or privacy_password must be specified when privacy_type != privacy-none", ) } } else if config.PrivacyType.IsNull() || config.PrivacyType.ValueString() == "privacy-none" { @@ -586,41 +586,36 @@ func checkSnmpV3UsmUserExists( ) ( bool, error, ) { + showPrefix := junos.CmdShowConfig + "snmp v3 usm " switch engineType { case "local": - showConfig, err := junSess.Command(junos.CmdShowConfig + - "snmp v3 usm local-engine user \"" + name + "\"" + junos.PipeDisplaySet) - if err != nil { - return false, err - } - if showConfig == junos.EmptyW { - return false, nil - } + showPrefix += "local-engine " case "remote": - showConfig, err := junSess.Command(junos.CmdShowConfig + - "snmp v3 usm remote-engine \"" + engineID + "\" user \"" + name + "\"" + junos.PipeDisplaySet) - if err != nil { - return false, err - } - if showConfig == junos.EmptyW { - return false, nil - } + showPrefix += "remote-engine \"" + engineID + "\" " default: return false, fmt.Errorf("can't check config with engine_type %q", engineType) } + showConfig, err := junSess.Command(showPrefix + + "user \"" + name + "\"" + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } return true, nil } func (rscData *snmpV3UsmUserData) fillID() { - switch rscData.EngineType.ValueString() { - case "remote": + switch v := rscData.EngineType.ValueString(); v { + case "local": rscData.ID = types.StringValue( - "remote" + junos.IDSeparator + rscData.EngineID.ValueString() + junos.IDSeparator + rscData.Name.ValueString(), + v + junos.IDSeparator + rscData.Name.ValueString(), ) - case "local": + case "remote": rscData.ID = types.StringValue( - "local" + junos.IDSeparator + rscData.Name.ValueString(), + v + junos.IDSeparator + rscData.EngineID.ValueString() + junos.IDSeparator + rscData.Name.ValueString(), ) } } @@ -634,16 +629,17 @@ func (rscData *snmpV3UsmUserData) set( ) ( path.Path, error, ) { - setPrefix := "set snmp v3 usm " + - "local-engine user \"" + rscData.Name.ValueString() + "\" " - if v := rscData.EngineType.ValueString(); v == "remote" { - setPrefix = "set snmp v3 usm " + - "remote-engine \"" + rscData.EngineID.ValueString() + "\" " + - "user \"" + rscData.Name.ValueString() + "\" " - } else if v != "local" { + configSet := make([]string, 0) + setPrefix := "set snmp v3 usm " + switch v := rscData.EngineType.ValueString(); v { + case "local": + setPrefix += "local-engine " + case "remote": + setPrefix += "remote-engine \"" + rscData.EngineID.ValueString() + "\" " + default: return path.Root("engine_type"), fmt.Errorf("can't set config with engine_type %q", v) } - configSet := make([]string, 0) + setPrefix += "user \"" + rscData.Name.ValueString() + "\" " if authenticationType := rscData.AuthenticationType.ValueString(); authenticationType != "authentication-none" { if rscData.AuthenticationKey.ValueString() == "" && rscData.AuthenticationPassword.ValueString() == "" { @@ -700,18 +696,19 @@ func (rscData *snmpV3UsmUserData) set( func (rscData *snmpV3UsmUserData) read( _ context.Context, name, engineType, engineID string, junSess *junos.Session, -) ( - err error, -) { - showCommand := junos.CmdShowConfig + - "snmp v3 usm local-engine user \"" + name + "\"" + junos.PipeDisplaySetRelative - if engineType == "remote" { - showCommand = junos.CmdShowConfig + - "snmp v3 usm remote-engine \"" + engineID + "\" user \"" + name + "\"" + junos.PipeDisplaySetRelative - } else { - engineType = "local" +) error { + showPrefix := junos.CmdShowConfig + "snmp v3 usm " + switch engineType { + case "remote": + showPrefix += "remote-engine \"" + engineID + "\" " + default: + if engineType != "local" { + engineType = "local" + } + showPrefix += "local-engine " } - showConfig, err := junSess.Command(showCommand) + showConfig, err := junSess.Command(showPrefix + + "user \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { return err } @@ -759,14 +756,18 @@ func (rscData *snmpV3UsmUserData) read( func (rscData *snmpV3UsmUserData) del( _ context.Context, junSess *junos.Session, ) error { - configSet := []string{ - "delete snmp v3 usm " + - "local-engine user \"" + rscData.Name.ValueString() + "\"", + delPrefix := junos.DeleteLS + "snmp v3 usm " + switch v := rscData.EngineType.ValueString(); v { + case "local": + delPrefix += "local-engine " + case "remote": + delPrefix += "remote-engine \"" + rscData.EngineID.ValueString() + "\" " + default: + return fmt.Errorf("can't del config with engine_type %q", v) } - if rscData.EngineType.ValueString() == "remote" { - configSet[0] = "delete snmp v3 usm " + - "remote-engine \"" + rscData.EngineID.ValueString() + "\" " + - "user \"" + rscData.Name.ValueString() + "\"" + + configSet := []string{ + delPrefix + "user \"" + rscData.Name.ValueString() + "\"", } return junSess.ConfigSet(configSet) diff --git a/internal/providerfwk/resource_snmp_v3_vacm_accessgroup.go b/internal/providerfwk/resource_snmp_v3_vacm_accessgroup.go index 7d1b87ee..10d66b89 100644 --- a/internal/providerfwk/resource_snmp_v3_vacm_accessgroup.go +++ b/internal/providerfwk/resource_snmp_v3_vacm_accessgroup.go @@ -564,8 +564,8 @@ func (rscData *snmpV3VacmAccessgroupData) set( ) ( path.Path, error, ) { - setPrefix := "set snmp v3 vacm access group \"" + rscData.Name.ValueString() + "\" " configSet := make([]string, 0) + setPrefix := "set snmp v3 vacm access group \"" + rscData.Name.ValueString() + "\" " defaultContextPrefixModelLevel := make(map[string]struct{}) for _, block := range rscData.DefaultContextPrefix { @@ -642,9 +642,7 @@ func (rscData *snmpV3VacmAccessgroupData) set( func (rscData *snmpV3VacmAccessgroupData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp v3 vacm access group \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_snmp_v3_vacm_securitytogroup.go b/internal/providerfwk/resource_snmp_v3_vacm_securitytogroup.go index ecd86c2d..37e996f0 100644 --- a/internal/providerfwk/resource_snmp_v3_vacm_securitytogroup.go +++ b/internal/providerfwk/resource_snmp_v3_vacm_securitytogroup.go @@ -333,9 +333,7 @@ func (rscData *snmpV3VacmSecuritytogroupData) set( func (rscData *snmpV3VacmSecuritytogroupData) read( _ context.Context, model, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp v3 vacm security-to-group security-model " + model + " security-name \"" + name + "\"" + junos.PipeDisplaySetRelative) diff --git a/internal/providerfwk/resource_snmp_view.go b/internal/providerfwk/resource_snmp_view.go index 17b8d44c..c67ee36e 100644 --- a/internal/providerfwk/resource_snmp_view.go +++ b/internal/providerfwk/resource_snmp_view.go @@ -329,8 +329,8 @@ func (rscData *snmpViewData) set( ) ( path.Path, error, ) { - setPrefix := "set snmp view \"" + rscData.Name.ValueString() + "\" " configSet := make([]string, 0) + setPrefix := "set snmp view \"" + rscData.Name.ValueString() + "\" " for _, v := range rscData.OIDInclude { configSet = append(configSet, setPrefix+"oid \""+v.ValueString()+"\" include") @@ -344,9 +344,7 @@ func (rscData *snmpViewData) set( func (rscData *snmpViewData) read( _ context.Context, name string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "snmp view \"" + name + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_static_route.go b/internal/providerfwk/resource_static_route.go index 54af5d87..f2c4d951 100644 --- a/internal/providerfwk/resource_static_route.go +++ b/internal/providerfwk/resource_static_route.go @@ -798,9 +798,10 @@ func (rsc *staticRoute) ImportState( ) } -func checkStaticRouteExists(_ context.Context, destination, routingInstance string, junSess *junos.Session, +func checkStaticRouteExists( + _ context.Context, destination, routingInstance string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showPrefix := junos.CmdShowConfig switch routingInstance { @@ -815,11 +816,11 @@ func checkStaticRouteExists(_ context.Context, destination, routingInstance stri showPrefix += "rib " + routingInstance + ".inet6.0 " } } - showConfig, err := junSess.Command(showPrefix + "static route " + destination + junos.PipeDisplaySet) + showConfig, err := junSess.Command(showPrefix + + "static route " + destination + junos.PipeDisplaySet) if err != nil { return false, err } - if showConfig == junos.EmptyW { return false, nil } @@ -959,9 +960,7 @@ func (rscData *staticRouteData) set( func (rscData *staticRouteData) read( _ context.Context, destination, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig switch routingInstance { case junos.DefaultW, "": @@ -975,16 +974,17 @@ func (rscData *staticRouteData) read( showPrefix += "rib " + routingInstance + ".inet6.0 " } } - showConfig, err := junSess.Command(showPrefix + "static route " + destination + junos.PipeDisplaySetRelative) + showConfig, err := junSess.Command(showPrefix + + "static route " + destination + junos.PipeDisplaySetRelative) if err != nil { return err } - if showConfig != junos.EmptyW { rscData.Destination = types.StringValue(destination) - rscData.RoutingInstance = types.StringValue(routingInstance) - if rscData.RoutingInstance.ValueString() == "" { + if routingInstance == "" { rscData.RoutingInstance = types.StringValue(junos.DefaultW) + } else { + rscData.RoutingInstance = types.StringValue(routingInstance) } rscData.fillID() for _, item := range strings.Split(showConfig, "\n") { @@ -1097,6 +1097,7 @@ func (rscData *staticRouteData) del( delPrefix += "rib " + routingInstance + ".inet6.0 " } } + configSet := []string{ delPrefix + "static route " + rscData.Destination.ValueString(), } diff --git a/internal/providerfwk/resource_switch_options.go b/internal/providerfwk/resource_switch_options.go index 8d7c3ea3..99e75a65 100644 --- a/internal/providerfwk/resource_switch_options.go +++ b/internal/providerfwk/resource_switch_options.go @@ -238,9 +238,7 @@ func (rscData *switchOptionsData) set( func (rscData *switchOptionsData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "switch-options" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_system.go b/internal/providerfwk/resource_system.go index 3c7084d7..8b9988b3 100644 --- a/internal/providerfwk/resource_system.go +++ b/internal/providerfwk/resource_system.go @@ -3223,6 +3223,7 @@ func (block *systemBlockAccounting) configSet() ( func (block *systemBlockAccountingBlockDestinationRadiusServer) configSet() []string { setPrefix := "set system accounting destination radius server " + block.Address.ValueString() + " " + configSet := []string{ setPrefix + "secret \"" + block.Secret.ValueString() + "\"", } @@ -3278,6 +3279,7 @@ func (block *systemBlockAccountingBlockDestinationRadiusServer) configSet() []st func (block *systemBlockAccountingBlockDestinationTacplusServer) configSet() []string { setPrefix := "set system accounting destination tacplus server " + block.Address.ValueString() + " " + configSet := []string{ setPrefix, } @@ -3966,9 +3968,7 @@ func (block *systemBlockSyslog) configSet() ( func (rscData *systemData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "system" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_system_radius_server.go b/internal/providerfwk/resource_system_radius_server.go index cc6b6a6a..7b0bb59a 100644 --- a/internal/providerfwk/resource_system_radius_server.go +++ b/internal/providerfwk/resource_system_radius_server.go @@ -351,7 +351,7 @@ func (rsc *systemRadiusServer) ImportState( func checkSystemRadiusServerExists( _ context.Context, address string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showConfig, err := junSess.Command(junos.CmdShowConfig + "system radius-server " + address + junos.PipeDisplaySet) @@ -379,6 +379,7 @@ func (rscData *systemRadiusServerData) set( path.Path, error, ) { setPrefix := "set system radius-server " + rscData.Address.ValueString() + " " + configSet := []string{ setPrefix + "secret \"" + rscData.Secret.ValueString() + "\"", } @@ -434,9 +435,7 @@ func (rscData *systemRadiusServerData) set( func (rscData *systemRadiusServerData) read( _ context.Context, address string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "system radius-server " + address + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_system_syslog_file.go b/internal/providerfwk/resource_system_syslog_file.go index d46e5946..45f37995 100644 --- a/internal/providerfwk/resource_system_syslog_file.go +++ b/internal/providerfwk/resource_system_syslog_file.go @@ -810,9 +810,7 @@ func (rscData *systemSyslogFileData) set( func (rscData *systemSyslogFileData) read( _ context.Context, filename string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "system syslog file \"" + filename + "\"" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_system_syslog_host.go b/internal/providerfwk/resource_system_syslog_host.go index 8ee648fc..99426747 100644 --- a/internal/providerfwk/resource_system_syslog_host.go +++ b/internal/providerfwk/resource_system_syslog_host.go @@ -583,9 +583,7 @@ func (rscData *systemSyslogHostData) set( func (rscData *systemSyslogHostData) read( _ context.Context, host string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "system syslog host " + host + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_system_syslog_user.go b/internal/providerfwk/resource_system_syslog_user.go index 30f6fc57..53fda0d7 100644 --- a/internal/providerfwk/resource_system_syslog_user.go +++ b/internal/providerfwk/resource_system_syslog_user.go @@ -484,9 +484,7 @@ func (rscData *systemSyslogUserData) set( func (rscData *systemSyslogUserData) read( _ context.Context, username string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "system syslog user " + username + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_system_tacplus_server.go b/internal/providerfwk/resource_system_tacplus_server.go index 3b9d01f4..2fc67c3e 100644 --- a/internal/providerfwk/resource_system_tacplus_server.go +++ b/internal/providerfwk/resource_system_tacplus_server.go @@ -293,7 +293,7 @@ func (rsc *systemTacplusServer) ImportState( func checkSystemTacplusServerExists( _ context.Context, address string, junSess *junos.Session, ) ( - _ bool, err error, + bool, error, ) { showConfig, err := junSess.Command(junos.CmdShowConfig + "system tacplus-server " + address + junos.PipeDisplaySet) @@ -321,6 +321,7 @@ func (rscData *systemTacplusServerData) set( path.Path, error, ) { setPrefix := "set system tacplus-server " + rscData.Address.ValueString() + " " + configSet := []string{ setPrefix, } @@ -351,9 +352,7 @@ func (rscData *systemTacplusServerData) set( func (rscData *systemTacplusServerData) read( _ context.Context, address string, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "system tacplus-server " + address + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_virtual_chassis.go b/internal/providerfwk/resource_virtual_chassis.go index c4085f49..b1d06b07 100644 --- a/internal/providerfwk/resource_virtual_chassis.go +++ b/internal/providerfwk/resource_virtual_chassis.go @@ -604,8 +604,8 @@ func (rscData *virtualChassisData) set( ) ( path.Path, error, ) { - setPrefix := "set virtual-chassis " configSet := make([]string, 0) + setPrefix := "set virtual-chassis " if rscData.AutoSWUpdate.ValueBool() { configSet = append(configSet, setPrefix+"auto-sw-update") @@ -689,8 +689,8 @@ func (rscData *virtualChassisData) set( } func (block *virtualChassisBlockMember) configSet() []string { - setPrefix := "set virtual-chassis member " + utils.ConvI64toa(block.ID.ValueInt64()) + " " configSet := make([]string, 0, 1) + setPrefix := "set virtual-chassis member " + utils.ConvI64toa(block.ID.ValueInt64()) + " " if v := block.Location.ValueString(); v != "" { configSet = append(configSet, setPrefix+"location \""+v+"\"") @@ -714,6 +714,7 @@ func (block *virtualChassisBlockMember) configSet() []string { func (block *virtualChassisBlockTraceoptionsBlockFile) configSet() []string { setPrefix := "set virtual-chassis traceoptions file " + configSet := []string{ setPrefix + "\"" + block.Name.ValueString() + "\"", } @@ -744,9 +745,7 @@ func (block *virtualChassisBlockTraceoptionsBlockFile) configSet() []string { func (rscData *virtualChassisData) read( _ context.Context, junSess *junos.Session, -) ( - err error, -) { +) error { showConfig, err := junSess.Command(junos.CmdShowConfig + "virtual-chassis" + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resource_vlan.go b/internal/providerfwk/resource_vlan.go index 71c2e932..b35c096b 100644 --- a/internal/providerfwk/resource_vlan.go +++ b/internal/providerfwk/resource_vlan.go @@ -606,7 +606,6 @@ func checkVlanExists( if routingInstance != "" && routingInstance != junos.DefaultW { showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - showConfig, err := junSess.Command(showPrefix + "vlans " + name + junos.PipeDisplaySet) if err != nil { @@ -716,14 +715,11 @@ func (rscData *vlanData) set( func (rscData *vlanData) read( _ context.Context, name, routingInstance string, junSess *junos.Session, -) ( - err error, -) { +) error { showPrefix := junos.CmdShowConfig if routingInstance != "" && routingInstance != junos.DefaultW { showPrefix += junos.RoutingInstancesWS + routingInstance + " " } - showConfig, err := junSess.Command(showPrefix + "vlans " + name + junos.PipeDisplaySetRelative) if err != nil { diff --git a/internal/providerfwk/resourcedata_bgp.go b/internal/providerfwk/resourcedata_bgp.go index 28143d8e..83109c24 100644 --- a/internal/providerfwk/resourcedata_bgp.go +++ b/internal/providerfwk/resourcedata_bgp.go @@ -116,6 +116,7 @@ func (block *bgpBlockBfdLivenessDetection) configSet(setPrefix string) []string func (block *bgpBlockBgpErrorTolerance) configSet(setPrefix string) []string { setPrefix += "bgp-error-tolerance" + configSet := []string{ setPrefix, } @@ -137,6 +138,7 @@ func (block *bgpBlockBgpErrorTolerance) configSet(setPrefix string) []string { func (block *bgpBlockBgpMultipath) configSet(setPrefix string) []string { setPrefix += "multipath" + configSet := []string{ setPrefix, } @@ -162,6 +164,7 @@ func (block *bgpBlockFamily) configSet( error, // error ) { setPrefix += block.NlriType.ValueString() + " " + configSet := []string{ setPrefix, } @@ -216,6 +219,7 @@ func (block *bgpBlockFamily) configSet( func (block *bgpBlockGracefulRestart) configSet(setPrefix string) []string { setPrefix += "graceful-restart" + configSet := []string{ setPrefix, } diff --git a/internal/providerfwk/upgradestate_bridge_domain.go b/internal/providerfwk/upgradestate_bridge_domain.go index fc7f4d64..3a442876 100644 --- a/internal/providerfwk/upgradestate_bridge_domain.go +++ b/internal/providerfwk/upgradestate_bridge_domain.go @@ -108,8 +108,8 @@ func upgradeBridgeDomainStateV0toV1( VLANID types.Int64 `tfsdk:"vlan_id"` VLANIDList []types.String `tfsdk:"vlan_id_list"` VXLAN []struct { - VNI types.Int64 `tfsdk:"vni"` - VNIExtendEvpn types.Bool `tfsdk:"vni_extend_evpn"` + Vni types.Int64 `tfsdk:"vni"` + VniExtendEvpn types.Bool `tfsdk:"vni_extend_evpn"` DecapsulateAcceptInnerVlan types.Bool `tfsdk:"decapsulate_accept_inner_vlan"` EncapsulateInnerVlan types.Bool `tfsdk:"encapsulate_inner_vlan"` IngressNodeReplication types.Bool `tfsdk:"ingress_node_replication"` @@ -140,12 +140,12 @@ func upgradeBridgeDomainStateV0toV1( dataV1.VLANIDList = dataV0.VLANIDList if len(dataV0.VXLAN) > 0 { dataV1.VXLAN = &bridgeDomainBlockVXLAN{ - VNIExtendEvpn: dataV0.VXLAN[0].VNIExtendEvpn, + Vni: dataV0.VXLAN[0].Vni, + VniExtendEvpn: dataV0.VXLAN[0].VniExtendEvpn, DecapsulateAcceptInnerVlan: dataV0.VXLAN[0].DecapsulateAcceptInnerVlan, EncapsulateInnerVlan: dataV0.VXLAN[0].EncapsulateInnerVlan, IngressNodeReplication: dataV0.VXLAN[0].IngressNodeReplication, OvsdbManaged: dataV0.VXLAN[0].OvsdbManaged, - VNI: dataV0.VXLAN[0].VNI, MulticastGroup: dataV0.VXLAN[0].MulticastGroup, UnreachableVtepAgingTimer: dataV0.VXLAN[0].UnreachableVtepAgingTimer, } diff --git a/internal/providersdk/constants.go b/internal/providersdk/constants.go index 4e97290a..1be2e1b0 100644 --- a/internal/providersdk/constants.go +++ b/internal/providersdk/constants.go @@ -1,3 +1,10 @@ package providersdk +import "github.com/jeremmfr/terraform-provider-junos/internal/junos" + const failedConvAtoiError = "failed to convert value from '%s' to integer: %w" + +const ( + setRoutingInstances = junos.SetLS + junos.RoutingInstancesWS + delRoutingInstances = junos.DeleteLS + junos.RoutingInstancesWS +) diff --git a/internal/providersdk/resource_access_address_assignment_pool.go b/internal/providersdk/resource_access_address_assignment_pool.go index 6f7e51e8..01767b0c 100644 --- a/internal/providersdk/resource_access_address_assignment_pool.go +++ b/internal/providersdk/resource_access_address_assignment_pool.go @@ -752,7 +752,7 @@ func setAccessAddressAssignPool(d *schema.ResourceData, junSess *junos.Session) setPrefix := junos.SetLS if d.Get("routing_instance").(string) != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + d.Get("routing_instance").(string) + " " + setPrefix = setRoutingInstances + d.Get("routing_instance").(string) + " " } setPrefix += "access address-assignment pool " + d.Get("name").(string) + " " @@ -1366,7 +1366,7 @@ func delAccessAddressAssignPool(name, instance string, junSess *junos.Session) e if instance == junos.DefaultW { configSet = append(configSet, "delete access address-assignment pool "+name) } else { - configSet = append(configSet, junos.DelRoutingInstances+instance+" access address-assignment pool "+name) + configSet = append(configSet, delRoutingInstances+instance+" access address-assignment pool "+name) } return junSess.ConfigSet(configSet) diff --git a/internal/providersdk/resource_forwardingoptions_dhcprelay.go b/internal/providersdk/resource_forwardingoptions_dhcprelay.go index d830019a..93621c1d 100644 --- a/internal/providersdk/resource_forwardingoptions_dhcprelay.go +++ b/internal/providersdk/resource_forwardingoptions_dhcprelay.go @@ -788,7 +788,7 @@ func setForwardingOptionsDhcpRelay( //nolint:gocognit,gocyclo setPrefix := junos.SetLS if d.Get("routing_instance").(string) != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + d.Get("routing_instance").(string) + " " + setPrefix = setRoutingInstances + d.Get("routing_instance").(string) + " " } if d.Get("version").(string) == "v6" { setPrefix += "forwarding-options dhcp-relay dhcpv6 " @@ -1555,9 +1555,9 @@ func delForwardingOptionsDhcpRelay(instance, version string, junSess *junos.Sess case instance == junos.DefaultW && version == "v4": delPrefix = junos.DeleteLS + "forwarding-options dhcp-relay " case instance != junos.DefaultW && version == "v6": - delPrefix = junos.DelRoutingInstances + instance + " forwarding-options dhcp-relay dhcpv6 " + delPrefix = delRoutingInstances + instance + " forwarding-options dhcp-relay dhcpv6 " case instance != junos.DefaultW && version == "v4": - delPrefix = junos.DelRoutingInstances + instance + " forwarding-options dhcp-relay " + delPrefix = delRoutingInstances + instance + " forwarding-options dhcp-relay " } listLinesToDelete := []string{ "access-profile", diff --git a/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go b/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go index 37dc22e1..3eb77847 100644 --- a/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go +++ b/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go @@ -885,7 +885,7 @@ func setForwardingOptionsDhcpRelayGroup(d *schema.ResourceData, junSess *junos.S setPrefix := junos.SetLS if d.Get("routing_instance").(string) != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + d.Get("routing_instance").(string) + " " + setPrefix = setRoutingInstances + d.Get("routing_instance").(string) + " " } if d.Get("version").(string) == "v6" { setPrefix += "forwarding-options dhcp-relay dhcpv6 group " + d.Get("name").(string) + " " @@ -1675,10 +1675,10 @@ func delForwardingOptionsDhcpRelayGroup(name, instance, version string, junSess case instance == junos.DefaultW && version == "v4": configSet = append(configSet, junos.DeleteLS+"forwarding-options dhcp-relay group "+name) case instance != junos.DefaultW && version == "v6": - configSet = append(configSet, junos.DelRoutingInstances+instance+" "+ + configSet = append(configSet, delRoutingInstances+instance+" "+ "forwarding-options dhcp-relay dhcpv6 group "+name) case instance != junos.DefaultW && version == "v4": - configSet = append(configSet, junos.DelRoutingInstances+instance+" "+ + configSet = append(configSet, delRoutingInstances+instance+" "+ "forwarding-options dhcp-relay group "+name) } diff --git a/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go b/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go index 36d8d438..2ae80539 100644 --- a/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go +++ b/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go @@ -367,7 +367,7 @@ func setForwardingOptionsDhcpRelayServerGroup(d *schema.ResourceData, junSess *j setPrefix := junos.SetLS if d.Get("routing_instance").(string) != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + d.Get("routing_instance").(string) + " " + setPrefix = setRoutingInstances + d.Get("routing_instance").(string) + " " } if d.Get("version").(string) == "v6" { setPrefix += "forwarding-options dhcp-relay dhcpv6 server-group " + d.Get("name").(string) + " " @@ -429,10 +429,10 @@ func delForwardingOptionsDhcpRelayServerGroup(name, instance, version string, ju case instance == junos.DefaultW && version == "v4": configSet = append(configSet, junos.DeleteLS+"forwarding-options dhcp-relay server-group "+name) case instance != junos.DefaultW && version == "v6": - configSet = append(configSet, junos.DelRoutingInstances+instance+" "+ + configSet = append(configSet, delRoutingInstances+instance+" "+ "forwarding-options dhcp-relay dhcpv6 server-group "+name) case instance != junos.DefaultW && version == "v4": - configSet = append(configSet, junos.DelRoutingInstances+instance+" "+ + configSet = append(configSet, delRoutingInstances+instance+" "+ "forwarding-options dhcp-relay server-group "+name) } diff --git a/internal/providersdk/resource_igmp_snooping_vlan.go b/internal/providersdk/resource_igmp_snooping_vlan.go index b371611c..d8babbec 100644 --- a/internal/providersdk/resource_igmp_snooping_vlan.go +++ b/internal/providersdk/resource_igmp_snooping_vlan.go @@ -418,7 +418,7 @@ func setIgmpSnoopingVlan(d *schema.ResourceData, junSess *junos.Session) error { setPrefix := junos.SetLS if rI := d.Get("routing_instance").(string); rI != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + rI + " " + setPrefix = setRoutingInstances + rI + " " } setPrefix += "protocols igmp-snooping vlan " + d.Get("name").(string) + " " @@ -586,7 +586,7 @@ func delIgmpSnoopingVlan(name, routingInstance string, junSess *junos.Session) e if routingInstance == junos.DefaultW { configSet = append(configSet, "delete protocols igmp-snooping vlan "+name) } else { - configSet = append(configSet, junos.DelRoutingInstances+routingInstance+" protocols igmp-snooping vlan "+name) + configSet = append(configSet, delRoutingInstances+routingInstance+" protocols igmp-snooping vlan "+name) } return junSess.ConfigSet(configSet) diff --git a/internal/providersdk/resource_rip_group.go b/internal/providersdk/resource_rip_group.go index 8ed75da4..85eaceb9 100644 --- a/internal/providersdk/resource_rip_group.go +++ b/internal/providersdk/resource_rip_group.go @@ -498,7 +498,7 @@ func setRipGroup(d *schema.ResourceData, junSess *junos.Session) error { setPrefix := junos.SetLS if rI := d.Get("routing_instance").(string); rI != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + rI + " " + setPrefix = setRoutingInstances + rI + " " } if d.Get("ng").(bool) { setPrefix += "protocols ripng group " @@ -726,7 +726,7 @@ func delRipGroup( ) error { delPrefix := junos.DeleteLS if routingInstance != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + routingInstance + " " + delPrefix = delRoutingInstances + routingInstance + " " } if ripNg { delPrefix += "protocols ripng group " diff --git a/internal/providersdk/resource_rip_neighbor.go b/internal/providersdk/resource_rip_neighbor.go index 0425d62a..432c10e3 100644 --- a/internal/providersdk/resource_rip_neighbor.go +++ b/internal/providersdk/resource_rip_neighbor.go @@ -622,7 +622,7 @@ func setRipNeighbor(d *schema.ResourceData, junSess *junos.Session) error { setPrefix := junos.SetLS if rI := d.Get("routing_instance").(string); rI != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + rI + " " + setPrefix = setRoutingInstances + rI + " " } if d.Get("ng").(bool) { setPrefix += "protocols ripng group " @@ -932,7 +932,7 @@ func delRipNeighbor( ) error { delPrefix := junos.DeleteLS if routingInstance != junos.DefaultW { - delPrefix = junos.DelRoutingInstances + routingInstance + " " + delPrefix = delRoutingInstances + routingInstance + " " } if ripNg { delPrefix += "protocols ripng group " diff --git a/internal/providersdk/resource_system_services_dhcp_localserver_group.go b/internal/providersdk/resource_system_services_dhcp_localserver_group.go index 2a0fdd3b..7e46ac6e 100644 --- a/internal/providersdk/resource_system_services_dhcp_localserver_group.go +++ b/internal/providersdk/resource_system_services_dhcp_localserver_group.go @@ -1072,7 +1072,7 @@ func setSystemServicesDhcpLocalServerGroup(d *schema.ResourceData, junSess *juno setPrefix := junos.SetLS if d.Get("routing_instance").(string) != junos.DefaultW { - setPrefix = junos.SetRoutingInstances + d.Get("routing_instance").(string) + " " + setPrefix = setRoutingInstances + d.Get("routing_instance").(string) + " " } if d.Get("version").(string) == "v6" { setPrefix += "system services dhcp-local-server dhcpv6 group " + d.Get("name").(string) + " " @@ -2090,10 +2090,10 @@ func delSystemServicesDhcpLocalServerGroup(name, instance, version string, junSe case instance == junos.DefaultW && version == "v4": configSet = append(configSet, "delete system services dhcp-local-server group "+name) case instance != junos.DefaultW && version == "v6": - configSet = append(configSet, junos.DelRoutingInstances+instance+" "+ + configSet = append(configSet, delRoutingInstances+instance+" "+ "system services dhcp-local-server dhcpv6 group "+name) case instance != junos.DefaultW && version == "v4": - configSet = append(configSet, junos.DelRoutingInstances+instance+" "+ + configSet = append(configSet, delRoutingInstances+instance+" "+ "system services dhcp-local-server group "+name) } From 69a9dba39eab42d8e49ce751dea7eb0314939a1f Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Fri, 14 Jun 2024 14:01:35 +0200 Subject: [PATCH 2/2] r/bridge_domain: fix potential wrong True when read vxlan.vni_extend_evpn argument --- internal/providerfwk/resource_bridge_domain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/providerfwk/resource_bridge_domain.go b/internal/providerfwk/resource_bridge_domain.go index a0e1cbc7..2230bdbf 100644 --- a/internal/providerfwk/resource_bridge_domain.go +++ b/internal/providerfwk/resource_bridge_domain.go @@ -746,7 +746,7 @@ func (rscData *bridgeDomainData) read( if strings.Contains(itemEvpn, junos.XMLEndTagConfigOut) { break } - if strings.HasPrefix(itemEvpn, junos.SetLS+"extended-vni-list "+itemTrim) { + if itemEvpn == junos.SetLS+"extended-vni-list "+itemTrim { rscData.VXLAN.VniExtendEvpn = types.BoolValue(true) break