Skip to content

Commit

Permalink
Merge pull request #745 from jeremmfr/latest-system-resources-with-fwk
Browse files Browse the repository at this point in the history
Latest system resources with fwk
  • Loading branch information
jeremmfr authored Jan 20, 2025
2 parents 923a353 + 92d2bbf commit 4b564b9
Show file tree
Hide file tree
Showing 35 changed files with 5,482 additions and 3,674 deletions.
23 changes: 23 additions & 0 deletions .changes/latest-system-resources-with-fwk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- markdownlint-disable-file MD013 MD041 -->
ENHANCEMENTS:

* **resource/junos_system_ntp_server**:
* resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework)
optional boolean attribute doesn't accept value *false*
optional string attribute doesn't accept *empty* value
* add `nts` block argument
* **resource/junos_system_services_dhcp_localserver_group**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework)
some of config errors are now sent during Plan instead of during Apply
optional boolean attributes doesn't accept value *false*
optional string attributes doesn't accept *empty* value
the resource schema has been upgraded to have one-blocks in single mode instead of list
* **data-source/junos_system_information** data-source now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework)

BUG FIXES:

* **resource/junos_forwardingoptions_dhcprelay**:
* fix missing detection of conflict between `dynamic_profile_aggregate_clients` and `dynamic_profile_use_primary` arguments in config validation
* fix missing detection of empty `overrides_v4` and `overrides_v6` block arguments in config validation
* **resource/junos_forwardingoptions_dhcprelay_group**:
* fix missing detection of conflict between `dynamic_profile_aggregate_clients` and `dynamic_profile_use_primary` arguments in config validation
* fix missing detection of empty `overrides_v4` and `overrides_v6` block arguments in config validation
8 changes: 8 additions & 0 deletions docs/resources/system_ntp_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ The following arguments are supported:
Address of server.
- **key** (Optional, Number)
Authentication key (1..65534).
- **nts** (Optional, Block)
Enable NTS protocol for this server.
- **remote_identity_distinguished_name_container** (Optional, String)
Container string for distinguished name of server to remote identity of server for verification.
- **remote_identity_distinguished_name_wildcard** (Optional, String)
Wildcard string for distinguished name of server to remote identity of server for verification.
- **remote_identity_hostname** (Optional, String)
Fully-qualified domain name to remote identity of server for verification.
- **prefer** (Optional, Boolean)
Prefer this peer_serv.
- **routing_instance** (Optional, String)
Expand Down
16 changes: 8 additions & 8 deletions docs/resources/system_services_dhcp_localserver_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ The following arguments are supported:
Include the vlan tag(s).
- **dynamic_profile** (Optional, String)
Dynamic profile to use.
- **dynamic_profile_use_primary** (Optional, String)
Dynamic profile to use on the primary interface.
`dynamic_profile` need to be set.
Conflict with `dynamic_profile_aggregate_clients`.
- **dynamic_profile_aggregate_clients** (Optional, Boolean)
Aggregate client profiles.
- **dynamic_profile_aggregate_clients_action** (Optional, String)
Merge or replace the client dynamic profiles.
Need to be `merge` or `replace`.
`dynamic_profile_aggregate_clients` need to be true.
- **dynamic_profile_use_primary** (Optional, String)
Dynamic profile to use on the primary interface.
`dynamic_profile` need to be set.
Conflict with `dynamic_profile_aggregate_clients`.
- **interface** (Optional, Block Set)
For each name of interface to declare.
See [below for nested schema](#interface-arguments).
Expand Down Expand Up @@ -174,7 +174,7 @@ The following arguments are supported:
- **clear_on_abort** (Optional, Boolean)
Delete client on reconfiguration abort.
- **support_option_pd_exclude** (Optional, Boolean)
Request prefix exclude option in reconfigure message
Request prefix exclude option in reconfigure message.
- **timeout** (Optional, Number)
Initial timeout value for retry (1..10).
- **token** (Optional, String)
Expand Down Expand Up @@ -248,7 +248,7 @@ The following arguments are supported:
- **allow_no_end_option** (Optional, Boolean)
Allow packets without end-of-option.
- **asymmetric_lease_time** (Optional, Number)
Use a reduced lease time for the client. In seconds (600..86400 seconds).
Use a reduced lease time for the client (600..86400 seconds).
- **bootp_support** (Optional, Boolean)
Allow processing of bootp requests.
- **client_discover_match** (Optional, String)
Expand Down Expand Up @@ -298,7 +298,7 @@ The following arguments are supported:
- **asymmetric_prefix_lease_time** (Optional, Number)
Use a reduced prefix lease time for the client. In seconds (600..86400 seconds).
- **client_negotiation_match_incoming_interface** (Optional, Boolean)
Use incoming interface match criteria for SOLICIT PDU
Use incoming interface match criteria for SOLICIT PDU.
- **delay_advertise_based_on** (Optional, Block Set)
For each combination of block arguments, filter options for dhcp-server.
- **option** (Required, String)
Expand Down Expand Up @@ -328,7 +328,7 @@ The following arguments are supported:
- **process_inform** (Optional, Boolean)
Process INFORM PDUs.
- **process_inform_pool** (Optional, String)
Pool name for family inet.
Pool name for family inet6.
- **protocol_attributes** (Optional, String)
DHCPv6 attributes to use as defined under access protocol-attributes.
- **rapid_commit** (Optional, Boolean)
Expand Down
12 changes: 6 additions & 6 deletions internal/junos/netconf_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ type rpcGetSystemInformationReply struct {
}

type rpcSystemInformation struct {
HardwareModel string `xml:"hardware-model"`
OsName string `xml:"os-name"`
OsVersion string `xml:"os-version"`
SerialNumber string `xml:"serial-number"`
HostName string `xml:"host-name"`
ClusterNode *bool `xml:"cluster-node"`
HardwareModel string `xml:"hardware-model"`
OSName string `xml:"os-name"`
OSVersion string `xml:"os-version"`
SerialNumber string `xml:"serial-number"`
HostName string `xml:"host-name"`
ClusterNode *struct{} `xml:"cluster-node"`
}

func (i rpcSystemInformation) NotCompatibleMsg() string {
Expand Down
142 changes: 142 additions & 0 deletions internal/providerfwk/data_source_system_information.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package providerfwk

import (
"context"

"github.com/jeremmfr/terraform-provider-junos/internal/junos"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &systemInformationDataSource{}
_ datasource.DataSourceWithConfigure = &systemInformationDataSource{}
)

type systemInformationDataSource struct {
client *junos.Client
}

func (dsc *systemInformationDataSource) typeName() string {
return providerName + "_system_information"
}

func (dsc *systemInformationDataSource) junosClient() *junos.Client {
return dsc.client
}

func newSystemInformationDataSource() datasource.DataSource {
return &systemInformationDataSource{}
}

func (dsc *systemInformationDataSource) Metadata(
_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse,
) {
resp.TypeName = dsc.typeName()
}

func (dsc *systemInformationDataSource) Configure(
ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse,
) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}
client, ok := req.ProviderData.(*junos.Client)
if !ok {
unexpectedDataSourceConfigureType(ctx, req, resp)

return
}
dsc.client = client
}

