-
Notifications
You must be signed in to change notification settings - Fork 21
/
data_source_dataplatform_node_pools.go
172 lines (163 loc) · 5.49 KB
/
data_source_dataplatform_node_pools.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package ionoscloud
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
dataplatform "github.com/ionos-cloud/sdk-go-dataplatform"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
dataplatformService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dataplatform"
)
func dataSourceDataplatformNodePools() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceNodePoolsRead,
Schema: map[string]*schema.Schema{
"cluster_id": {
Type: schema.TypeString,
Required: true,
Description: "The UUID of an existing Dataplatform cluster",
ValidateDiagFunc: validation.ToDiagFunc(validation.IsUUID),
},
"name": {
Type: schema.TypeString,
Description: "The name of your node pool.",
Optional: true,
},
"partial_match": {
Type: schema.TypeBool,
Description: "Whether partial matching is allowed or not when using name argument.",
Default: false,
Optional: true,
},
"node_pools": {
Type: schema.TypeList,
Description: "list of node pools",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "The name of your node pool.",
Computed: true,
},
"version": {
Type: schema.TypeString,
Description: "The version of the Data Platform.",
Computed: true,
},
"datacenter_id": {
Type: schema.TypeString,
Description: "The UUID of the virtual data center (VDC) in which the node pool is provisioned",
Computed: true,
},
"node_count": {
Type: schema.TypeInt,
Description: "The number of nodes that make up the node pool.",
Computed: true,
},
"cpu_family": {
Type: schema.TypeString,
Description: "A valid CPU family name or `AUTO` if the platform shall choose the best fitting option. Available CPU architectures can be retrieved from the datacenter resource.",
Computed: true,
},
"cores_count": {
Type: schema.TypeInt,
Description: "The number of CPU cores per node.",
Computed: true,
},
"ram_size": {
Type: schema.TypeInt,
Description: "The RAM size for one node in MB. Must be set in multiples of 1024 MB, with a minimum size is of 2048 MB.",
Computed: true,
},
"availability_zone": {
Type: schema.TypeString,
Description: "The availability zone of the virtual datacenter region where the node pool resources should be provisioned.",
Computed: true,
},
"storage_type": {
Type: schema.TypeString,
Description: "The type of hardware for the volume.",
Computed: true,
},
"storage_size": {
Type: schema.TypeInt,
Description: "The size of the volume in GB. The size must be greater than 10GB.",
Computed: true,
},
"maintenance_window": {
Type: schema.TypeList,
Description: "Starting time of a weekly 4 hour-long window, during which maintenance might occur in hh:mm:ss format",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"time": {
Type: schema.TypeString,
Description: "Time at which the maintenance should start. Must conform to the 'HH:MM:SS' 24-hour format.",
Computed: true,
},
"day_of_the_week": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"labels": {
Type: schema.TypeMap,
Description: "Key-value pairs attached to the node pool resource as kubernetes labels",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"annotations": {
Type: schema.TypeMap,
Description: "Key-value pairs attached to node pool resource as kubernetes annotations",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
Timeouts: &resourceDefaultTimeouts,
}
}
func dataSourceNodePoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(services.SdkBundle).DataplatformClient
clusterId := d.Get("cluster_id").(string)
nameValue, nameOk := d.GetOk("name")
name := nameValue.(string)
var results []dataplatform.NodePoolResponseData
var err diag.Diagnostics
if nameOk {
results, err = filterNodePools(ctx, d, client, name)
if err != nil {
return err
}
} else {
nodePools, _, err := client.ListNodePools(ctx, clusterId)
if err != nil {
diags := diag.FromErr(fmt.Errorf("an error occurred while fetching Dataplatform NodePools: %w", err))
return diags
}
if nodePools.Items != nil {
results = *nodePools.Items
}
}
if results == nil || len(results) == 0 {
err := fmt.Errorf("no Dataplatform NodePool found under cluster %s", clusterId)
if nameOk {
err = fmt.Errorf("%w with the specified name = %s", err, name)
}
return diag.FromErr(err)
}
if err = dataplatformService.SetNodePoolsData(d, results); err != nil {
return err
}
return nil
}