-
Notifications
You must be signed in to change notification settings - Fork 120
/
schemas.go
37 lines (32 loc) · 994 Bytes
/
schemas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package regional
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
)
// ComputedSchema returns a standard schema for a region
func ComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Description: "The region of the resource",
Computed: true,
}
}
func allRegions() []string {
regions := make([]string, 0, len(scw.AllRegions))
for _, z := range scw.AllRegions {
regions = append(regions, z.String())
}
return regions
}
// Schema returns a standard schema for a region
func Schema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Description: "The region you want to attach the resource to",
Optional: true,
ForceNew: true,
Computed: true,
ValidateDiagFunc: locality.ValidateStringInSliceWithWarning(allRegions(), "region"),
}
}