Skip to content

Commit

Permalink
[minor_change] Add support for endpoint move detection mode in schema…
Browse files Browse the repository at this point in the history
…_template_bd
  • Loading branch information
akinross committed Jan 13, 2025
1 parent 7dafa77 commit 6bf46cd
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
13 changes: 13 additions & 0 deletions examples/schema_template_bd/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ resource "mso_schema_template_vrf" "vrf" {
display_name = "test_bd_vrf"
}

// Endpoint move detect mode

resource "mso_schema_template_bd" "bd_ep" {
schema_id = mso_schema.schema_1.id
template_name = one(mso_schema.schema_1.template).name
vrf_name = mso_schema_template_vrf.vrf.name
name = "bd_ep_demo"
display_name = "bd_ep_demo"
arp_flooding = true
ep_move_detection_mode = "garp"
}


// MSO versions 3.2 and higher
resource "mso_schema_template_bd" "bd" {
schema_id = mso_schema.schema_1.id
Expand Down
11 changes: 11 additions & 0 deletions mso/datasource_mso_schema_template_bd.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func dataSourceMSOTemplateBD() *schema.Resource {
},
},
},
"ep_move_detection_mode": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
}),
}
}
Expand Down Expand Up @@ -243,6 +247,13 @@ func setSchemaTemplateBDAttrs(schemaId, templateName, bdName string, cont *conta
d.Set("virtual_mac_address", "")
}

epMoveDetectMode := models.StripQuotes(bdCont.S("epMoveDetectMode").String())
if epMoveDetectMode != "{}" {
d.Set("ep_move_detection_mode", epMoveDetectMode)
} else {
d.Set("ep_move_detection_mode", "none") // set to default value of none when not present
}

if bdCont.Exists("intersiteBumTrafficAllow") {
d.Set("intersite_bum_traffic", bdCont.S("intersiteBumTrafficAllow").Data().(bool))
}
Expand Down
43 changes: 40 additions & 3 deletions mso/resource_mso_schema_template_bd.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ func resourceMSOTemplateBD() *schema.Resource {
},
},
},
"ep_move_detection_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"none",
"garp",
}, false),
},
}),
}
}
Expand Down Expand Up @@ -277,6 +286,14 @@ func resourceMSOTemplateBDImport(d *schema.ResourceData, m interface{}) ([]*sche
} else {
d.Set("virtual_mac_address", "")
}

epMoveDetectMode := models.StripQuotes(bdCont.S("epMoveDetectMode").String())
if epMoveDetectMode != "{}" {
d.Set("ep_move_detection_mode", epMoveDetectMode)
} else {
d.Set("ep_move_detection_mode", "none") // set to default value of none when not present
}

if bdCont.Exists("intersiteBumTrafficAllow") {
d.Set("intersite_bum_traffic", bdCont.S("intersiteBumTrafficAllow").Data().(bool))
}
Expand Down Expand Up @@ -406,7 +423,7 @@ func resourceMSOTemplateBDCreate(d *schema.ResourceData, m interface{}) error {
}

var intersite_bum_traffic, optimize_wan_bandwidth, layer2_stretch, layer3_multicast, unicast_routing, arp_flooding bool
var layer2_unknown_unicast, vrf_schema_id, vrf_template_name, virtual_mac_address, ipv6_unknown_multicast_flooding, multi_destination_flooding, unknown_multicast_flooding string
var layer2_unknown_unicast, vrf_schema_id, vrf_template_name, virtual_mac_address, ep_move_detection_mode, ipv6_unknown_multicast_flooding, multi_destination_flooding, unknown_multicast_flooding string

