From f14bc66bbba34c21e13621fc74fd1e3e61251ada Mon Sep 17 00:00:00 2001 From: Jorge Gomez Velasquez Date: Thu, 6 Jun 2024 15:38:04 -0700 Subject: [PATCH] Add attributes to isis interface resource (#219) --- docs/data-sources/isis_interface.md | 2 ++ docs/resources/isis_interface.md | 5 +++++ .../resources/nxos_isis_interface/resource.tf | 2 ++ gen/definitions/isis_interface.yaml | 12 ++++++++++++ .../data_source_nxos_isis_interface.go | 8 ++++++++ .../data_source_nxos_isis_interface_test.go | 4 ++++ internal/provider/model_nxos_isis_interface.go | 18 ++++++++++++++++++ .../provider/resource_nxos_isis_interface.go | 10 ++++++++++ .../resource_nxos_isis_interface_test.go | 4 ++++ 9 files changed, 65 insertions(+) diff --git a/docs/data-sources/isis_interface.md b/docs/data-sources/isis_interface.md index 67e74435..983cb0bb 100644 --- a/docs/data-sources/isis_interface.md +++ b/docs/data-sources/isis_interface.md @@ -44,6 +44,7 @@ data "nxos_isis_interface" "example" { - `authentication_type_l1` (String) IS-IS Authentication-Type for Level-1. - `authentication_type_l2` (String) IS-IS Authentication-Type for Level-2. - `circuit_type` (String) Circuit type. +- `enable_ipv4` (Boolean) Enabling ISIS router tag on Interface's IPV4 family. - `hello_interval` (Number) Hello interval. - `hello_interval_l1` (Number) Hello interval Level-1. - `hello_interval_l2` (Number) Hello interval Level-2. @@ -52,6 +53,7 @@ data "nxos_isis_interface" "example" { - `hello_multiplier_l2` (Number) Hello multiplier Level-2. - `hello_padding` (String) Hello padding. - `id` (String) The distinguished name of the object. +- `instance_name` (String) Instance to which the interface belongs to. - `metric_l1` (Number) Interface metric Level-1. - `metric_l2` (Number) Interface metric Level-2. - `mtu_check` (Boolean) MTU Check for IS-IS without specific level. diff --git a/docs/resources/isis_interface.md b/docs/resources/isis_interface.md index 8d6fc04f..bcf0364d 100644 --- a/docs/resources/isis_interface.md +++ b/docs/resources/isis_interface.md @@ -42,6 +42,7 @@ resource "nxos_isis_interface" "example" { hello_multiplier_l1 = 4 hello_multiplier_l2 = 4 hello_padding = "never" + instance_name = "ISIS1" metric_l1 = 1000 metric_l2 = 1000 mtu_check = true @@ -51,6 +52,7 @@ resource "nxos_isis_interface" "example" { passive = "l1" priority_l1 = 80 priority_l2 = 80 + enable_ipv4 = true } ``` @@ -85,6 +87,8 @@ resource "nxos_isis_interface" "example" { - Choices: `l1`, `l2`, `l12` - Default value: `l12` - `device` (String) A device name from the provider configuration. +- `enable_ipv4` (Boolean) Enabling ISIS router tag on Interface's IPV4 family. + - Default value: `false` - `hello_interval` (Number) Hello interval. - Range: `1`-`65535` - Default value: `10` @@ -106,6 +110,7 @@ resource "nxos_isis_interface" "example" { - `hello_padding` (String) Hello padding. - Choices: `always`, `transient`, `never` - Default value: `always` +- `instance_name` (String) Instance to which the interface belongs to. - `metric_l1` (Number) Interface metric Level-1. - Range: `0`-`16777216` - Default value: `16777216` diff --git a/examples/resources/nxos_isis_interface/resource.tf b/examples/resources/nxos_isis_interface/resource.tf index 2d9d1017..aa675c5d 100644 --- a/examples/resources/nxos_isis_interface/resource.tf +++ b/examples/resources/nxos_isis_interface/resource.tf @@ -18,6 +18,7 @@ resource "nxos_isis_interface" "example" { hello_multiplier_l1 = 4 hello_multiplier_l2 = 4 hello_padding = "never" + instance_name = "ISIS1" metric_l1 = 1000 metric_l2 = 1000 mtu_check = true @@ -27,4 +28,5 @@ resource "nxos_isis_interface" "example" { passive = "l1" priority_l1 = 80 priority_l2 = 80 + enable_ipv4 = true } diff --git a/gen/definitions/isis_interface.yaml b/gen/definitions/isis_interface.yaml index aa2e0d4c..ae68c513 100644 --- a/gen/definitions/isis_interface.yaml +++ b/gen/definitions/isis_interface.yaml @@ -154,6 +154,12 @@ attributes: - never default_value: always example: never + - nxos_name: instance + tf_name: instance_name + type: String + description: 'Instance to which the interface belongs to.' + omit_empty_value: true + example: ISIS1 - nxos_name: metricLvl1 tf_name: metric_l1 type: Int64 @@ -228,6 +234,12 @@ attributes: default_value: 64 description: 'Circuit priority.' example: 80 + - nxos_name: v4enable + tf_name: enable_ipv4 + type: Bool + default_value: false + description: "Enabling ISIS router tag on Interface's IPV4 family." + example: true test_prerequisites: - dn: sys/fm/isis class_name: fmIsis diff --git a/internal/provider/data_source_nxos_isis_interface.go b/internal/provider/data_source_nxos_isis_interface.go index cb060b90..d75e555d 100644 --- a/internal/provider/data_source_nxos_isis_interface.go +++ b/internal/provider/data_source_nxos_isis_interface.go @@ -139,6 +139,10 @@ func (d *ISISInterfaceDataSource) Schema(ctx context.Context, req datasource.Sch MarkdownDescription: "Hello padding.", Computed: true, }, + "instance_name": schema.StringAttribute{ + MarkdownDescription: "Instance to which the interface belongs to.", + Computed: true, + }, "metric_l1": schema.Int64Attribute{ MarkdownDescription: "Interface metric Level-1.", Computed: true, @@ -175,6 +179,10 @@ func (d *ISISInterfaceDataSource) Schema(ctx context.Context, req datasource.Sch MarkdownDescription: "Circuit priority.", Computed: true, }, + "enable_ipv4": schema.BoolAttribute{ + MarkdownDescription: "Enabling ISIS router tag on Interface's IPV4 family.", + Computed: true, + }, }, } } diff --git a/internal/provider/data_source_nxos_isis_interface_test.go b/internal/provider/data_source_nxos_isis_interface_test.go index 9b47b804..be24a923 100644 --- a/internal/provider/data_source_nxos_isis_interface_test.go +++ b/internal/provider/data_source_nxos_isis_interface_test.go @@ -49,6 +49,7 @@ func TestAccDataSourceNxosISISInterface(t *testing.T) { resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "hello_multiplier_l1", "4"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "hello_multiplier_l2", "4"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "hello_padding", "never"), + resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "instance_name", "ISIS1"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "metric_l1", "1000"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "metric_l2", "1000"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "mtu_check", "true"), @@ -58,6 +59,7 @@ func TestAccDataSourceNxosISISInterface(t *testing.T) { resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "passive", "l1"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "priority_l1", "80"), resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "priority_l2", "80"), + resource.TestCheckResourceAttr("data.nxos_isis_interface.test", "enable_ipv4", "true"), ), }, }, @@ -104,6 +106,7 @@ resource "nxos_isis_interface" "test" { hello_multiplier_l1 = 4 hello_multiplier_l2 = 4 hello_padding = "never" + instance_name = "ISIS1" metric_l1 = 1000 metric_l2 = 1000 mtu_check = true @@ -113,6 +116,7 @@ resource "nxos_isis_interface" "test" { passive = "l1" priority_l1 = 80 priority_l2 = 80 + enable_ipv4 = true depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, ] } diff --git a/internal/provider/model_nxos_isis_interface.go b/internal/provider/model_nxos_isis_interface.go index 1ce0f5a5..85797f70 100644 --- a/internal/provider/model_nxos_isis_interface.go +++ b/internal/provider/model_nxos_isis_interface.go @@ -52,6 +52,7 @@ type ISISInterface struct { HelloMultiplierL1 types.Int64 `tfsdk:"hello_multiplier_l1"` HelloMultiplierL2 types.Int64 `tfsdk:"hello_multiplier_l2"` HelloPadding types.String `tfsdk:"hello_padding"` + InstanceName types.String `tfsdk:"instance_name"` MetricL1 types.Int64 `tfsdk:"metric_l1"` MetricL2 types.Int64 `tfsdk:"metric_l2"` MtuCheck types.Bool `tfsdk:"mtu_check"` @@ -61,6 +62,7 @@ type ISISInterface struct { Passive types.String `tfsdk:"passive"` PriorityL1 types.Int64 `tfsdk:"priority_l1"` PriorityL2 types.Int64 `tfsdk:"priority_l2"` + EnableIpv4 types.Bool `tfsdk:"enable_ipv4"` } func (data ISISInterface) getDn() string { @@ -131,6 +133,9 @@ func (data ISISInterface) toBody() nxos.Body { if (!data.HelloPadding.IsUnknown() && !data.HelloPadding.IsNull()) || true { body, _ = sjson.Set(body, data.getClassName()+".attributes."+"helloPad", data.HelloPadding.ValueString()) } + if (!data.InstanceName.IsUnknown() && !data.InstanceName.IsNull()) || false { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"instance", data.InstanceName.ValueString()) + } if (!data.MetricL1.IsUnknown() && !data.MetricL1.IsNull()) || true { body, _ = sjson.Set(body, data.getClassName()+".attributes."+"metricLvl1", strconv.FormatInt(data.MetricL1.ValueInt64(), 10)) } @@ -158,6 +163,9 @@ func (data ISISInterface) toBody() nxos.Body { if (!data.PriorityL2.IsUnknown() && !data.PriorityL2.IsNull()) || true { body, _ = sjson.Set(body, data.getClassName()+".attributes."+"priorityLvl2", strconv.FormatInt(data.PriorityL2.ValueInt64(), 10)) } + if (!data.EnableIpv4.IsUnknown() && !data.EnableIpv4.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"v4enable", strconv.FormatBool(data.EnableIpv4.ValueBool())) + } return nxos.Body{body} } @@ -243,6 +251,11 @@ func (data *ISISInterface) fromBody(res gjson.Result, all bool) { } else { data.HelloPadding = types.StringNull() } + if !data.InstanceName.IsNull() || all { + data.InstanceName = types.StringValue(res.Get(data.getClassName() + ".attributes.instance").String()) + } else { + data.InstanceName = types.StringNull() + } if !data.MetricL1.IsNull() || all { data.MetricL1 = types.Int64Value(res.Get(data.getClassName() + ".attributes.metricLvl1").Int()) } else { @@ -288,4 +301,9 @@ func (data *ISISInterface) fromBody(res gjson.Result, all bool) { } else { data.PriorityL2 = types.Int64Null() } + if !data.EnableIpv4.IsNull() || all { + data.EnableIpv4 = types.BoolValue(helpers.ParseNxosBoolean(res.Get(data.getClassName() + ".attributes.v4enable").String())) + } else { + data.EnableIpv4 = types.BoolNull() + } } diff --git a/internal/provider/resource_nxos_isis_interface.go b/internal/provider/resource_nxos_isis_interface.go index 9f8fe2e7..decef227 100644 --- a/internal/provider/resource_nxos_isis_interface.go +++ b/internal/provider/resource_nxos_isis_interface.go @@ -213,6 +213,10 @@ func (r *ISISInterfaceResource) Schema(ctx context.Context, req resource.SchemaR stringvalidator.OneOf("always", "transient", "never"), }, }, + "instance_name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Instance to which the interface belongs to.").String, + Optional: true, + }, "metric_l1": schema.Int64Attribute{ MarkdownDescription: helpers.NewAttributeDescription("Interface metric Level-1.").AddIntegerRangeDescription(0, 16777216).AddDefaultValueDescription("16777216").String, Optional: true, @@ -285,6 +289,12 @@ func (r *ISISInterfaceResource) Schema(ctx context.Context, req resource.SchemaR int64validator.Between(0, 127), }, }, + "enable_ipv4": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Enabling ISIS router tag on Interface's IPV4 family.").AddDefaultValueDescription("false").String, + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, }, } } diff --git a/internal/provider/resource_nxos_isis_interface_test.go b/internal/provider/resource_nxos_isis_interface_test.go index f265c576..04b3d65b 100644 --- a/internal/provider/resource_nxos_isis_interface_test.go +++ b/internal/provider/resource_nxos_isis_interface_test.go @@ -52,6 +52,7 @@ func TestAccNxosISISInterface(t *testing.T) { resource.TestCheckResourceAttr("nxos_isis_interface.test", "hello_multiplier_l1", "4"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "hello_multiplier_l2", "4"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "hello_padding", "never"), + resource.TestCheckResourceAttr("nxos_isis_interface.test", "instance_name", "ISIS1"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "metric_l1", "1000"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "metric_l2", "1000"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "mtu_check", "true"), @@ -61,6 +62,7 @@ func TestAccNxosISISInterface(t *testing.T) { resource.TestCheckResourceAttr("nxos_isis_interface.test", "passive", "l1"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "priority_l1", "80"), resource.TestCheckResourceAttr("nxos_isis_interface.test", "priority_l2", "80"), + resource.TestCheckResourceAttr("nxos_isis_interface.test", "enable_ipv4", "true"), ), }, { @@ -121,6 +123,7 @@ func testAccNxosISISInterfaceConfig_all() string { hello_multiplier_l1 = 4 hello_multiplier_l2 = 4 hello_padding = "never" + instance_name = "ISIS1" metric_l1 = 1000 metric_l2 = 1000 mtu_check = true @@ -130,6 +133,7 @@ func testAccNxosISISInterfaceConfig_all() string { passive = "l1" priority_l1 = 80 priority_l2 = 80 + enable_ipv4 = true depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, ] } `