func (dsc *systemInformationDataSource) Schema(
_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Description: "Get information of the Junos device system information.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
Description: "Hostname of the Junos device or `Null-Hostname` if not set.",
},
"hardware_model": schema.StringAttribute{
Computed: true,
Description: "Type of hardware/software of Junos device.",
},
"os_name": schema.StringAttribute{
Computed: true,
Description: "Operating system name of Junos.",
},
"os_version": schema.StringAttribute{
Computed: true,
Description: "Software version of Junos.",
},
"serial_number": schema.StringAttribute{
Computed: true,
Description: "Serial number of the device.",
},
"cluster_node": schema.BoolAttribute{
Computed: true,
Description: "Boolean flag that indicates if device is part of a cluster or not.",
},
},
}
}

type systemInformationDataSourceData struct {
ID types.String `tfsdk:"id"`
HardwareModel types.String `tfsdk:"hardware_model"`
OSName types.String `tfsdk:"os_name"`
OSVersion types.String `tfsdk:"os_version"`
SerialNumber types.String `tfsdk:"serial_number"`
ClusterNode types.Bool `tfsdk:"cluster_node"`

hostName string `tfsdk:"-"`
}

func (dsc *systemInformationDataSource) Read(
ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse,
) {
var data systemInformationDataSourceData

var _ dataSourceDataReadWithoutArg = &data
defaultDataSourceRead(
ctx,
dsc,
nil,
&data,
resp,
)
}