if tempVar, ok := d.GetOk("intersite_bum_traffic"); ok {
intersite_bum_traffic = tempVar.(bool)
Expand Down Expand Up @@ -438,6 +455,9 @@ func resourceMSOTemplateBDCreate(d *schema.ResourceData, m interface{}) error {
if tempVar, ok := d.GetOk("virtual_mac_address"); ok {
virtual_mac_address = tempVar.(string)
}
if tempVar, ok := d.GetOk("ep_move_detection_mode"); ok {
ep_move_detection_mode = tempVar.(string)
}
if tempVar, ok := d.GetOk("arp_flooding"); ok {
arp_flooding = tempVar.(bool)
}
Expand Down Expand Up @@ -518,7 +538,7 @@ func resourceMSOTemplateBDCreate(d *schema.ResourceData, m interface{}) error {
vrfRefMap["templateName"] = vrf_template_name
vrfRefMap["vrfName"] = vrfName
path := fmt.Sprintf("/templates/%s/bds/-", templateName)
bdStruct := models.NewTemplateBD("add", path, name, displayName, layer2_unknown_unicast, unknown_multicast_flooding, multi_destination_flooding, ipv6_unknown_multicast_flooding, virtual_mac_address, description, intersite_bum_traffic, optimize_wan_bandwidth, layer2_stretch, layer3_multicast, arp_flooding, unicast_routing, vrfRefMap, dhcpPolMap, dhcpPolList)
bdStruct := models.NewTemplateBD("add", path, name, displayName, layer2_unknown_unicast, unknown_multicast_flooding, multi_destination_flooding, ipv6_unknown_multicast_flooding, virtual_mac_address, ep_move_detection_mode, description, intersite_bum_traffic, optimize_wan_bandwidth, layer2_stretch, layer3_multicast, arp_flooding, unicast_routing, vrfRefMap, dhcpPolMap, dhcpPolList)
_, err = msoClient.PatchbyID(fmt.Sprintf("api/v1/schemas/%s", schemaID), bdStruct)

if err != nil {
Expand Down Expand Up @@ -606,6 +626,13 @@ func resourceMSOTemplateBDRead(d *schema.ResourceData, m interface{}) error {
d.Set("virtual_mac_address", "")
}

epMoveDetectMode := models.StripQuotes(bdCont.S("epMoveDetectMode").String())
if epMoveDetectMode != "{}" {
d.Set("ep_move_detection_mode", epMoveDetectMode)
} else {
d.Set("ep_move_detection_mode", "none") // set to default value of none when not present
}

if bdCont.Exists("intersiteBumTrafficAllow") {
d.Set("intersite_bum_traffic", bdCont.S("intersiteBumTrafficAllow").Data().(bool))
}
Expand Down Expand Up @@ -737,7 +764,7 @@ func resourceMSOTemplateBDUpdate(d *schema.ResourceData, m interface{}) error {
return err
}
var intersite_bum_traffic, optimize_wan_bandwidth, layer2_stretch, layer3_multicast, unicast_routing, arp_flooding bool
var layer2_unknown_unicast, vrf_schema_id, vrf_template_name, virtual_mac_address, ipv6_unknown_multicast_flooding, multi_destination_flooding, unknown_multicast_flooding string
var layer2_unknown_unicast, vrf_schema_id, vrf_template_name, virtual_mac_address, ep_move_detection_mode, ipv6_unknown_multicast_flooding, multi_destination_flooding, unknown_multicast_flooding string

if tempVar, ok := d.GetOk("intersite_bum_traffic"); ok {
intersite_bum_traffic = tempVar.(bool)
Expand Down Expand Up @@ -769,6 +796,9 @@ func resourceMSOTemplateBDUpdate(d *schema.ResourceData, m interface{}) error {
if tempVar, ok := d.GetOk("virtual_mac_address"); ok {
virtual_mac_address = tempVar.(string)
}
if tempVar, ok := d.GetOk("ep_move_detection_mode"); ok {
ep_move_detection_mode = tempVar.(string)
}
if tempVar, ok := d.GetOk("arp_flooding"); ok {
arp_flooding = tempVar.(bool)
}
Expand Down Expand Up @@ -904,6 +934,13 @@ func resourceMSOTemplateBDUpdate(d *schema.ResourceData, m interface{}) error {
}
}

if ep_move_detection_mode != "" {
err = addPatchPayloadToContainer(payloadCon, "replace", fmt.Sprintf("%s/epMoveDetectMode", basePath), ep_move_detection_mode)
if err != nil {
return err
}
}

err = addPatchPayloadToContainer(payloadCon, "replace", fmt.Sprintf("%s/description", basePath), description)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/schema_template_bd.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data "mso_schema_template_bd" "example" {
* `ipv6_unknown_multicast_flooding` - (Read-Only) The IPv6 unknown multicast flooding settings of the BD.
* `arp_flooding` - (Read-Only) The ARP flooding settings of the BD.
* `virtual_mac_address` - (Read-Only) The virtual mac address of the BD.
* `ep_move_detection_mode` - (Read-Only) Trigger an endpoint move based on incoming Gratuitous Address Resolution Protocol (GARP) packets.
* `unicast_routing` - (Read-Only) Whether unicast routing is enabled.

### Deprecation warning: do not use 'dhcp_policy' map below in combination with NDO releases 3.2 and higher, use above 'dhcp_policies' block instead.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/schema_template_bd.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ resource "mso_schema_template_bd" "bridge_domain" {
* `layer3_multicast` - (Optional) Boolean flag to enable or disable layer 3 multicast traffic. Default to false.
* `arp_flooding` - (Optional) ARP Flooding status. Default to false.
* `virtual_mac_address` - (Optional) Virtual MAC Address.
* `ep_move_detection_mode` - (Optional) Trigger an endpoint move based on incoming Gratuitous Address Resolution Protocol (GARP) packets. Allowed values are `garp` (enabled) and `none` (disabled). Default to `none`.
* `unicast_routing` - (Optional) Unicast Routing status. Default to false.
* `ipv6_unknown_multicast_flooding` - (Optional) IPv6 Unknown Multicast Flooding behavior. Allowed values are `flood` and `optimized_flooding`. Default to `flood`.
* `multi_destination_flooding` - (Optional) Multi-destination flooding behavior. Allowed values are `flood_in_bd`, `drop` and `flood_in_encap`. Default to `flood_in_bd`.
Expand Down

0 comments on commit 6bf46cd

Please sign in to comment.