9
9
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
10
10
"github.com/hashicorp/terraform-plugin-sdk/terraform"
11
11
"github.com/mitchellh/go-homedir"
12
+ "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
12
13
"github.com/scaleway/scaleway-sdk-go/scw"
13
14
)
14
15
@@ -168,7 +169,20 @@ func Provider() terraform.ResourceProvider {
168
169
},
169
170
ValidateFunc : validationZone (),
170
171
},
171
-
172
+ "api_url" : {
173
+ Type : schema .TypeString ,
174
+ Optional : true ,
175
+ Description : "The Scaleway API URL to use." ,
176
+ DefaultFunc : func () (interface {}, error ) {
177
+ if envProfile .APIURL != nil {
178
+ return * envProfile .APIURL , nil
179
+ }
180
+ if activeProfile != nil && activeProfile .APIURL != nil {
181
+ return * activeProfile .APIURL , nil
182
+ }
183
+ return nil , nil
184
+ },
185
+ },
172
186
// Deprecated values
173
187
"token" : {
174
188
Type : schema .TypeString ,
@@ -294,6 +308,7 @@ func providerConfigure(d *schema.ResourceData, terraformVersion string) (interfa
294
308
DefaultRegion : region ,
295
309
DefaultZone : zone ,
296
310
TerraformVersion : terraformVersion ,
311
+ APIURL : d .Get ("api_url" ).(string ),
297
312
}
298
313
299
314
err = meta .bootstrap ()
@@ -303,10 +318,15 @@ func providerConfigure(d *schema.ResourceData, terraformVersion string) (interfa
303
318
304
319
// fetch known scaleway server types to support validation in r/server
305
320
if len (commercialServerTypes ) == 0 {
306
- if availability , err := meta .deprecatedClient .GetServerAvailabilities (); err == nil {
307
- commercialServerTypes = availability .CommercialTypes ()
321
+ instanceAPI := instance .NewAPI (meta .scwClient )
322
+ availabilityResp , err := instanceAPI .GetServerTypesAvailability (& instance.GetServerTypesAvailabilityRequest {}, scw .WithAllPages ())
323
+ if err == nil {
324
+ for k := range availabilityResp .Servers {
325
+ commercialServerTypes = append (commercialServerTypes , k )
326
+ }
308
327
sort .StringSlice (commercialServerTypes ).Sort ()
309
328
}
329
+
310
330
if os .Getenv ("DISABLE_SCALEWAY_SERVER_TYPE_VALIDATION" ) != "" {
311
331
commercialServerTypes = commercialServerTypes [:0 ]
312
332
}
0 commit comments