From 8275a4e94a2372bf553d3306dbce2682fa43834f Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 21 Nov 2023 08:43:25 +0100 Subject: [PATCH] r/interface_physical: add storm_control argument Partial fix #574 --- .changes/issue-574.md | 4 ++++ docs/resources/interface_physical.md | 2 ++ .../providerfwk/resource_interface_physical.go | 16 ++++++++++++++++ .../1/main.tf | 16 +++++++++++----- .../2/main.tf | 5 +++++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.changes/issue-574.md b/.changes/issue-574.md index 7995d5b9..3a3eabd0 100644 --- a/.changes/issue-574.md +++ b/.changes/issue-574.md @@ -2,3 +2,7 @@ FEATURES: * add **junos_forwardingoptions_storm_control_profile** resource (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) + +ENHANCEMENTS: + +* **resource/junos_interface_physical**: add `storm_control` argument (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) diff --git a/docs/resources/interface_physical.md b/docs/resources/interface_physical.md index 93e37897..a59e6aec 100644 --- a/docs/resources/interface_physical.md +++ b/docs/resources/interface_physical.md @@ -110,6 +110,8 @@ The following arguments are supported: - **speed** (Optional, String) Link speed. Must be a valid speed (10m | 100m | 1g ...) +- **storm_control** (Optional, String) + Storm control profile name to bind. - **trunk** (Optional, Boolean) Interface mode is trunk. - **trunk_non_els** (Optional, Boolean) diff --git a/internal/providerfwk/resource_interface_physical.go b/internal/providerfwk/resource_interface_physical.go index 0776a5fc..560ad032 100644 --- a/internal/providerfwk/resource_interface_physical.go +++ b/internal/providerfwk/resource_interface_physical.go @@ -194,6 +194,14 @@ func (rsc *interfacePhysical) Schema( "must be a valid speed (10m | 100m | 1g ...)"), }, }, + "storm_control": schema.StringAttribute{ + Optional: true, + Description: "Storm control profile name to bind.", + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 127), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, "trunk": schema.BoolAttribute{ Optional: true, Description: "Interface mode is trunk.", @@ -641,6 +649,7 @@ type interfacePhysicalData struct { LinkMode types.String `tfsdk:"link_mode"` Mtu types.Int64 `tfsdk:"mtu"` Speed types.String `tfsdk:"speed"` + StormControl types.String `tfsdk:"storm_control"` VlanMembers []types.String `tfsdk:"vlan_members"` VlanNative types.Int64 `tfsdk:"vlan_native"` VlanNativeNonELS types.String `tfsdk:"vlan_native_non_els"` @@ -669,6 +678,7 @@ type interfacePhysicalConfig struct { LinkMode types.String `tfsdk:"link_mode"` Mtu types.Int64 `tfsdk:"mtu"` Speed types.String `tfsdk:"speed"` + StormControl types.String `tfsdk:"storm_control"` VlanMembers types.List `tfsdk:"vlan_members"` VlanNative types.Int64 `tfsdk:"vlan_native"` VlanNativeNonELS types.String `tfsdk:"vlan_native_non_els"` @@ -1737,6 +1747,9 @@ func (rscData *interfacePhysicalData) set( if v := rscData.Speed.ValueString(); v != "" { configSet = append(configSet, setPrefix+"speed "+v) } + if v := rscData.StormControl.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"unit 0 family ethernet-switching storm-control \""+v+"\"") + } if rscData.Trunk.ValueBool() { configSet = append(configSet, setPrefix+"unit 0 family ethernet-switching interface-mode trunk") } @@ -2028,6 +2041,8 @@ func (rscData *interfacePhysicalData) read( rscData.NoGratuitousArpRequest = types.BoolValue(true) case balt.CutPrefixInString(&itemTrim, "speed "): rscData.Speed = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "unit 0 family ethernet-switching storm-control "): + rscData.StormControl = types.StringValue(strings.Trim(itemTrim, "\"")) case itemTrim == "unit 0 family ethernet-switching interface-mode trunk": rscData.Trunk = types.BoolValue(true) case itemTrim == "unit 0 family ethernet-switching port-mode trunk": @@ -2228,6 +2243,7 @@ func (rscData *interfacePhysicalData) delOpts( delPrefix + "unit 0 family ethernet-switching interface-mode", delPrefix + "unit 0 family ethernet-switching native-vlan-id", delPrefix + "unit 0 family ethernet-switching port-mode", + delPrefix + "unit 0 family ethernet-switching storm-control", delPrefix + "unit 0 family ethernet-switching vlan members", delPrefix + "vlan-tagging", } diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf index b4e5e667..2d2c6f28 100644 --- a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf @@ -1,7 +1,13 @@ resource "junos_interface_physical" "testacc_interface" { - name = var.interface - description = "testacc_interface" - trunk = true - vlan_native = 100 - vlan_members = ["100-110"] + name = var.interface + description = "testacc_interface" + storm_control = junos_forwardingoptions_storm_control_profile.testacc_interface.name + trunk = true + vlan_native = 100 + vlan_members = ["100-110"] +} + +resource "junos_forwardingoptions_storm_control_profile" "testacc_interface" { + name = "testacc interface" + all {} } diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf index 4d8df0b3..21e1068b 100644 --- a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf @@ -3,3 +3,8 @@ resource "junos_interface_physical" "testacc_interface" { description = "testacc_interfaceU" vlan_members = ["100"] } + +resource "junos_forwardingoptions_storm_control_profile" "testacc_interface" { + name = "testacc interface" + all {} +}