Skip to content

Commit 108d512

Browse files
jremy42remyleone
andauthored
chore: migrate webhosting to v1 (#2939)
* chore: migrate webhosting to v1 * bump sdk go * update test * bump sdk go * fix doc * fix lint * fix doc * fix lint --------- Co-authored-by: Rémy Léone <[email protected]>
1 parent ac3efa9 commit 108d512

16 files changed

+913
-1037
lines changed

docs/data-sources/webhosting_offer.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Gets information about a webhosting offer.
1313
# Get info by offer name
1414
data "scaleway_webhosting_offer" "by_name" {
1515
name = "performance"
16+
control_panel = "Cpanel"
1617
}
1718
1819
# Get info by offer id
@@ -25,6 +26,8 @@ data "scaleway_webhosting_offer" "by_id" {
2526

2627
- `name` - (Optional) The offer name. Only one of `name` and `offer_id` should be specified.
2728

29+
- `control_panel` - (Optional) Name of the control panel (Cpanel or Plesk). This argument is only used when `offer_id` is not specified.
30+
2831
- `offer_id` - (Optional) The offer id. Only one of `name` and `offer_id` should be specified.
2932

3033
- `region` - (Defaults to [provider](../index.md#zone) `region`) The [region](../guides/regions_and_zones.md#zones) in which offer exists.
@@ -34,7 +37,7 @@ data "scaleway_webhosting_offer" "by_id" {
3437
In addition to all arguments above, the following attributes are exported:
3538

3639
- `billing_operation_path` - The unique identifier used for billing.
37-
- `product` - The offer product.
40+
- `product` - (deprecated) The offer product.
3841
- `option` - The product option.
3942
- `email_accounts_quota` - The quota of email accounts.
4043
- `email_storage_quota` - The quota of email storage.
@@ -43,5 +46,23 @@ In addition to all arguments above, the following attributes are exported:
4346
- `support_included` - If support is included.
4447
- `v_cpu` - The number of cores.
4548
- `ram` - The capacity of the memory in GB.
49+
- `offer` - The detailed offer of the hosting.
50+
- `id` - The unique identifier of the offer.
51+
- `name` - The name of the offer.
52+
- `billing_operation_path` - The billing operation identifier for the offer.
53+
- `available` - Indicates if the offer is available.
54+
- `control_panel_name` - The name of the control panel (e.g., Cpanel or Plesk).
55+
- `end_of_life` - Indicates if the offer is deprecated or no longer supported.
56+
- `quota_warning` - Warning information regarding quota limitations.
57+
- `price` - The price of the offer.
58+
- `options` - A list of available options for the offer:
59+
- `id` - The unique identifier of the option.
60+
- `name` - The name of the option.
61+
- `billing_operation_path` - The billing operation identifier for the option.
62+
- `min_value` - The minimum value for the option.
63+
- `current_value` - The current value set for the option.
64+
- `max_value` - The maximum allowed value for the option.
65+
- `quota_warning` - Warning information regarding quota limitations for the option.
66+
- `price` - The price of the option.
4667
- `price` - The offer price.
4768

docs/resources/webhosting.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ For more information, see the [API documentation](https://www.scaleway.com/en/de
1313
```terraform
1414
data "scaleway_webhosting_offer" "by_name" {
1515
name = "lite"
16+
control_panel = "Cpanel"
1617
}
1718
1819
resource "scaleway_webhosting" "main" {
@@ -57,7 +58,7 @@ In addition to all arguments above, the following attributes are exported:
5758
- `dashboard` - The URL of the Dashboard.
5859
- `webmail` - The URL of the Webmail interface.
5960
- `username` - The main hosting cPanel username.
60-
- `organization_id` - The organization ID the hosting is associated with.
61+
- `organization_id` - (Deprecated) The organization ID the hosting is associated with.
6162

6263
## Import
6364

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/nats-io/jwt/v2 v2.7.3
2727
github.com/nats-io/nats.go v1.38.0
2828
github.com/robfig/cron/v3 v3.0.1
29-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250206152403-1eed2f2ce9d3
29+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250226134545-32bb2d9f1eee
3030
github.com/stretchr/testify v1.10.0
3131
golang.org/x/crypto v0.33.0
3232
gopkg.in/dnaeon/go-vcr.v3 v3.2.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXq
280280
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
281281
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
282282
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
283-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250206152403-1eed2f2ce9d3 h1:wNQbwsFYaWiqTRtAgO5uroCTsS0o8FPGdI/x4hCJqtM=
284-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250206152403-1eed2f2ce9d3/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
283+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250226134545-32bb2d9f1eee h1:MMM+KEDnKZ14GVt4de0hslFGYUualLHKYsvf1dCIxM4=
284+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250226134545-32bb2d9f1eee/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
285285
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
286286
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
287287
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=

internal/services/webhosting/helpers.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
webhosting "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1alpha1"
8+
"github.com/scaleway/scaleway-sdk-go/api/webhosting/v1"
99
"github.com/scaleway/scaleway-sdk-go/scw"
1010
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1111
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
@@ -17,9 +17,8 @@ const (
1717
hostingRetryInterval = 5 * time.Second
1818
)
1919

20-
// newAPIWithRegion returns a new Webhosting API and the region for a Create request
21-
func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*webhosting.API, scw.Region, error) {
22-
api := webhosting.NewAPI(meta.ExtractScwClient(m))
20+
func newOfferAPIWithRegion(d *schema.ResourceData, m interface{}) (*webhosting.OfferAPI, scw.Region, error) {
21+
api := webhosting.NewOfferAPI(meta.ExtractScwClient(m))
2322

2423
region, err := meta.ExtractRegion(d, m)
2524
if err != nil {
@@ -29,9 +28,21 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*webhosting.API, s
2928
return api, region, nil
3029
}
3130

32-
// NewAPIWithRegionAndID returns a Webhosting API with region and ID extracted from the state
33-
func NewAPIWithRegionAndID(m interface{}, id string) (*webhosting.API, scw.Region, string, error) {
34-
api := webhosting.NewAPI(meta.ExtractScwClient(m))
31+
// newHostingAPIWithRegion returns a new Hosting API and the region for a Create request.
32+
func newHostingAPIWithRegion(d *schema.ResourceData, m interface{}) (*webhosting.HostingAPI, scw.Region, error) {
33+
api := webhosting.NewHostingAPI(meta.ExtractScwClient(m))
34+
35+
region, err := meta.ExtractRegion(d, m)
36+
if err != nil {
37+
return nil, "", err
38+
}
39+
40+
return api, region, nil
41+
}
42+
43+
// NewAPIWithRegionAndID returns a Hosting API with region and ID extracted from the state.
44+
func NewAPIWithRegionAndID(m interface{}, id string) (*webhosting.HostingAPI, scw.Region, string, error) {
45+
api := webhosting.NewHostingAPI(meta.ExtractScwClient(m))
3546

3647
region, id, err := regional.ParseID(id)
3748
if err != nil {
@@ -41,7 +52,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*webhosting.API, scw.Regio
4152
return api, region, id, nil
4253
}
4354

44-
func waitForHosting(ctx context.Context, api *webhosting.API, region scw.Region, hostingID string, timeout time.Duration) (*webhosting.Hosting, error) {
55+
func waitForHosting(ctx context.Context, api *webhosting.HostingAPI, region scw.Region, hostingID string, timeout time.Duration) (*webhosting.Hosting, error) {
4556
retryInterval := hostingRetryInterval
4657
if transport.DefaultWaitRetryInterval != nil {
4758
retryInterval = *transport.DefaultWaitRetryInterval

internal/services/webhosting/offer_data_source.go

+111-16
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package webhosting
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9-
webhosting "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1alpha1"
10+
webhosting "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1"
1011
"github.com/scaleway/scaleway-sdk-go/scw"
1112
"github.com/scaleway/terraform-provider-scaleway/v2/internal/datasource"
13+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1214
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1315
)
1416

@@ -22,19 +24,27 @@ func DataSourceOffer() *schema.Resource {
2224
Description: "Exact name of the desired offer",
2325
ConflictsWith: []string{"offer_id"},
2426
},
27+
"control_panel": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
Description: "Name of the control panel.(Cpanel or Plesk)",
31+
DiffSuppressFunc: dsf.IgnoreCase,
32+
ConflictsWith: []string{"offer_id"},
33+
},
2534
"offer_id": {
2635
Type: schema.TypeString,
2736
Optional: true,
2837
Description: "ID of the desired offer",
29-
ConflictsWith: []string{"name"},
38+
ConflictsWith: []string{"name", "control_panel"},
3039
},
3140
"billing_operation_path": {
3241
Computed: true,
3342
Type: schema.TypeString,
3443
},
3544
"product": {
36-
Type: schema.TypeList,
37-
Computed: true,
45+
Type: schema.TypeList,
46+
Computed: true,
47+
Deprecated: "The product field is deprecated. Please use the offer field instead.",
3848
Elem: &schema.Resource{
3949
Schema: map[string]*schema.Schema{
4050
"name": {
@@ -46,32 +56,113 @@ func DataSourceOffer() *schema.Resource {
4656
Computed: true,
4757
},
4858
"email_accounts_quota": {
49-
Computed: true,
5059
Type: schema.TypeInt,
60+
Computed: true,
5161
},
5262
"email_storage_quota": {
53-
Computed: true,
5463
Type: schema.TypeInt,
64+
Computed: true,
5565
},
5666
"databases_quota": {
57-
Computed: true,
5867
Type: schema.TypeInt,
68+
Computed: true,
5969
},
6070
"hosting_storage_quota": {
61-
Computed: true,
6271
Type: schema.TypeInt,
72+
Computed: true,
6373
},
6474
"support_included": {
65-
Computed: true,
6675
Type: schema.TypeBool,
76+
Computed: true,
6777
},
6878
"v_cpu": {
69-
Computed: true,
7079
Type: schema.TypeInt,
80+
Computed: true,
7181
},
7282
"ram": {
73-
Computed: true,
7483
Type: schema.TypeInt,
84+
Computed: true,
85+
},
86+
},
87+
},
88+
},
89+
"offer": {
90+
Type: schema.TypeList,
91+
Computed: true,
92+
Description: "The offer details of the hosting",
93+
Elem: &schema.Resource{
94+
Schema: map[string]*schema.Schema{
95+
"id": {
96+
Type: schema.TypeString,
97+
Computed: true,
98+
},
99+
"name": {
100+
Type: schema.TypeString,
101+
Computed: true,
102+
},
103+
"billing_operation_path": {
104+
Type: schema.TypeString,
105+
Computed: true,
106+
},
107+
"available": {
108+
Type: schema.TypeBool,
109+
Computed: true,
110+
},
111+
"control_panel_name": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
},
115+
"end_of_life": {
116+
Type: schema.TypeBool,
117+
Computed: true,
118+
},
119+
"quota_warning": {
120+
Type: schema.TypeString,
121+
Computed: true,
122+
},
123+
"price": {
124+
Type: schema.TypeString,
125+
Computed: true,
126+
},
127+
"options": {
128+
Type: schema.TypeList,
129+
Computed: true,
130+
Elem: &schema.Resource{
131+
Schema: map[string]*schema.Schema{
132+
"id": {
133+
Type: schema.TypeString,
134+
Computed: true,
135+
},
136+
"name": {
137+
Type: schema.TypeString,
138+
Computed: true,
139+
},
140+
"billing_operation_path": {
141+
Type: schema.TypeString,
142+
Computed: true,
143+
},
144+
"min_value": {
145+
Type: schema.TypeInt,
146+
Computed: true,
147+
},
148+
"current_value": {
149+
Type: schema.TypeInt,
150+
Computed: true,
151+
},
152+
"max_value": {
153+
Type: schema.TypeInt,
154+
Computed: true,
155+
},
156+
"quota_warning": {
157+
Type: schema.TypeString,
158+
Computed: true,
159+
},
160+
"price": {
161+
Type: schema.TypeString,
162+
Computed: true,
163+
},
164+
},
165+
},
75166
},
76167
},
77168
},
@@ -86,12 +177,12 @@ func DataSourceOffer() *schema.Resource {
86177
}
87178

88179
func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
89-
api, region, err := newAPIWithRegion(d, m)
180+
api, region, err := newOfferAPIWithRegion(d, m)
90181
if err != nil {
91182
return diag.FromErr(err)
92183
}
93184

94-
res, err := api.ListOffers(&webhosting.ListOffersRequest{
185+
res, err := api.ListOffers(&webhosting.OfferAPIListOffersRequest{
95186
Region: region,
96187
}, scw.WithContext(ctx))
97188
if err != nil {
@@ -105,8 +196,11 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
105196
var filteredOffer *webhosting.Offer
106197

107198
for _, offer := range res.Offers {
108-
if offer.ID == d.Get("offer_id") || offer.Product.Name == d.Get("name") {
199+
cp, _ := d.Get("control_panel").(string)
200+
if offer.ID == d.Get("offer_id") || (offer.Name == d.Get("name") && (cp == "" || strings.EqualFold(offer.ControlPanelName, cp))) {
109201
filteredOffer = offer
202+
203+
break
110204
}
111205
}
112206

@@ -117,10 +211,11 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
117211
regionalID := datasource.NewRegionalID(filteredOffer.ID, region)
118212
d.SetId(regionalID)
119213
_ = d.Set("offer_id", regionalID)
120-
_ = d.Set("name", filteredOffer.Product.Name)
214+
_ = d.Set("name", filteredOffer.Name)
121215
_ = d.Set("region", region)
122216
_ = d.Set("billing_operation_path", filteredOffer.BillingOperationPath)
123-
_ = d.Set("product", flattenOfferProduct(filteredOffer.Product))
217+
_ = d.Set("product", nil)
218+
_ = d.Set("offer", flattenOffer(filteredOffer))
124219
_ = d.Set("price", flattenOfferPrice(filteredOffer.Price))
125220

126221
return nil

internal/services/webhosting/offer_data_source_test.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,10 @@ func TestAccDataSourceOffer_Basic(t *testing.T) {
2727
Check: resource.ComposeTestCheckFunc(
2828
resource.TestCheckResourceAttrSet("data.scaleway_webhosting_offer.by_id", "id"),
2929
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_id", "name", "professional"),
30-
3130
resource.TestCheckResourceAttrSet("data.scaleway_webhosting_offer.by_name", "id"),
3231
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "name", "professional"),
33-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.option", "false"),
34-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.email_accounts_quota", "10"),
35-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.email_storage_quota", "5"),
36-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.databases_quota", "-1"),
37-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.hosting_storage_quota", "100"),
38-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.support_included", "true"),
39-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.v_cpu", "4"),
40-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "product.0.ram", "2"),
41-
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "price", "€ 18.99"),
32+
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "offer.0.name", "professional"),
33+
resource.TestCheckResourceAttr("data.scaleway_webhosting_offer.by_name", "offer.0.price", "€ 18.99"),
4234
),
4335
},
4436
},

0 commit comments

Comments
 (0)