Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow vlan range in policy vlan segments #342

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions nsxt/resource_nsxt_policy_vlan_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func TestAccResourceNsxtPolicyVlanSegment_basicUpdate(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccNsxtPolicyVlanSegmentExists(testResourceName),
resource.TestCheckResourceAttr(testResourceName, "display_name", updatedName),
// TODO: file bug for description not being updated
// resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test2"),
resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test2"),
resource.TestCheckResourceAttr(testResourceName, "domain_name", "tftest2.org"),
resource.TestCheckResourceAttr(testResourceName, "vlan_ids.#", "2"),
resource.TestCheckResourceAttr(testResourceName, "tag.#", "2"),
Expand Down Expand Up @@ -272,10 +271,10 @@ func testAccNsxtPolicyVlanSegmentBasicUpdateTemplate(name string) string {

resource "nsxt_policy_vlan_segment" "test" {
display_name = "%s"
description = "Acceptance Test"
description = "Acceptance Test2"
transport_zone_path = data.nsxt_policy_transport_zone.vlantz.path
domain_name = "tftest2.org"
vlan_ids = ["101", "102"]
vlan_ids = ["101", "104-110"]

tag {
scope = "color"
Expand Down
2 changes: 1 addition & 1 deletion nsxt/segment_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func getPolicyCommonSegmentSchema() map[string]*schema.Schema {
Description: "VLAN IDs for VLAN backed Segment",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validateVLANId,
ValidateFunc: validateVLANIdOrRange,
},
Required: true,
},
Expand Down
21 changes: 20 additions & 1 deletion nsxt/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,31 @@ func validateVLANId(i interface{}, k string) (s []string, es []error) {
}
}
if vlan < 0 || vlan > 4095 {
es = append(es, fmt.Errorf("invalid VLAN ID %d", vlan))
es = append(es, fmt.Errorf("Invalid VLAN ID %d", vlan))
return
}
return
}

func validateVLANIdOrRange(i interface{}, k string) (s []string, es []error) {
v, ok := i.(string)
if !ok {
s, es = validateVLANId(i, k)
return
}

tokens := strings.Split(v, "-")
if len(tokens) > 2 {
es = append(es, fmt.Errorf("Invalid vlan range %s", v))
return
}
for _, token := range tokens {
s, es = validateVLANId(token, k)
}

return
}

func validateStringIntBetween(start int, end int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(string)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/policy_vlan_segment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following arguments are supported:
* `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource.
* `domain_name`- (Optional) DNS domain names.
* `transport_zone_path` - (Required) Policy path to the VLAN backed transport zone.
* `vlan_ids` - (Optional) VLAN IDs for VLAN backed Segment.
* `vlan_ids` - (Optional) List of VLAN IDs or VLAN ranges.
* `dhcp_config_path` - (Optional) Policy path to DHCP server or relay configuration to use for subnets configured on this segment. This attribute is supported with NSX 3.0.0 onwards.
* `subnet` - (Required) Subnet configuration block.
* `cidr` - (Required) Gateway IP address CIDR.
Expand Down