@@ -8,13 +8,28 @@ import (
88 "context"
99 "errors"
1010 "fmt"
11+ "strings"
1112
1213 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1314 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1415 "github.com/vmware/vra-sdk-go/pkg/client/location"
1516 "github.com/vmware/vra-sdk-go/pkg/models"
1617)
1718
19+ const (
20+ PlacementPolicyDefault = "DEFAULT"
21+ PlacementPolicyBinpack = "BINPACK"
22+ PlacementPolicySpread = "SPREAD"
23+ PlacementPolicySpreadMemory = "SPREAD_MEMORY"
24+ )
25+
26+ var AllowedPlacementPolicies = []string {
27+ PlacementPolicyDefault ,
28+ PlacementPolicyBinpack ,
29+ PlacementPolicySpread ,
30+ PlacementPolicySpreadMemory ,
31+ }
32+
1833func resourceZone () * schema.Resource {
1934 return & schema.Resource {
2035 CreateContext : resourceZoneCreate ,
@@ -67,14 +82,17 @@ func resourceZone() *schema.Resource {
6782 "placement_policy" : {
6883 Type : schema .TypeString ,
6984 Default : "DEFAULT" ,
70- Description : "The placement policy for the zone. One of DEFAULT, SPREAD or BINPACK." ,
85+ Description : fmt . Sprintf ( "The placement policy for the zone. One of %v." , AllowedPlacementPolicies ) ,
7186 Optional : true ,
7287 ValidateFunc : func (v interface {}, k string ) (ws []string , errors []error ) {
7388 value := v .(string )
74- if value != "DEFAULT" && value != "SPREAD" && value != "BINPACK" {
75- errors = append (errors , fmt .Errorf (
76- "%q must be one of 'DEFAULT', 'SPREAD', 'BINPACK'" , k ))
89+ for _ , validValue := range AllowedPlacementPolicies {
90+ if value == validValue {
91+ return
92+ }
7793 }
94+ errors = append (errors , fmt .Errorf (
95+ "%q must be one of %s" , k , strings .Join (AllowedPlacementPolicies , ", " )))
7896 return
7997 },
8098 },
0 commit comments