Skip to content

Commit ed45b4b

Browse files
Codelaxremyleone
andauthored
chore: bump marketplace api to v2 (#1697)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 639237d commit ed45b4b

File tree

45 files changed

+37536
-150664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+37536
-150664
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/hashicorp/terraform-plugin-log v0.7.0
1414
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
1515
github.com/robfig/cron/v3 v3.0.1
16-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.11
16+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.12.0.20230117165151-13d6966bd791
1717
github.com/stretchr/testify v1.8.1
1818
)
1919

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
227227
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
228228
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
229229
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
230-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.11 h1:aBAUkfUmdpAs/7Yeq6T3inWFaKPxDmdkLMjbktx7qCs=
231-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.11/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
230+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.12.0.20230117165151-13d6966bd791 h1:bn1ri6xgpMyDnfq2ZS17uXDduGvPBsJQaxyB+2IRnzs=
231+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.12.0.20230117165151-13d6966bd791/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
232232
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
233233
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
234234
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=

scaleway/data_source_marketplace_image.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v1"
8+
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v2"
99
"github.com/scaleway/scaleway-sdk-go/scw"
1010
)
1111

@@ -35,7 +35,7 @@ func dataSourceScalewayMarketplaceImageRead(ctx context.Context, d *schema.Resou
3535
return diag.FromErr(err)
3636
}
3737

38-
imageID, err := marketplaceAPI.GetLocalImageIDByLabel(&marketplace.GetLocalImageIDByLabelRequest{
38+
image, err := marketplaceAPI.GetLocalImageByLabel(&marketplace.GetLocalImageByLabelRequest{
3939
ImageLabel: d.Get("label").(string),
4040
CommercialType: d.Get("instance_type").(string),
4141
Zone: zone,
@@ -44,7 +44,7 @@ func dataSourceScalewayMarketplaceImageRead(ctx context.Context, d *schema.Resou
4444
return diag.FromErr(err)
4545
}
4646

47-
zonedID := datasourceNewZonedID(imageID, zone)
47+
zonedID := datasourceNewZonedID(image.ID, zone)
4848
d.SetId(zonedID)
4949
_ = d.Set("zone", zone)
5050
_ = d.Set("label", d.Get("label"))

scaleway/helpers_instance.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"sort"
77
"strconv"
8+
"strings"
89
"time"
910

1011
"github.com/dustin/go-humanize"
@@ -584,3 +585,7 @@ func flattenInstanceImageExtraVolumes(volumes map[string]*instance.Volume, zone
584585
}
585586
return volumesFlat
586587
}
588+
589+
func formatImageLabel(imageUUID string) string {
590+
return strings.ReplaceAll(imageUUID, "-", "_")
591+
}

scaleway/helpers_marketplace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scaleway
22

33
import (
44
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
5-
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v1"
5+
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v2"
66
"github.com/scaleway/scaleway-sdk-go/scw"
77
)
88

scaleway/resource_instance_server.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1616
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
17-
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v1"
17+
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v2"
1818
"github.com/scaleway/scaleway-sdk-go/scw"
1919
scwvalidation "github.com/scaleway/scaleway-sdk-go/validation"
2020
)
@@ -288,15 +288,19 @@ func resourceScalewayInstanceServerCreate(ctx context.Context, d *schema.Resourc
288288

289289
imageUUID := expandID(d.Get("image"))
290290
if imageUUID != "" && !scwvalidation.IsUUID(imageUUID) {
291+
// Replace dashes with underscores ubuntu-focal -> ubuntu_focal
292+
imageLabel := formatImageLabel(imageUUID)
293+
291294
marketPlaceAPI := marketplace.NewAPI(meta.(*Meta).scwClient)
292-
imageUUID, err = marketPlaceAPI.GetLocalImageIDByLabel(&marketplace.GetLocalImageIDByLabelRequest{
295+
image, err := marketPlaceAPI.GetLocalImageByLabel(&marketplace.GetLocalImageByLabelRequest{
293296
CommercialType: commercialType,
294297
Zone: zone,
295-
ImageLabel: imageUUID,
298+
ImageLabel: imageLabel,
296299
})
297300
if err != nil {
298-
return diag.FromErr(fmt.Errorf("could not get image '%s': %s", newZonedID(zone, imageUUID), err))
301+
return diag.FromErr(fmt.Errorf("could not get image '%s': %s", newZonedID(zone, imageLabel), err))
299302
}
303+
imageUUID = image.ID
300304
}
301305

302306
req := &instance.CreateServerRequest{

0 commit comments

Comments
 (0)