Skip to content

Commit

Permalink
r/bridge_domain: add interface argument
Browse files Browse the repository at this point in the history
Fix #548
  • Loading branch information
jeremmfr committed Oct 12, 2023
1 parent d21f719 commit b407bcb
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changes/issue-548.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ENHANCEMENTS:
optional boolean attributes doesn't accept value *false*
optional string attributes doesn't accept *empty* value
the resource schema has been upgraded to have one-blocks in single mode instead of list
* add `interface` argument (Fix [#548](https://github.com/jeremmfr/terraform-provider-junos/issues/548))
2 changes: 2 additions & 0 deletions docs/resources/bridge_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The following arguments are supported:
Domain-id for auto derived Route Target (1..15).
- **domain_type_bridge** (Optional, Boolean)
Forwarding instance.
- **interface** (Optional, Set of String)
Interface for this bridge domain.
- **isolated_vlan** (Optional, Number)
Isolated VLAN ID for private vlan bridge domain (1..4094).
- **routing_interface** (Optional, String)
Expand Down
25 changes: 25 additions & 0 deletions internal/providerfwk/resource_bridge_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ func (rsc *bridgeDomain) Schema(
tfvalidator.BoolTrue(),
},
},
"interface": schema.SetAttribute{
ElementType: types.StringType,
Optional: true,
Description: "Interface for this bridge domain.",
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(
stringvalidator.LengthAtLeast(1),
tfvalidator.StringFormat(tfvalidator.InterfaceFormat),
tfvalidator.String1DotCount(),
),
},
},
"isolated_vlan": schema.Int64Attribute{
Optional: true,
Description: "Isolated VLAN ID for private vlan bridge domain.",
Expand Down Expand Up @@ -271,6 +284,7 @@ type bridgeDomainData struct {
CommunityVlans []types.String `tfsdk:"community_vlans"`
Description types.String `tfsdk:"description"`
DomainID types.Int64 `tfsdk:"domain_id"`
Interface []types.String `tfsdk:"interface"`
IsolatedVLAN types.Int64 `tfsdk:"isolated_vlan"`
RoutingInterface types.String `tfsdk:"routing_interface"`
ServiceID types.Int64 `tfsdk:"service_id"`
Expand All @@ -287,6 +301,7 @@ type bridgeDomainConfig struct {
CommunityVlans types.Set `tfsdk:"community_vlans"`
Description types.String `tfsdk:"description"`
DomainID types.Int64 `tfsdk:"domain_id"`
Interface types.Set `tfsdk:"interface"`
IsolatedVLAN types.Int64 `tfsdk:"isolated_vlan"`
RoutingInterface types.String `tfsdk:"routing_interface"`
ServiceID types.Int64 `tfsdk:"service_id"`
Expand All @@ -305,6 +320,8 @@ func (rscConfig *bridgeDomainConfig) isEmpty() bool {
return false
case !rscConfig.DomainID.IsNull():
return false
case !rscConfig.Interface.IsNull():
return false
case !rscConfig.IsolatedVLAN.IsNull():
return false
case !rscConfig.RoutingInterface.IsNull():
Expand Down Expand Up @@ -605,6 +622,9 @@ func (rscData *bridgeDomainData) set(
if rscData.DomainTypeBridge.ValueBool() {
configSet = append(configSet, setPrefix+"domain-type bridge")
}
for _, v := range rscData.Interface {
configSet = append(configSet, setPrefix+"interface "+v.ValueString())
}
if !rscData.IsolatedVLAN.IsNull() {
configSet = append(configSet, setPrefix+"isolated-vlan "+
utils.ConvI64toa(rscData.IsolatedVLAN.ValueInt64()))
Expand Down Expand Up @@ -702,6 +722,8 @@ func (rscData *bridgeDomainData) read(
}
case itemTrim == "domain-type bridge":
rscData.DomainTypeBridge = types.BoolValue(true)
case balt.CutPrefixInString(&itemTrim, "interface "):
rscData.Interface = append(rscData.Interface, types.StringValue(itemTrim))
case balt.CutPrefixInString(&itemTrim, "isolated-vlan "):
rscData.IsolatedVLAN, err = tfdata.ConvAtoi64Value(itemTrim)
if err != nil {
Expand Down Expand Up @@ -799,6 +821,9 @@ func (rscData *bridgeDomainData) delOpts(
delPrefix + "vlan-id-list",
delPrefix + "vxlan",
}
for _, v := range rscData.Interface {
configSet = append(configSet, delPrefix+"interface "+v.ValueString())
}
if rscData.VXLAN != nil {
if rscData.VXLAN.VNIExtendEvpn.ValueBool() {
if v := rscData.RoutingInstance.ValueString(); v != "" && v != junos.DefaultW {
Expand Down
20 changes: 20 additions & 0 deletions internal/providerfwk/resource_bridge_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ import (
"os"
"testing"

"github.com/jeremmfr/terraform-provider-junos/internal/junos"

"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccResourceBridgeDomain_basic(t *testing.T) {
testaccInterface := junos.DefaultInterfaceTestAcc
testaccInterface2 := junos.DefaultInterfaceSwitchTestAcc2
if iface := os.Getenv("TESTACC_INTERFACE"); iface != "" {
testaccInterface = iface
}
if iface := os.Getenv("TESTACC_INTERFACE2"); iface != "" {
testaccInterface2 = iface
}
if os.Getenv("TESTACC_ROUTER") != "" {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -29,6 +39,16 @@ func TestAccResourceBridgeDomain_basic(t *testing.T) {
},
{
ConfigDirectory: config.TestStepDirectory(),
ConfigVariables: map[string]config.Variable{
"interface": config.StringVariable(testaccInterface),
"interface2": config.StringVariable(testaccInterface2),
},
},
{
ConfigDirectory: config.TestStepDirectory(),
ConfigVariables: map[string]config.Variable{
"interface": config.StringVariable(testaccInterface),
},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ resource "junos_bridge_domain" "testacc_bridge_ri" {
routing_instance = junos_routing_instance.testacc_bridge_ri.name
description = "testacc bridge domain routing instance"
routing_interface = "irb.13"
service_id = 12
vlan_id = 13
interface = [
"${var.interface}.0",
"${var.interface2}.0",
]
service_id = 12
vlan_id = 13
vxlan {
vni = 15
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "interface" {
type = string
}

variable "interface2" {
type = string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "junos_bridge_domain" "testacc_default" {
name = "testacc_bd_def"
description = "testacc bridge domain default update"
vlan_id = 8
}
resource "junos_bridge_domain" "testacc_default2" {
name = "testacc_bd_def2"
vlan_id_list = [9]
}

resource "junos_interface_logical" "testacc_bridge_ri" {
name = "lo0.1"
family_inet {
address {
cidr_ip = "${junos_routing_options.testacc_bridge_ri.router_id}/32"
}
}
}
resource "junos_routing_options" "testacc_bridge_ri" {
clean_on_destroy = true
router_id = "192.0.2.5"
}

resource "junos_routing_instance" "testacc_bridge_ri" {
name = "testacc_bridge_ri"
type = "virtual-switch"
route_distinguisher = "10:11"
vrf_target = "target:1:200"
vtep_source_interface = junos_interface_logical.testacc_bridge_ri.name
}
resource "junos_evpn" "testacc_bridge_ri" {
routing_instance = junos_routing_instance.testacc_bridge_ri.name
encapsulation = "vxlan"
multicast_mode = "ingress-replication"
}
resource "junos_bridge_domain" "testacc_bridge_ri" {
depends_on = [
junos_evpn.testacc_bridge_ri
]
name = "testacc_bd_ri"
routing_instance = junos_routing_instance.testacc_bridge_ri.name
description = "testacc bridge domain routing instance"
routing_interface = "irb.13"
interface = [
"${var.interface}.0",
]
service_id = 12
vlan_id = 13
vxlan {
vni = 15
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "interface" {
type = string
}

0 comments on commit b407bcb

Please sign in to comment.