@@ -3,12 +3,14 @@ package webhosting
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "strings"
6
7
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8
9
"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 "
10
11
"github.com/scaleway/scaleway-sdk-go/scw"
11
12
"github.com/scaleway/terraform-provider-scaleway/v2/internal/datasource"
13
+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
12
14
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
13
15
)
14
16
@@ -22,19 +24,27 @@ func DataSourceOffer() *schema.Resource {
22
24
Description : "Exact name of the desired offer" ,
23
25
ConflictsWith : []string {"offer_id" },
24
26
},
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
+ },
25
34
"offer_id" : {
26
35
Type : schema .TypeString ,
27
36
Optional : true ,
28
37
Description : "ID of the desired offer" ,
29
- ConflictsWith : []string {"name" },
38
+ ConflictsWith : []string {"name" , "control_panel" },
30
39
},
31
40
"billing_operation_path" : {
32
41
Computed : true ,
33
42
Type : schema .TypeString ,
34
43
},
35
44
"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." ,
38
48
Elem : & schema.Resource {
39
49
Schema : map [string ]* schema.Schema {
40
50
"name" : {
@@ -46,32 +56,113 @@ func DataSourceOffer() *schema.Resource {
46
56
Computed : true ,
47
57
},
48
58
"email_accounts_quota" : {
49
- Computed : true ,
50
59
Type : schema .TypeInt ,
60
+ Computed : true ,
51
61
},
52
62
"email_storage_quota" : {
53
- Computed : true ,
54
63
Type : schema .TypeInt ,
64
+ Computed : true ,
55
65
},
56
66
"databases_quota" : {
57
- Computed : true ,
58
67
Type : schema .TypeInt ,
68
+ Computed : true ,
59
69
},
60
70
"hosting_storage_quota" : {
61
- Computed : true ,
62
71
Type : schema .TypeInt ,
72
+ Computed : true ,
63
73
},
64
74
"support_included" : {
65
- Computed : true ,
66
75
Type : schema .TypeBool ,
76
+ Computed : true ,
67
77
},
68
78
"v_cpu" : {
69
- Computed : true ,
70
79
Type : schema .TypeInt ,
80
+ Computed : true ,
71
81
},
72
82
"ram" : {
73
- Computed : true ,
74
83
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
+ },
75
166
},
76
167
},
77
168
},
@@ -86,12 +177,12 @@ func DataSourceOffer() *schema.Resource {
86
177
}
87
178
88
179
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 )
90
181
if err != nil {
91
182
return diag .FromErr (err )
92
183
}
93
184
94
- res , err := api .ListOffers (& webhosting.ListOffersRequest {
185
+ res , err := api .ListOffers (& webhosting.OfferAPIListOffersRequest {
95
186
Region : region ,
96
187
}, scw .WithContext (ctx ))
97
188
if err != nil {
@@ -105,8 +196,11 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
105
196
var filteredOffer * webhosting.Offer
106
197
107
198
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 ))) {
109
201
filteredOffer = offer
202
+
203
+ break
110
204
}
111
205
}
112
206
@@ -117,10 +211,11 @@ func dataSourceOfferRead(ctx context.Context, d *schema.ResourceData, m interfac
117
211
regionalID := datasource .NewRegionalID (filteredOffer .ID , region )
118
212
d .SetId (regionalID )
119
213
_ = d .Set ("offer_id" , regionalID )
120
- _ = d .Set ("name" , filteredOffer .Product . Name )
214
+ _ = d .Set ("name" , filteredOffer .Name )
121
215
_ = d .Set ("region" , region )
122
216
_ = 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 ))
124
219
_ = d .Set ("price" , flattenOfferPrice (filteredOffer .Price ))
125
220
126
221
return nil
0 commit comments