Skip to content

Commit e6ffe44

Browse files
committed
feat: add SPREAD_MEMORY to r/zone placement_policy
- Adds `SPREAD_MEMORY` to `r/zone` `placement_policy`. - Refactors to use constants for the placement policies and a var for the validation. Signed-off-by: Ryan Johnson <[email protected]>
1 parent 3ef566f commit e6ffe44

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

vra/resource_zone.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1833
func 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
},

vra/resource_zone_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestAccVRAZoneInvalidPlacementPolicy(t *testing.T) {
172172
Steps: []resource.TestStep{
173173
{
174174
Config: testAccCheckVRAZoneConfigInvalidPlacementPolicy(),
175-
ExpectError: regexp.MustCompile("\"placement_policy\" must be one of 'DEFAULT', 'SPREAD', 'BINPACK'"),
175+
ExpectError: regexp.MustCompile("\"placement_policy\" must be one of 'DEFAULT', 'BINPACK', 'SPREAD', 'SPREAD_MEMORY'"),
176176
},
177177
},
178178
})

website/docs/d/vra_zone.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ A zone data source supports the following arguments:
4747

4848
* `owner` - Email of the user that owns the entity.
4949

50-
* `placement_policy` - The placement policy for the zone. One of `DEFAULT`, `SPREAD` or `BINPACK`.
50+
* `placement_policy` - The placement policy for the zone. One of `DEFAULT`, `BINPACK`, `SPREAD` or `SPREAD_MEMORY`.
5151

5252
* `tags` - A set of tag keys and optional values that were set on this resource:
5353
* `key` - Tag’s key.

website/docs/r/vra_zone.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A zone resource supports the following arguments:
4343

4444
* `name` - (Required) A human-friendly name used as an identifier for the zone resource instance.
4545

46-
* `placement_policy` - (Optional) The placement policy for the zone. One of `DEFAULT`, `SPREAD` or `BINPACK`. Default is `DEFAULT`.
46+
* `placement_policy` - (Optional) The placement policy for the zone. One of `DEFAULT`, `BINPACK`, `SPREAD` or `SPREAD_MEMORY`. Default is `DEFAULT`.
4747

4848
* `region_id` - (Required) The id of the region for which this zone is created.
4949

0 commit comments

Comments
 (0)