func (dscData *systemInformationDataSourceData) fillID() {
if v := dscData.hostName; v != "" {
dscData.ID = types.StringValue(v)
} else {
dscData.ID = types.StringValue("Null-Hostname")
}
}

func (dscData *systemInformationDataSourceData) read(
_ context.Context, junSess *junos.Session,
) error {
dscData.hostName = junSess.SystemInformation.HostName
dscData.HardwareModel = types.StringValue(junSess.SystemInformation.HardwareModel)
dscData.OSName = types.StringValue(junSess.SystemInformation.OSName)
dscData.OSVersion = types.StringValue(junSess.SystemInformation.OSVersion)
dscData.SerialNumber = types.StringValue(junSess.SystemInformation.SerialNumber)

// Pointer will be nil if the tag does not exist
if junSess.SystemInformation.ClusterNode != nil {
dscData.ClusterNode = types.BoolValue(true)
} else {
dscData.ClusterNode = types.BoolValue(false)
}

return nil
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package providersdk_test
package providerfwk_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccDataSourceSystemInformation_basic(t *testing.T) {
Expand All @@ -12,8 +13,9 @@ func TestAccDataSourceSystemInformation_basic(t *testing.T) {
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccSystemInformationConfig(),
ConfigDirectory: config.TestStepDirectory(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.junos_system_information.test", "id"),
resource.TestCheckResourceAttrSet("data.junos_system_information.test", "hardware_model"),
resource.TestCheckResourceAttrSet("data.junos_system_information.test", "os_name"),
resource.TestCheckResourceAttrSet("data.junos_system_information.test", "os_version"),
Expand All @@ -24,9 +26,3 @@ func TestAccDataSourceSystemInformation_basic(t *testing.T) {
},
})
}

func testAccSystemInformationConfig() string {
return `
data "junos_system_information" "test" {}
`
}
3 changes: 3 additions & 0 deletions internal/providerfwk/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (p *junosProvider) DataSources(_ context.Context) []func() datasource.DataS
newRoutesDataSource,
newRoutingInstanceDataSource,
newSecurityZoneDataSource,
newSystemInformationDataSource,
}
}

Expand Down Expand Up @@ -329,8 +330,10 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource
newSystemResource,
newSystemLoginClassResource,
newSystemLoginUserResource,
newSystemNtpServerResource,
newSystemRadiusServerResource,
newSystemRootAuthenticationResource,
newSystemServicesDhcpLocalserverGroupResource,
newSystemSyslogFileResource,
newSystemSyslogHostResource,
newSystemSyslogUserResource,
Expand Down
4 changes: 2 additions & 2 deletions internal/providerfwk/resource_bridge_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ type bridgeDomainConfig struct {
Vxlan *bridgeDomainBlockVxlanConfig `tfsdk:"vxlan"`
}

func (rscConfig *bridgeDomainConfig) isEmpty() bool {
return tfdata.CheckBlockIsEmpty(rscConfig)
func (config *bridgeDomainConfig) isEmpty() bool {
return tfdata.CheckBlockIsEmpty(config)
}

type bridgeDomainBlockVxlan struct {
Expand Down
Loading

0 comments on commit 4b564b9

Please sign in to comment.