From 7259ee5e4103505b37767150ddc7577634831a75 Mon Sep 17 00:00:00 2001 From: Jorge Gomez Velasquez Date: Fri, 12 Jan 2024 09:16:23 -0500 Subject: [PATCH] Fix ospf vrf resource and data source (#199) --- CHANGELOG.md | 1 + docs/data-sources/ospf_vrf.md | 2 +- docs/resources/ospf_vrf.md | 16 +++++------ examples/resources/nxos_ospf_vrf/resource.tf | 14 +++++----- gen/definitions/ospf_vrf.yaml | 2 +- .../provider/data_source_nxos_ospf_vrf.go | 2 +- .../data_source_nxos_ospf_vrf_test.go | 4 +-- .../data_source_nxos_vpc_peerlink_test.go | 1 + internal/provider/model_nxos_ospf_vrf.go | 28 +++++++++---------- internal/provider/resource_nxos_ospf_vrf.go | 2 +- .../provider/resource_nxos_ospf_vrf_test.go | 4 +-- .../resource_nxos_vpc_peerlink_test.go | 1 + templates/guides/changelog.md.tmpl | 1 + 13 files changed, 41 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc318189..c427fcd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Add `nxos_vpc_keepalive` resource and data source - Add `nxos_vpc_peerlink` resource and data source +- Fix `bandwidth_reference_unit` of `nxos_ospf_vrf` resource and data source ## 0.5.1 diff --git a/docs/data-sources/ospf_vrf.md b/docs/data-sources/ospf_vrf.md index 7ab07a56..b48e3f7a 100644 --- a/docs/data-sources/ospf_vrf.md +++ b/docs/data-sources/ospf_vrf.md @@ -38,7 +38,7 @@ data "nxos_ospf_vrf" "example" { - `admin_state` (String) Administrative state. - `bandwidth_reference` (Number) Bandwidth reference value. -- `banwidth_reference_unit` (String) Bandwidth reference unit. +- `bandwidth_reference_unit` (String) Bandwidth reference unit. - `distance` (Number) Administrative distance preference. - `id` (String) The distinguished name of the object. - `router_id` (String) Router ID. diff --git a/docs/resources/ospf_vrf.md b/docs/resources/ospf_vrf.md index 164e13cd..41786b37 100644 --- a/docs/resources/ospf_vrf.md +++ b/docs/resources/ospf_vrf.md @@ -36,13 +36,13 @@ This resource can manage the OSPF VRF configuration. ```terraform resource "nxos_ospf_vrf" "example" { - instance_name = "OSPF1" - name = "VRF1" - admin_state = "enabled" - bandwidth_reference = 400000 - banwidth_reference_unit = "mbps" - distance = 110 - router_id = "34.56.78.90" + instance_name = "OSPF1" + name = "VRF1" + admin_state = "enabled" + bandwidth_reference = 400000 + bandwidth_reference_unit = "mbps" + distance = 110 + router_id = "34.56.78.90" } ``` @@ -62,7 +62,7 @@ resource "nxos_ospf_vrf" "example" { - `bandwidth_reference` (Number) Bandwidth reference value. - Range: `0`-`4294967295` - Default value: `40000` -- `banwidth_reference_unit` (String) Bandwidth reference unit. +- `bandwidth_reference_unit` (String) Bandwidth reference unit. - Choices: `mbps`, `gbps` - Default value: `mbps` - `device` (String) A device name from the provider configuration. diff --git a/examples/resources/nxos_ospf_vrf/resource.tf b/examples/resources/nxos_ospf_vrf/resource.tf index 82c3e615..232f8074 100644 --- a/examples/resources/nxos_ospf_vrf/resource.tf +++ b/examples/resources/nxos_ospf_vrf/resource.tf @@ -1,9 +1,9 @@ resource "nxos_ospf_vrf" "example" { - instance_name = "OSPF1" - name = "VRF1" - admin_state = "enabled" - bandwidth_reference = 400000 - banwidth_reference_unit = "mbps" - distance = 110 - router_id = "34.56.78.90" + instance_name = "OSPF1" + name = "VRF1" + admin_state = "enabled" + bandwidth_reference = 400000 + bandwidth_reference_unit = "mbps" + distance = 110 + router_id = "34.56.78.90" } diff --git a/gen/definitions/ospf_vrf.yaml b/gen/definitions/ospf_vrf.yaml index 6c1b2fa7..cd896c2e 100644 --- a/gen/definitions/ospf_vrf.yaml +++ b/gen/definitions/ospf_vrf.yaml @@ -45,7 +45,7 @@ attributes: description: 'Bandwidth reference value.' example: 400000 - nxos_name: bwRefUnit - tf_name: banwidth_reference_unit + tf_name: bandwidth_reference_unit type: String description: 'Bandwidth reference unit.' enum_values: diff --git a/internal/provider/data_source_nxos_ospf_vrf.go b/internal/provider/data_source_nxos_ospf_vrf.go index 690a8931..5e6b4d58 100644 --- a/internal/provider/data_source_nxos_ospf_vrf.go +++ b/internal/provider/data_source_nxos_ospf_vrf.go @@ -79,7 +79,7 @@ func (d *OSPFVRFDataSource) Schema(ctx context.Context, req datasource.SchemaReq MarkdownDescription: "Bandwidth reference value.", Computed: true, }, - "banwidth_reference_unit": schema.StringAttribute{ + "bandwidth_reference_unit": schema.StringAttribute{ MarkdownDescription: "Bandwidth reference unit.", Computed: true, }, diff --git a/internal/provider/data_source_nxos_ospf_vrf_test.go b/internal/provider/data_source_nxos_ospf_vrf_test.go index 63efbfb9..a370672f 100644 --- a/internal/provider/data_source_nxos_ospf_vrf_test.go +++ b/internal/provider/data_source_nxos_ospf_vrf_test.go @@ -36,7 +36,7 @@ func TestAccDataSourceNxosOSPFVRF(t *testing.T) { resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "name", "VRF1"), resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "admin_state", "enabled"), resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "bandwidth_reference", "400000"), - resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "banwidth_reference_unit", "mbps"), + resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "bandwidth_reference_unit", "mbps"), resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "distance", "110"), resource.TestCheckResourceAttr("data.nxos_ospf_vrf.test", "router_id", "34.56.78.90"), ), @@ -79,7 +79,7 @@ resource "nxos_ospf_vrf" "test" { name = "VRF1" admin_state = "enabled" bandwidth_reference = 400000 - banwidth_reference_unit = "mbps" + bandwidth_reference_unit = "mbps" distance = 110 router_id = "34.56.78.90" depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, ] diff --git a/internal/provider/data_source_nxos_vpc_peerlink_test.go b/internal/provider/data_source_nxos_vpc_peerlink_test.go index 2d484d39..23fb03bf 100644 --- a/internal/provider/data_source_nxos_vpc_peerlink_test.go +++ b/internal/provider/data_source_nxos_vpc_peerlink_test.go @@ -71,6 +71,7 @@ resource "nxos_rest" "PreReq3" { resource "nxos_rest" "PreReq4" { dn = "sys/fm/lacp" class_name = "fmLacp" + delete = false content = { = "" } diff --git a/internal/provider/model_nxos_ospf_vrf.go b/internal/provider/model_nxos_ospf_vrf.go index 66f30cb5..52deac33 100644 --- a/internal/provider/model_nxos_ospf_vrf.go +++ b/internal/provider/model_nxos_ospf_vrf.go @@ -30,15 +30,15 @@ import ( ) type OSPFVRF struct { - Device types.String `tfsdk:"device"` - Dn types.String `tfsdk:"id"` - InstanceName types.String `tfsdk:"instance_name"` - Name types.String `tfsdk:"name"` - AdminState types.String `tfsdk:"admin_state"` - BandwidthReference types.Int64 `tfsdk:"bandwidth_reference"` - BanwidthReferenceUnit types.String `tfsdk:"banwidth_reference_unit"` - Distance types.Int64 `tfsdk:"distance"` - RouterId types.String `tfsdk:"router_id"` + Device types.String `tfsdk:"device"` + Dn types.String `tfsdk:"id"` + InstanceName types.String `tfsdk:"instance_name"` + Name types.String `tfsdk:"name"` + AdminState types.String `tfsdk:"admin_state"` + BandwidthReference types.Int64 `tfsdk:"bandwidth_reference"` + BandwidthReferenceUnit types.String `tfsdk:"bandwidth_reference_unit"` + Distance types.Int64 `tfsdk:"distance"` + RouterId types.String `tfsdk:"router_id"` } func (data OSPFVRF) getDn() string { @@ -61,8 +61,8 @@ func (data OSPFVRF) toBody() nxos.Body { if (!data.BandwidthReference.IsUnknown() && !data.BandwidthReference.IsNull()) || true { body, _ = sjson.Set(body, data.getClassName()+".attributes."+"bwRef", strconv.FormatInt(data.BandwidthReference.ValueInt64(), 10)) } - if (!data.BanwidthReferenceUnit.IsUnknown() && !data.BanwidthReferenceUnit.IsNull()) || true { - body, _ = sjson.Set(body, data.getClassName()+".attributes."+"bwRefUnit", data.BanwidthReferenceUnit.ValueString()) + if (!data.BandwidthReferenceUnit.IsUnknown() && !data.BandwidthReferenceUnit.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"bwRefUnit", data.BandwidthReferenceUnit.ValueString()) } if (!data.Distance.IsUnknown() && !data.Distance.IsNull()) || true { body, _ = sjson.Set(body, data.getClassName()+".attributes."+"dist", strconv.FormatInt(data.Distance.ValueInt64(), 10)) @@ -90,10 +90,10 @@ func (data *OSPFVRF) fromBody(res gjson.Result, all bool) { } else { data.BandwidthReference = types.Int64Null() } - if !data.BanwidthReferenceUnit.IsNull() || all { - data.BanwidthReferenceUnit = types.StringValue(res.Get(data.getClassName() + ".attributes.bwRefUnit").String()) + if !data.BandwidthReferenceUnit.IsNull() || all { + data.BandwidthReferenceUnit = types.StringValue(res.Get(data.getClassName() + ".attributes.bwRefUnit").String()) } else { - data.BanwidthReferenceUnit = types.StringNull() + data.BandwidthReferenceUnit = types.StringNull() } if !data.Distance.IsNull() || all { data.Distance = types.Int64Value(res.Get(data.getClassName() + ".attributes.dist").Int()) diff --git a/internal/provider/resource_nxos_ospf_vrf.go b/internal/provider/resource_nxos_ospf_vrf.go index 543ade13..aa62c3fb 100644 --- a/internal/provider/resource_nxos_ospf_vrf.go +++ b/internal/provider/resource_nxos_ospf_vrf.go @@ -104,7 +104,7 @@ func (r *OSPFVRFResource) Schema(ctx context.Context, req resource.SchemaRequest int64validator.Between(0, 4294967295), }, }, - "banwidth_reference_unit": schema.StringAttribute{ + "bandwidth_reference_unit": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Bandwidth reference unit.").AddStringEnumDescription("mbps", "gbps").AddDefaultValueDescription("mbps").String, Optional: true, Computed: true, diff --git a/internal/provider/resource_nxos_ospf_vrf_test.go b/internal/provider/resource_nxos_ospf_vrf_test.go index 9ca927c7..f1f1c0f4 100644 --- a/internal/provider/resource_nxos_ospf_vrf_test.go +++ b/internal/provider/resource_nxos_ospf_vrf_test.go @@ -37,7 +37,7 @@ func TestAccNxosOSPFVRF(t *testing.T) { resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "name", "VRF1"), resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "admin_state", "enabled"), resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "bandwidth_reference", "400000"), - resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "banwidth_reference_unit", "mbps"), + resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "bandwidth_reference_unit", "mbps"), resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "distance", "110"), resource.TestCheckResourceAttr("nxos_ospf_vrf.test", "router_id", "34.56.78.90"), ), @@ -95,7 +95,7 @@ func testAccNxosOSPFVRFConfig_all() string { name = "VRF1" admin_state = "enabled" bandwidth_reference = 400000 - banwidth_reference_unit = "mbps" + bandwidth_reference_unit = "mbps" distance = 110 router_id = "34.56.78.90" depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, ] diff --git a/internal/provider/resource_nxos_vpc_peerlink_test.go b/internal/provider/resource_nxos_vpc_peerlink_test.go index d14dc639..8b5b76ca 100644 --- a/internal/provider/resource_nxos_vpc_peerlink_test.go +++ b/internal/provider/resource_nxos_vpc_peerlink_test.go @@ -76,6 +76,7 @@ resource "nxos_rest" "PreReq3" { resource "nxos_rest" "PreReq4" { dn = "sys/fm/lacp" class_name = "fmLacp" + delete = false content = { = "" } diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 28c13dfd..d62c139d 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -11,6 +11,7 @@ description: |- - Add `nxos_vpc_keepalive` resource and data source - Add `nxos_vpc_peerlink` resource and data source +- Fix `bandwidth_reference_unit` of `nxos_ospf_vrf` resource and data source ## 0.5.1