@@ -30,52 +30,111 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
30
30
Schema : map [string ]* schema.Schema {
31
31
"service_name" : {
32
32
Type : schema .TypeString ,
33
+ Description : "Service name" ,
33
34
Required : true ,
34
35
ForceNew : true ,
35
36
DefaultFunc : schema .EnvDefaultFunc ("OVH_CLOUD_PROJECT_SERVICE" , nil ),
36
37
},
37
38
"kube_id" : {
38
- Type : schema .TypeString ,
39
- Required : true ,
40
- ForceNew : true ,
39
+ Type : schema .TypeString ,
40
+ Description : "Kube ID" ,
41
+ Required : true ,
42
+ ForceNew : true ,
41
43
},
42
- "name" : {
43
- Type : schema .TypeString ,
44
- Optional : true ,
45
- ForceNew : true ,
44
+ "autoscale" : {
45
+ Type : schema .TypeBool ,
46
+ Description : "Enable auto-scaling for the pool" ,
47
+ Optional : true ,
48
+ ForceNew : true ,
49
+ Default : "false" ,
50
+ },
51
+ "anti_affinity" : {
52
+ Type : schema .TypeBool ,
53
+ Description : "Enable anti affinity groups for nodes in the pool" ,
54
+ Optional : true ,
55
+ ForceNew : true ,
56
+ Default : "false" ,
46
57
},
47
58
"flavor_name" : {
48
- Type : schema .TypeString ,
49
- Required : true ,
50
- ForceNew : true ,
59
+ Type : schema .TypeString ,
60
+ Description : "Flavor name" ,
61
+ Required : true ,
62
+ ForceNew : true ,
51
63
},
52
64
"desired_nodes" : {
53
- Type : schema .TypeInt ,
54
- Optional : true ,
65
+ Type : schema .TypeInt ,
66
+ Description : "Number of nodes you desire in the pool" ,
67
+ Optional : true ,
68
+ },
69
+ "name" : {
70
+ Type : schema .TypeString ,
71
+ Description : "NodePool resource name" ,
72
+ Optional : true ,
73
+ ForceNew : true ,
55
74
},
56
75
"max_nodes" : {
57
- Type : schema .TypeInt ,
58
- Optional : true ,
76
+ Type : schema .TypeInt ,
77
+ Description : "Number of nodes you desire in the pool" ,
78
+ Optional : true ,
59
79
},
60
80
"min_nodes" : {
61
- Type : schema .TypeInt ,
62
- Optional : true ,
81
+ Type : schema .TypeInt ,
82
+ Description : "Number of nodes you desire in the pool" ,
83
+ Optional : true ,
63
84
},
64
85
"monthly_billed" : {
65
- Type : schema .TypeBool ,
66
- Optional : true ,
67
- ForceNew : true ,
68
- Default : "false" ,
86
+ Type : schema .TypeBool ,
87
+ Description : "Enable monthly billing on all nodes in the pool" ,
88
+ Optional : true ,
89
+ ForceNew : true ,
90
+ Default : "false" ,
69
91
},
70
- "anti_affinity" : {
71
- Type : schema .TypeBool ,
72
- Optional : true ,
73
- ForceNew : true ,
74
- Default : "false" ,
92
+
93
+ // computed
94
+ "available_nodes" : {
95
+ Type : schema .TypeInt ,
96
+ Description : "Number of nodes which are actually ready in the pool" ,
97
+ Computed : true ,
98
+ },
99
+ "created_at" : {
100
+ Type : schema .TypeString ,
101
+ Description : "Creation date" ,
102
+ Computed : true ,
103
+ },
104
+ "current_nodes" : {
105
+ Type : schema .TypeInt ,
106
+ Description : "Number of nodes present in the pool" ,
107
+ Computed : true ,
108
+ },
109
+ "flavor" : {
110
+ Type : schema .TypeString ,
111
+ Description : "Flavor name" ,
112
+ Computed : true ,
113
+ },
114
+ "project_id" : {
115
+ Type : schema .TypeString ,
116
+ Description : "Project id" ,
117
+ Computed : true ,
118
+ },
119
+ "size_status" : {
120
+ Type : schema .TypeString ,
121
+ Description : "Status describing the state between number of nodes wanted and available ones" ,
122
+ Computed : true ,
75
123
},
76
124
"status" : {
77
- Type : schema .TypeString ,
78
- Computed : true ,
125
+ Type : schema .TypeString ,
126
+ Description : "Current status" ,
127
+ Computed : true ,
128
+ },
129
+ "up_to_date_nodes" : {
130
+ Type : schema .TypeInt ,
131
+ Description : "Number of nodes with latest version installed in the pool" ,
132
+ Computed : true ,
133
+ },
134
+ "updated_at" : {
135
+ Type : schema .TypeString ,
136
+ Description : "Last update date" ,
137
+ Computed : true ,
79
138
},
80
139
},
81
140
}
@@ -87,15 +146,7 @@ func resourceCloudProjectKubeNodePoolCreate(d *schema.ResourceData, meta interfa
87
146
kubeId := d .Get ("kube_id" ).(string )
88
147
89
148
endpoint := fmt .Sprintf ("/cloud/project/%s/kube/%s/nodepool" , serviceName , kubeId )
90
- params := & CloudProjectKubeNodePoolCreateOpts {
91
- Name : d .Get ("name" ).(string ),
92
- FlavorName : d .Get ("flavor_name" ).(string ),
93
- DesiredNodes : d .Get ("desired_nodes" ).(int ),
94
- MaxNodes : d .Get ("max_nodes" ).(int ),
95
- MinNodes : d .Get ("min_nodes" ).(int ),
96
- MonthlyBilled : d .Get ("monthly_billed" ).(bool ),
97
- AntiAffinity : d .Get ("anti_affinity" ).(bool ),
98
- }
149
+ params := (& CloudProjectKubeNodePoolCreateOpts {}).FromResource (d )
99
150
res := & CloudProjectKubeNodePoolResponse {}
100
151
101
152
log .Printf ("[DEBUG] Will create nodepool: %+v" , params )
@@ -137,15 +188,13 @@ func resourceCloudProjectKubeNodePoolRead(d *schema.ResourceData, meta interface
137
188
return helpers .CheckDeleted (d , err , endpoint )
138
189
}
139
190
140
- d .SetId (res .Id )
141
- d .Set ("name" , res .Name )
142
- d .Set ("flavor_name" , res .Flavor )
143
- d .Set ("desired_nodes" , res .DesiredNodes )
144
- d .Set ("max_nodes" , res .MaxNodes )
145
- d .Set ("min_nodes" , res .MinNodes )
146
- d .Set ("monthly_billed" , res .MonthlyBilled )
147
- d .Set ("anti_affinity" , res .AntiAffinity )
148
- d .Set ("status" , res .Status )
191
+ for k , v := range res .ToMap () {
192
+ if k != "id" {
193
+ d .Set (k , v )
194
+ } else {
195
+ d .SetId (fmt .Sprint (v ))
196
+ }
197
+ }
149
198
150
199
log .Printf ("[DEBUG] Read nodepool: %+v" , res )
151
200
return nil
@@ -157,11 +206,7 @@ func resourceCloudProjectKubeNodePoolUpdate(d *schema.ResourceData, meta interfa
157
206
kubeId := d .Get ("kube_id" ).(string )
158
207
159
208
endpoint := fmt .Sprintf ("/cloud/project/%s/kube/%s/nodepool/%s" , serviceName , kubeId , d .Id ())
160
- params := & CloudProjectKubeNodePoolUpdateOpts {
161
- DesiredNodes : d .Get ("desired_nodes" ).(int ),
162
- MaxNodes : d .Get ("max_nodes" ).(int ),
163
- MinNodes : d .Get ("min_nodes" ).(int ),
164
- }
209
+ params := (& CloudProjectKubeNodePoolUpdateOpts {}).FromResource (d )
165
210
166
211
log .Printf ("[DEBUG] Will update nodepool: %+v" , params )
167
212
err := config .OVHClient .Put (endpoint , params , nil )
@@ -205,7 +250,7 @@ func resourceCloudProjectKubeNodePoolDelete(d *schema.ResourceData, meta interfa
205
250
}
206
251
207
252
func cloudProjectKubeNodePoolExists (serviceName , kubeId , id string , client * ovh.Client ) error {
208
- res := & CloudProjectKubeResponse {}
253
+ res := & CloudProjectKubeNodePoolResponse {}
209
254
210
255
endpoint := fmt .Sprintf ("/cloud/project/%s/kube/%s/nodepool/%s" , serviceName , kubeId , id )
211
256
return client .Get (endpoint , res )
@@ -216,7 +261,7 @@ func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeI
216
261
Pending : []string {"INSTALLING" , "UPDATING" , "REDEPLOYING" , "RESIZING" },
217
262
Target : []string {"READY" },
218
263
Refresh : func () (interface {}, string , error ) {
219
- res := & CloudProjectKubeResponse {}
264
+ res := & CloudProjectKubeNodePoolResponse {}
220
265
endpoint := fmt .Sprintf ("/cloud/project/%s/kube/%s/nodepool/%s" , serviceName , kubeId , id )
221
266
err := client .Get (endpoint , res )
222
267
if err != nil {
@@ -239,7 +284,7 @@ func waitForCloudProjectKubeNodePoolDeleted(client *ovh.Client, serviceName, kub
239
284
Pending : []string {"DELETING" },
240
285
Target : []string {"DELETED" },
241
286
Refresh : func () (interface {}, string , error ) {
242
- res := & CloudProjectKubeResponse {}
287
+ res := & CloudProjectKubeNodePoolResponse {}
243
288
endpoint := fmt .Sprintf ("/cloud/project/%s/kube/%s/nodepool/%s" , serviceName , kubeId , id )
244
289
err := client .Get (endpoint , res )
245
290
if err != nil {
0 commit comments