Skip to content

Commit

Permalink
NTP Server Datasource Implementation (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
RayLiu7 authored Jan 12, 2024
1 parent 7411218 commit 7102fd5
Show file tree
Hide file tree
Showing 10 changed files with 601 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/data-sources/networkpool.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ output "powerscale_networkpool_data_all" {

### Read-Only

- `id` (String) Unique identifier of the ads provider instance.
- `id` (String) Unique identifier of the network pool instance.
- `network_pools_details` (Attributes List) List of Network Pools. (see [below for nested schema](#nestedatt--network_pools_details))

<a id="nestedblock--filter"></a>
Expand Down
102 changes: 102 additions & 0 deletions docs/data-sources/ntpserver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
# Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Mozilla Public License Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://mozilla.org/MPL/2.0/
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

title: "powerscale_ntpserver data source"
linkTitle: "powerscale_ntpserver"
page_title: "powerscale_ntpserver Data Source - terraform-provider-powerscale"
subcategory: ""
description: |-
This datasource is used to query the existing NTP Servers from PowerScale array. The information fetched from this datasource can be used for getting the details or for further processing in resource block. You can use NTP Servers to synchronize the system time
---

# powerscale_ntpserver (Data Source)

This datasource is used to query the existing NTP Servers from PowerScale array. The information fetched from this datasource can be used for getting the details or for further processing in resource block. You can use NTP Servers to synchronize the system time

## Example Usage

```terraform
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
# This Terraform DataSource is used to query the details of existing NTP servers from PowerScale array.
# Returns a list of PowerScale NTP servers based on names specified in the filter block.
data "powerscale_ntpserver" "test" {
filter {
names = ["ntp_server_name_example"]
}
}
# Output value of above block by executing 'terraform output' command
# You can use the the fetched information by the variable data.powerscale_ntpserver.test
output "powerscale_ntpserver" {
value = data.powerscale_ntpserver.test
}
# Returns all PowerScale NTP servers on PowerScale array
data "powerscale_ntpserver" "all" {
}
# Output value of above block by executing 'terraform output' command
# You can use the the fetched information by the variable data.powerscale_ntpserver.all
output "powerscale_ntpserver_data_all" {
value = data.powerscale_ntpserver.all
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `filter` (Block, Optional) (see [below for nested schema](#nestedblock--filter))

### Read-Only

- `id` (String) Unique identifier of the NTP Server instance.
- `ntp_servers_details` (Attributes List) List of NTP Servers. (see [below for nested schema](#nestedatt--ntp_servers_details))

<a id="nestedblock--filter"></a>
### Nested Schema for `filter`

Optional:

- `names` (Set of String) Filter NTP Servers by names.


<a id="nestedatt--ntp_servers_details"></a>
### Nested Schema for `ntp_servers_details`

Read-Only:

- `id` (String) Field ID.
- `key` (String) Key value from key_file that maps to this server.
- `name` (String) NTP server name.
41 changes: 41 additions & 0 deletions examples/data-sources/powerscale_ntpserver/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

# This Terraform DataSource is used to query the details of existing NTP servers from PowerScale array.

# Returns a list of PowerScale NTP servers based on names specified in the filter block.
data "powerscale_ntpserver" "test" {
filter {
names = ["ntp_server_name_example"]
}
}

# Output value of above block by executing 'terraform output' command
# You can use the the fetched information by the variable data.powerscale_ntpserver.test
output "powerscale_ntpserver" {
value = data.powerscale_ntpserver.test
}

# Returns all PowerScale NTP servers on PowerScale array
data "powerscale_ntpserver" "all" {
}

# Output value of above block by executing 'terraform output' command
# You can use the the fetched information by the variable data.powerscale_ntpserver.all
output "powerscale_ntpserver_data_all" {
value = data.powerscale_ntpserver.all
}
30 changes: 30 additions & 0 deletions examples/data-sources/powerscale_ntpserver/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
terraform {
required_providers {
powerscale = {
source = "registry.terraform.io/dell/powerscale"
}
}
}

provider "powerscale" {
username = var.username
password = var.password
endpoint = var.endpoint
insecure = var.insecure
}
16 changes: 16 additions & 0 deletions powerscale/helper/ntp_server_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ import (
"terraform-provider-powerscale/powerscale/models"
)

// GetNtpServers Get a list of NTP Servers.
func GetNtpServers(ctx context.Context, client *client.Client) (*powerscale.V3NtpServers, error) {
ntpServerParams := client.PscaleOpenAPIClient.ProtocolsApi.ListProtocolsv3NtpServers(ctx)
ntpServers, _, err := ntpServerParams.Execute()
return ntpServers, err
}

// NtpServerDetailMapper Does the mapping from response to model.
//
//go:noinline
func NtpServerDetailMapper(ctx context.Context, ntpServer *powerscale.V3NtpServerExtended) (models.NtpServerDetailModel, error) {
model := models.NtpServerDetailModel{}
err := CopyFields(ctx, ntpServer, &model)
return model, err
}

// CreateNtpServer Create a NTP Server.
func CreateNtpServer(ctx context.Context, client *client.Client, ntpServer powerscale.V3NtpServer) (string, error) {
ntpID, _, err := client.PscaleOpenAPIClient.ProtocolsApi.CreateProtocolsv3NtpServer(ctx).V3NtpServer(ntpServer).Execute()
Expand Down
24 changes: 24 additions & 0 deletions powerscale/models/ntp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ package models

import "github.com/hashicorp/terraform-plugin-framework/types"

// NtpServerDataSourceModel describes the data source data model.
type NtpServerDataSourceModel struct {
ID types.String `tfsdk:"id"`
NtpServers []NtpServerDetailModel `tfsdk:"ntp_servers_details"`

// Filters
NtpServerFilter *NtpServerFilterType `tfsdk:"filter"`
}

// NtpServerDetailModel describes the datasource data model.
type NtpServerDetailModel struct {
// Key value from key_file that maps to this server.
Key types.String `tfsdk:"key"`
// NTP server name.
Name types.String `tfsdk:"name"`
// Field ID.
ID types.String `tfsdk:"id"`
}

// NtpServerFilterType describes the filter data model.
type NtpServerFilterType struct {
Names []types.String `tfsdk:"names"`
}

// NtpServerResourceModel describes the resource data model.
type NtpServerResourceModel struct {
// Key value from key_file that maps to this server.
Expand Down
4 changes: 2 additions & 2 deletions powerscale/provider/network_pool_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (d *NetworkPoolDataSource) Schema(ctx context.Context, req datasource.Schem
Description: "This datasource is used to query the existing network pools from PowerScale array. The information fetched from this datasource can be used for getting the details or for further processing in resource block. You can add network interfaces to network pools to associate address ranges with a node or a group of nodes.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "Unique identifier of the ads provider instance.",
MarkdownDescription: "Unique identifier of the ads provider instance.",
Description: "Unique identifier of the network pool instance.",
MarkdownDescription: "Unique identifier of the network pool instance.",
Computed: true,
},
"network_pools_details": schema.ListNestedAttribute{
Expand Down
Loading

0 comments on commit 7102fd5

Please sign in to comment.