8
8
"strings"
9
9
"time"
10
10
11
+ "github.com/hashicorp/go-cty/cty"
12
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13
15
"github.com/scaleway/scaleway-sdk-go/namegenerator"
@@ -256,15 +258,12 @@ func zoneSchema() *schema.Schema {
256
258
allZones = append (allZones , z .String ())
257
259
}
258
260
return & schema.Schema {
259
- Type : schema .TypeString ,
260
- Description : "The zone you want to attach the resource to" ,
261
- Optional : true ,
262
- ForceNew : true ,
263
- Computed : true ,
264
- ValidateFunc : validation .StringInSlice (
265
- allZones ,
266
- true ,
267
- ),
261
+ Type : schema .TypeString ,
262
+ Description : "The zone you want to attach the resource to" ,
263
+ Optional : true ,
264
+ ForceNew : true ,
265
+ Computed : true ,
266
+ ValidateDiagFunc : validateStringInSliceWithWarning (allZones , "zone" ),
268
267
}
269
268
}
270
269
@@ -275,15 +274,28 @@ func regionSchema() *schema.Schema {
275
274
allRegions = append (allRegions , z .String ())
276
275
}
277
276
return & schema.Schema {
278
- Type : schema .TypeString ,
279
- Description : "The region you want to attach the resource to" ,
280
- Optional : true ,
281
- ForceNew : true ,
282
- Computed : true ,
283
- ValidateFunc : validation .StringInSlice (
284
- allRegions ,
285
- true ,
286
- ),
277
+ Type : schema .TypeString ,
278
+ Description : "The region you want to attach the resource to" ,
279
+ Optional : true ,
280
+ ForceNew : true ,
281
+ Computed : true ,
282
+ ValidateDiagFunc : validateStringInSliceWithWarning (allRegions , "region" ),
283
+ }
284
+ }
285
+
286
+ // validateStringInSliceWithWarning helps to only returns warnings in case we got a non public locality passed
287
+ func validateStringInSliceWithWarning (correctValues []string , field string ) func (i interface {}, path cty.Path ) diag.Diagnostics {
288
+ return func (i interface {}, path cty.Path ) diag.Diagnostics {
289
+ _ , rawErr := validation .StringInSlice (correctValues , true )(i , field )
290
+ var res diag.Diagnostics
291
+ for _ , e := range rawErr {
292
+ res = append (res , diag.Diagnostic {
293
+ Severity : diag .Warning ,
294
+ Summary : e .Error (),
295
+ AttributePath : path ,
296
+ })
297
+ }
298
+ return res
287
299
}
288
300
}
289
301
0 commit comments