Skip to content

Commit 12f337b

Browse files
authored
fix(instance_server): update volume fields (#2006)
1 parent 32c8c93 commit 12f337b

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/nats-io/jwt/v2 v2.4.1
1717
github.com/nats-io/nats.go v1.26.0
1818
github.com/robfig/cron/v3 v3.0.1
19-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230526161530-cf508019231d
19+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230619154501-6a12f2ddaa47
2020
github.com/stretchr/testify v1.8.4
2121
)
2222

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
253253
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
254254
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
255255
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
256-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230526161530-cf508019231d h1:qeI25+qrQ5MQaMFS2RgmAeAwUSWZSeYy5eYHnmW8vpk=
257-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230526161530-cf508019231d/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
256+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230619154501-6a12f2ddaa47 h1:eGARFgFhRDgxFF6QwimHe+MV21xhuPKLPNhJyML3JkA=
257+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230619154501-6a12f2ddaa47/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
258258
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
259259
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
260260
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

scaleway/helpers_instance.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func validateLocalVolumeSizes(volumes map[string]*instance.VolumeServerTemplate,
214214
// Calculate local volume total size.
215215
var localVolumeTotalSize scw.Size
216216
for _, volume := range volumes {
217-
if volume.VolumeType == instance.VolumeVolumeTypeLSSD {
218-
localVolumeTotalSize += volume.Size
217+
if volume.VolumeType == instance.VolumeVolumeTypeLSSD && volume.Size != nil {
218+
localVolumeTotalSize += *volume.Size
219219
}
220220
}
221221

@@ -252,15 +252,15 @@ func sanitizeVolumeMap(volumes map[string]*instance.VolumeServerTemplate) map[st
252252
switch {
253253
// If a volume already got an ID it is passed as it to the API without specifying the volume type.
254254
// TODO: Fix once instance accept volume type in the schema validation
255-
case v.ID != "":
255+
case v.ID != nil:
256256
v = &instance.VolumeServerTemplate{
257257
ID: v.ID,
258258
Name: v.Name,
259259
Boot: v.Boot,
260260
}
261261
// For the root volume (index 0) if the size is 0, it is considered as a volume created from an image.
262262
// The size is not passed to the API, so it's computed by the API
263-
case index == "0" && v.Size == 0:
263+
case index == "0" && v.Size == nil:
264264
v = &instance.VolumeServerTemplate{
265265
VolumeType: v.VolumeType,
266266
Boot: v.Boot,

scaleway/resource_instance_server.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -367,24 +367,23 @@ func resourceScalewayInstanceServerCreate(ctx context.Context, d *schema.Resourc
367367
rootVolumeName = newRandomName("vol")
368368
}
369369

370-
var rootVolumeSize scw.Size
370+
var rootVolumeSize *scw.Size
371371
if sizeInput == 0 && rootVolumeType == instance.VolumeVolumeTypeLSSD.String() {
372372
// Compute the rootVolumeSize so it will be valid against the local volume constraints
373373
// It wouldn't be valid if another local volume is added, but in this case
374374
// the user would be informed that it does not fulfill the local volume constraints
375-
rootVolumeSize = serverType.VolumesConstraint.MaxSize
376-
} else {
377-
rootVolumeSize = scw.Size(uint64(sizeInput) * gb)
375+
rootVolumeSize = scw.SizePtr(serverType.VolumesConstraint.MaxSize)
376+
} else if sizeInput > 0 {
377+
rootVolumeSize = scw.SizePtr(scw.Size(uint64(sizeInput) * gb))
378378
}
379379

380380
req.Volumes["0"] = &instance.VolumeServerTemplate{
381-
Name: rootVolumeName,
382-
ID: rootVolumeID,
381+
Name: expandStringPtr(rootVolumeName),
382+
ID: expandStringPtr(rootVolumeID),
383383
VolumeType: instance.VolumeVolumeType(rootVolumeType),
384384
Size: rootVolumeSize,
385-
Boot: *rootVolumeIsBootVolume,
385+
Boot: rootVolumeIsBootVolume,
386386
}
387-
388387
if raw, ok := d.GetOk("additional_volume_ids"); ok {
389388
for i, volumeID := range raw.([]interface{}) {
390389
// We have to get the volume to know whether it is a local or a block volume
@@ -396,10 +395,10 @@ func resourceScalewayInstanceServerCreate(ctx context.Context, d *schema.Resourc
396395
return diag.FromErr(err)
397396
}
398397
req.Volumes[strconv.Itoa(i+1)] = &instance.VolumeServerTemplate{
399-
ID: vol.Volume.ID,
400-
Name: vol.Volume.Name,
398+
ID: &vol.Volume.ID,
399+
Name: &vol.Volume.Name,
401400
VolumeType: vol.Volume.VolumeType,
402-
Size: vol.Volume.Size,
401+
Size: &vol.Volume.Size,
403402
}
404403
}
405404
}
@@ -713,9 +712,9 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
713712

714713
if raw, hasAdditionalVolumes := d.GetOk("additional_volume_ids"); d.HasChanges("additional_volume_ids", "root_volume") {
715714
volumes["0"] = &instance.VolumeServerTemplate{
716-
ID: expandZonedID(d.Get("root_volume.0.volume_id")).ID,
717-
Name: newRandomName("vol"), // name is ignored by the API, any name will work here
718-
Boot: d.Get("root_volume.0.boot").(bool),
715+
ID: scw.StringPtr(expandZonedID(d.Get("root_volume.0.volume_id")).ID),
716+
Name: scw.StringPtr(newRandomName("vol")), // name is ignored by the API, any name will work here
717+
Boot: expandBoolPtr(d.Get("root_volume.0.boot")),
719718
}
720719

721720
if !hasAdditionalVolumes {
@@ -742,8 +741,8 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
742741
}
743742
}
744743
volumes[strconv.Itoa(i+1)] = &instance.VolumeServerTemplate{
745-
ID: expandZonedID(volumeID).ID,
746-
Name: newRandomName("vol"), // name is ignored by the API, any name will work here
744+
ID: scw.StringPtr(expandZonedID(volumeID).ID),
745+
Name: scw.StringPtr(newRandomName("vol")), // name is ignored by the API, any name will work here
747746
}
748747
}
749748

0 commit comments

Comments
 (0)