Skip to content

Commit 7102fd5

Browse files
authored
NTP Server Datasource Implementation (#111)
1 parent 7411218 commit 7102fd5

File tree

10 files changed

+601
-3
lines changed

10 files changed

+601
-3
lines changed

docs/data-sources/networkpool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ output "powerscale_networkpool_data_all" {
8787

8888
### Read-Only
8989

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

9393
<a id="nestedblock--filter"></a>

docs/data-sources/ntpserver.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
# Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
#
4+
# Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://mozilla.org/MPL/2.0/
9+
#
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
title: "powerscale_ntpserver data source"
18+
linkTitle: "powerscale_ntpserver"
19+
page_title: "powerscale_ntpserver Data Source - terraform-provider-powerscale"
20+
subcategory: ""
21+
description: |-
22+
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
23+
---
24+
25+
# powerscale_ntpserver (Data Source)
26+
27+
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
28+
29+
## Example Usage
30+
31+
```terraform
32+
/*
33+
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
34+
35+
Licensed under the Mozilla Public License Version 2.0 (the "License");
36+
you may not use this file except in compliance with the License.
37+
You may obtain a copy of the License at
38+
39+
http://mozilla.org/MPL/2.0/
40+
41+
42+
Unless required by applicable law or agreed to in writing, software
43+
distributed under the License is distributed on an "AS IS" BASIS,
44+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45+
See the License for the specific language governing permissions and
46+
limitations under the License.
47+
*/
48+
49+
# This Terraform DataSource is used to query the details of existing NTP servers from PowerScale array.
50+
51+
# Returns a list of PowerScale NTP servers based on names specified in the filter block.
52+
data "powerscale_ntpserver" "test" {
53+
filter {
54+
names = ["ntp_server_name_example"]
55+
}
56+
}
57+
58+
# Output value of above block by executing 'terraform output' command
59+
# You can use the the fetched information by the variable data.powerscale_ntpserver.test
60+
output "powerscale_ntpserver" {
61+
value = data.powerscale_ntpserver.test
62+
}
63+
64+
# Returns all PowerScale NTP servers on PowerScale array
65+
data "powerscale_ntpserver" "all" {
66+
}
67+
68+
# Output value of above block by executing 'terraform output' command
69+
# You can use the the fetched information by the variable data.powerscale_ntpserver.all
70+
output "powerscale_ntpserver_data_all" {
71+
value = data.powerscale_ntpserver.all
72+
}
73+
```
74+
75+
<!-- schema generated by tfplugindocs -->
76+
## Schema
77+
78+
### Optional
79+
80+
- `filter` (Block, Optional) (see [below for nested schema](#nestedblock--filter))
81+
82+
### Read-Only
83+
84+
- `id` (String) Unique identifier of the NTP Server instance.
85+
- `ntp_servers_details` (Attributes List) List of NTP Servers. (see [below for nested schema](#nestedatt--ntp_servers_details))
86+
87+
<a id="nestedblock--filter"></a>
88+
### Nested Schema for `filter`
89+
90+
Optional:
91+
92+
- `names` (Set of String) Filter NTP Servers by names.
93+
94+
95+
<a id="nestedatt--ntp_servers_details"></a>
96+
### Nested Schema for `ntp_servers_details`
97+
98+
Read-Only:
99+
100+
- `id` (String) Field ID.
101+
- `key` (String) Key value from key_file that maps to this server.
102+
- `name` (String) NTP server name.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
# This Terraform DataSource is used to query the details of existing NTP servers from PowerScale array.
19+
20+
# Returns a list of PowerScale NTP servers based on names specified in the filter block.
21+
data "powerscale_ntpserver" "test" {
22+
filter {
23+
names = ["ntp_server_name_example"]
24+
}
25+
}
26+
27+
# Output value of above block by executing 'terraform output' command
28+
# You can use the the fetched information by the variable data.powerscale_ntpserver.test
29+
output "powerscale_ntpserver" {
30+
value = data.powerscale_ntpserver.test
31+
}
32+
33+
# Returns all PowerScale NTP servers on PowerScale array
34+
data "powerscale_ntpserver" "all" {
35+
}
36+
37+
# Output value of above block by executing 'terraform output' command
38+
# You can use the the fetched information by the variable data.powerscale_ntpserver.all
39+
output "powerscale_ntpserver_data_all" {
40+
value = data.powerscale_ntpserver.all
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
terraform {
18+
required_providers {
19+
powerscale = {
20+
source = "registry.terraform.io/dell/powerscale"
21+
}
22+
}
23+
}
24+
25+
provider "powerscale" {
26+
username = var.username
27+
password = var.password
28+
endpoint = var.endpoint
29+
insecure = var.insecure
30+
}

powerscale/helper/ntp_server_helper.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ import (
2424
"terraform-provider-powerscale/powerscale/models"
2525
)
2626

27+
// GetNtpServers Get a list of NTP Servers.
28+
func GetNtpServers(ctx context.Context, client *client.Client) (*powerscale.V3NtpServers, error) {
29+
ntpServerParams := client.PscaleOpenAPIClient.ProtocolsApi.ListProtocolsv3NtpServers(ctx)
30+
ntpServers, _, err := ntpServerParams.Execute()
31+
return ntpServers, err
32+
}
33+
34+
// NtpServerDetailMapper Does the mapping from response to model.
35+
//
36+
//go:noinline
37+
func NtpServerDetailMapper(ctx context.Context, ntpServer *powerscale.V3NtpServerExtended) (models.NtpServerDetailModel, error) {
38+
model := models.NtpServerDetailModel{}
39+
err := CopyFields(ctx, ntpServer, &model)
40+
return model, err
41+
}
42+
2743
// CreateNtpServer Create a NTP Server.
2844
func CreateNtpServer(ctx context.Context, client *client.Client, ntpServer powerscale.V3NtpServer) (string, error) {
2945
ntpID, _, err := client.PscaleOpenAPIClient.ProtocolsApi.CreateProtocolsv3NtpServer(ctx).V3NtpServer(ntpServer).Execute()

powerscale/models/ntp_server.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ package models
1919

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

22+
// NtpServerDataSourceModel describes the data source data model.
23+
type NtpServerDataSourceModel struct {
24+
ID types.String `tfsdk:"id"`
25+
NtpServers []NtpServerDetailModel `tfsdk:"ntp_servers_details"`
26+
27+
// Filters
28+
NtpServerFilter *NtpServerFilterType `tfsdk:"filter"`
29+
}
30+
31+
// NtpServerDetailModel describes the datasource data model.
32+
type NtpServerDetailModel struct {
33+
// Key value from key_file that maps to this server.
34+
Key types.String `tfsdk:"key"`
35+
// NTP server name.
36+
Name types.String `tfsdk:"name"`
37+
// Field ID.
38+
ID types.String `tfsdk:"id"`
39+
}
40+
41+
// NtpServerFilterType describes the filter data model.
42+
type NtpServerFilterType struct {
43+
Names []types.String `tfsdk:"names"`
44+
}
45+
2246
// NtpServerResourceModel describes the resource data model.
2347
type NtpServerResourceModel struct {
2448
// Key value from key_file that maps to this server.

powerscale/provider/network_pool_datasource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func (d *NetworkPoolDataSource) Schema(ctx context.Context, req datasource.Schem
5858
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.",
5959
Attributes: map[string]schema.Attribute{
6060
"id": schema.StringAttribute{
61-
Description: "Unique identifier of the ads provider instance.",
62-
MarkdownDescription: "Unique identifier of the ads provider instance.",
61+
Description: "Unique identifier of the network pool instance.",
62+
MarkdownDescription: "Unique identifier of the network pool instance.",
6363
Computed: true,
6464
},
6565
"network_pools_details": schema.ListNestedAttribute{

0 commit comments

Comments
 (0)