Skip to content

Commit

Permalink
Merge pull request #312 from jeremmfr/main
Browse files Browse the repository at this point in the history
Release v1.22.0
  • Loading branch information
jeremmfr authored Nov 19, 2021
2 parents d034aa8 + d83f2de commit 8b4f735
Show file tree
Hide file tree
Showing 58 changed files with 6,892 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.42
version: v1.43
args: -c .golangci.yml -v

markdown-lint:
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- cyclop
- forcetypeassert
- gomoddirectives
- varnamelen
linters-settings:
gocognit:
# minimal code complexity to report, 30 by default
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ ENHANCEMENTS:

BUG FIXES:

## 1.22.0 (November 19, 2021)

FEATURES:

* add `junos_access_address_assignment_pool` resource (Fixes parts of [#301](https://github.com/jeremmfr/terraform-provider-junos/issues/301))
* add `junos_interface_physical_disable` resource (Fixes [#305](https://github.com/jeremmfr/terraform-provider-junos/issues/305))
* add `junos_interfaces_physical_present` data-source
* add `junos_system_services_dhcp_localserver_group` resource (Fixes parts of [#301](https://github.com/jeremmfr/terraform-provider-junos/issues/301))

ENHANCEMENTS:

* resource/`junos_application`: add `term` block argument (Fixes [#296](https://github.com/jeremmfr/terraform-provider-junos/issues/296)), add `inactivity_timeout_never` argument (Fixes [#308](https://github.com/jeremmfr/terraform-provider-junos/issues/308))
* resource/`junos_chassis_cluster`: add `control_ports` block argument (Fixes [#304](https://github.com/jeremmfr/terraform-provider-junos/issues/304))
* resource/`junos_group_dual_system`: add `system.0.inet6_backup_router_address` and `system.0.inet6_backup_router_destination` arguments, add validation on `system.0.backup_router_address` and list of string for `system.0.backup_router_destination` is now unordered (Fixes [#302](https://github.com/jeremmfr/terraform-provider-junos/issues/302))
* resource/`junos_interface_logical`: add `dhcp` and `dhcpv6_client` block arguments inside `family_inet` and `family_inet6` block arguments (Fixes parts of [#301](https://github.com/jeremmfr/terraform-provider-junos/issues/301))
* data-source/`junos_interface_logical`: add `dhcp` and `dhcpv6_client` block attributes inside `family_inet` and `family_inet6` block attributes
* resource/`junos_system`: add `ports` block argument (Fixes [#294](https://github.com/jeremmfr/terraform-provider-junos/issues/294))

BUG FIXES:

* resource/`junos_security_idp_custom_attack`: fix validation of IPv6 address for `destination_value`, `extension_header_destination_option_home_address_value` and `source_value` inside `protocol_ipv6` block
* resource/`junos_services_rpm_probe`: fix validation of IPv6 address for `inet6_source_address`, `rpm_scale.0.source_inet6_address_base`, `rpm_scale.0.source_inet6_step`, `rpm_scale.0.target_inet6_address_base` and `rpm_scale.0.target_inet6_step` inside `test` block

## 1.21.1 (October 22, 2021)

BUG FIXES:
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
default: install

.PHONY: install testacc testacc_srx testacc_router testacc_switch
# Install to use dev_overrides in provider_installation of Terraform
install:
go install
# Run acceptance tests
testacc:
cd junos ; TF_ACC=1 go test -v --timeout 0 -coverprofile=../coverage.out $(TESTARGS)
go tool cover -html=coverage.out
testacc/srx:
cd junos ; TESTACC_SRX=1 TF_ACC=1 go test -v --timeout 0 -coverprofile=../coverage_srx.out $(TESTARGS)
go tool cover -html=coverage_srx.out
testacc/router:
cd junos ; TESTACC_ROUTER=1 TF_ACC=1 go test -v --timeout 0 -coverprofile=../coverage_router.out $(TESTARGS)
go tool cover -html=coverage_router.out
testacc/switch:
cd junos ; TESTACC_SWITCH=1 TF_ACC=1 go test -v --timeout 0 -coverprofile=../coverage_switch.out $(TESTARGS)
go tool cover -html=coverage_switch.out
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
github.com/jeremmfr/go-netconf v0.4.0
github.com/jeremmfr/go-netconf v0.4.1
github.com/jeremmfr/go-utils v0.3.0
github.com/jeremmfr/junosdecode v1.1.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jeremmfr/go-netconf v0.4.0 h1:MYrbA5keH7bsBpgcTA0MVvIg6oiA2bgdsJkdE2F3I7Y=
github.com/jeremmfr/go-netconf v0.4.0/go.mod h1:Nd1B4xd6miAKQzNxe0m3wddyLdAeKK+N04MOAiVhE0c=
github.com/jeremmfr/go-netconf v0.4.1 h1:cFWw/x/3AI3XlmTft8G1qMI3+wwETQ2S1cbr0K2Ejl4=
github.com/jeremmfr/go-netconf v0.4.1/go.mod h1:Nd1B4xd6miAKQzNxe0m3wddyLdAeKK+N04MOAiVhE0c=
github.com/jeremmfr/go-utils v0.3.0 h1:f69G5Z6EnHO2bNEW+aeWB22P/4/plS1DZ2UZK7gd+WI=
github.com/jeremmfr/go-utils v0.3.0/go.mod h1:K0lGadiSvg9OKGJnW4Bs3t18/VApp/6x2+BV93Sts2M=
github.com/jeremmfr/junosdecode v1.1.0 h1:Os8QeOzyL+BPuDZJMjyJgz4QPOgA8EChgKB2Ih5wwCc=
Expand Down
140 changes: 139 additions & 1 deletion junos/data_source_interface_logical.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,86 @@ func dataSourceInterfaceLogical() *schema.Resource {
},
},
},
"dhcp": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_identifier_ascii": {
Type: schema.TypeString,
Computed: true,
},
"client_identifier_hexadecimal": {
Type: schema.TypeString,
Computed: true,
},
"client_identifier_prefix_hostname": {
Type: schema.TypeBool,
Computed: true,
},
"client_identifier_prefix_routing_instance_name": {
Type: schema.TypeBool,
Computed: true,
},
"client_identifier_use_interface_description": {
Type: schema.TypeString,
Computed: true,
},
"client_identifier_userid_ascii": {
Type: schema.TypeString,
Computed: true,
},
"client_identifier_userid_hexadecimal": {
Type: schema.TypeString,
Computed: true,
},
"force_discover": {
Type: schema.TypeBool,
Computed: true,
},
"lease_time": {
Type: schema.TypeInt,
Computed: true,
},
"lease_time_infinite": {
Type: schema.TypeBool,
Computed: true,
},
"metric": {
Type: schema.TypeInt,
Computed: true,
},
"no_dns_install": {
Type: schema.TypeBool,
Computed: true,
},
"options_no_hostname": {
Type: schema.TypeBool,
Computed: true,
},
"retransmission_attempt": {
Type: schema.TypeInt,
Computed: true,
},
"retransmission_interval": {
Type: schema.TypeInt,
Computed: true,
},
"server_address": {
Type: schema.TypeString,
Computed: true,
},
"update_server": {
Type: schema.TypeBool,
Computed: true,
},
"vendor_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"filter_input": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -303,7 +383,65 @@ func dataSourceInterfaceLogical() *schema.Resource {
},
"dad_disable": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"dhcpv6_client": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_identifier_duid_type": {
Type: schema.TypeString,
Computed: true,
},
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"client_ia_type_na": {
Type: schema.TypeBool,
Computed: true,
},
"client_ia_type_pd": {
Type: schema.TypeBool,
Computed: true,
},
"no_dns_install": {
Type: schema.TypeBool,
Computed: true,
},
"prefix_delegating_preferred_prefix_length": {
Type: schema.TypeInt,
Computed: true,
},
"prefix_delegating_sub_prefix_length": {
Type: schema.TypeInt,
Computed: true,
},
"rapid_commit": {
Type: schema.TypeBool,
Computed: true,
},
"req_option": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"retransmission_attempt": {
Type: schema.TypeInt,
Computed: true,
},
"update_router_advertisement_interface": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"update_server": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"filter_input": {
Type: schema.TypeString,
Expand Down
143 changes: 143 additions & 0 deletions junos/data_source_interfaces_physical_present.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package junos

import (
"context"
"encoding/xml"
"fmt"
"regexp"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

type interfacesPresentOpts struct {
interfaceNames []string
interfaceStatuses []map[string]interface{}
}

func dataSourceInterfacesPhysicalPresent() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceInterfacesPhysicalPresentRead,
Schema: map[string]*schema.Schema{
"match_name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if _, err := regexp.Compile(value); err != nil {
errors = append(errors, fmt.Errorf(
"%q for %q is not valid regexp", value, k))
}

return
},
},
"match_admin_up": {
Type: schema.TypeBool,
Optional: true,
},
"match_oper_up": {
Type: schema.TypeBool,
Optional: true,
},
"interface_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"interface_statuses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"admin_status": {
Type: schema.TypeString,
Computed: true,
},
"oper_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}

func dataSourceInterfacesPhysicalPresentRead(ctx context.Context,
d *schema.ResourceData, m interface{}) diag.Diagnostics {
sess := m.(*Session)
jnprSess, err := sess.startNewSession()
if err != nil {
return diag.FromErr(err)
}
defer sess.closeSession(jnprSess)
mutex.Lock()
iPresent, err := searchInterfacesPhysicalPresent(d, m, jnprSess)
mutex.Unlock()
if err != nil {
return diag.FromErr(err)
}
if tfErr := d.Set("interface_names", iPresent.interfaceNames); tfErr != nil {
panic(tfErr)
}
if tfErr := d.Set("interface_statuses", iPresent.interfaceStatuses); tfErr != nil {
panic(tfErr)
}
idString := "match=" + d.Get("match_name").(string)
if d.Get("match_admin_up").(bool) {
idString += idSeparator + "admin_up=true"
}
if d.Get("match_oper_up").(bool) {
idString += idSeparator + "oper_up=true"
}
d.SetId(idString)

return nil
}

func searchInterfacesPhysicalPresent(
d *schema.ResourceData, m interface{}, jnprSess *NetconfObject) (interfacesPresentOpts, error) {
sess := m.(*Session)
var result interfacesPresentOpts
replyData, err := sess.commandXML(rpcGetInterfaceInformationTerse, jnprSess)
if err != nil {
return result, err
}
var iface getInterfaceTerseReply
err = xml.Unmarshal([]byte(replyData), &iface.InterfaceInfo)
if err != nil {
return result, fmt.Errorf("failed to xml unmarshal reply data %s : %w", replyData, err)
}
for _, iFace := range iface.InterfaceInfo.PhysicalInterface {
if mName := d.Get("match_name").(string); mName != "" {
matched, err := regexp.MatchString(mName, strings.Trim(iFace.Name, " \n\t"))
if err != nil {
return result, fmt.Errorf("failed to regexp with %s : %w", mName, err)
}
if !matched {
continue
}
}
if d.Get("match_admin_up").(bool) && strings.Trim(iFace.AdminStatus, " \n\t") != "up" {
continue
}
if d.Get("match_oper_up").(bool) && strings.Trim(iFace.OperStatus, " \n\t") != "up" {
continue
}
result.interfaceNames = append(result.interfaceNames, strings.Trim(iFace.Name, " \n\t"))
result.interfaceStatuses = append(result.interfaceStatuses, map[string]interface{}{
"name": strings.Trim(iFace.Name, " \n\t"),
"admin_status": strings.Trim(iFace.AdminStatus, " \n\t"),
"oper_status": strings.Trim(iFace.OperStatus, " \n\t"),
})
}

return result, nil
}
Loading

0 comments on commit 8b4f735

Please sign in to comment.