From dffb94340cbf2db1418d8be7c2c0a3a1bec21a22 Mon Sep 17 00:00:00 2001 From: danischm Date: Thu, 21 Mar 2024 21:22:33 +0100 Subject: [PATCH] Update changelog and cleanup --- CHANGELOG.md | 4 + docs/guides/changelog.md | 4 + .../router_static_vrf_ipv4_multicast.md | 2 +- .../router_static_vrf_ipv4_unicast.md | 2 +- .../router_static_vrf_ipv6_multicast.md | 2 +- .../router_static_vrf_ipv6_unicast.md | 2 +- .../iosxr_router_static_vrf/data-source.tf | 3 - .../iosxr_router_static_vrf/import.sh | 1 - .../iosxr_router_static_vrf/resource.tf | 3 - .../import.sh | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- ... => router_static_vrf_ipv4_multicast.yaml} | 0 ...ml => router_static_vrf_ipv4_unicast.yaml} | 0 ... => router_static_vrf_ipv6_multicast.yaml} | 0 ...ml => router_static_vrf_ipv6_unicast.yaml} | 0 .../data_source_iosxr_router_static_vrf.go | 106 ------- ...ata_source_iosxr_router_static_vrf_test.go | 55 ---- .../provider/model_iosxr_router_static_vrf.go | 78 ------ ..._iosxr_router_static_vrf_ipv4_multicast.go | 206 ++++++++++++++ ...el_iosxr_router_static_vrf_ipv4_unicast.go | 206 ++++++++++++++ ..._iosxr_router_static_vrf_ipv6_multicast.go | 206 ++++++++++++++ ...el_iosxr_router_static_vrf_ipv6_unicast.go | 206 ++++++++++++++ .../resource_iosxr_router_static_vrf.go | 258 ------------------ ..._iosxr_router_static_vrf_ipv4_multicast.go | 31 ++- ...r_router_static_vrf_ipv4_multicast_test.go | 3 +- ...ce_iosxr_router_static_vrf_ipv4_unicast.go | 31 ++- ...sxr_router_static_vrf_ipv4_unicast_test.go | 3 +- ..._iosxr_router_static_vrf_ipv6_multicast.go | 31 ++- ...r_router_static_vrf_ipv6_multicast_test.go | 3 +- ...ce_iosxr_router_static_vrf_ipv6_unicast.go | 31 ++- ...sxr_router_static_vrf_ipv6_unicast_test.go | 3 +- .../resource_iosxr_router_static_vrf_test.go | 66 ----- templates/guides/changelog.md.tmpl | 4 + 35 files changed, 968 insertions(+), 590 deletions(-) delete mode 100644 examples/data-sources/iosxr_router_static_vrf/data-source.tf delete mode 100644 examples/resources/iosxr_router_static_vrf/import.sh delete mode 100644 examples/resources/iosxr_router_static_vrf/resource.tf rename gen/definitions/{router_static_vrf_address_family_ipv4_multicast.yaml => router_static_vrf_ipv4_multicast.yaml} (100%) rename gen/definitions/{router_static_vrf_address_family_ipv4_unicast.yaml => router_static_vrf_ipv4_unicast.yaml} (100%) rename gen/definitions/{router_static_vrf_address_family_ipv6_multicast.yaml => router_static_vrf_ipv6_multicast.yaml} (100%) rename gen/definitions/{router_static_vrf_address_family_ipv6_unicast.yaml => router_static_vrf_ipv6_unicast.yaml} (100%) delete mode 100644 internal/provider/data_source_iosxr_router_static_vrf.go delete mode 100644 internal/provider/data_source_iosxr_router_static_vrf_test.go delete mode 100644 internal/provider/model_iosxr_router_static_vrf.go delete mode 100644 internal/provider/resource_iosxr_router_static_vrf.go delete mode 100644 internal/provider/resource_iosxr_router_static_vrf_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 408a7792..9fc169cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ - Add `next_hop_self`, `soft_reconfiguration_inbound_always`, `send_community_ebgp`, `send_community_ebgp_inheritance_disable`, `maximum_prefix_limit`, `maximum_prefix_threshold`, `maximum_prefix_restart`, `maximum_prefix_discard_extra_paths`, `maximum_prefix_warning_only`, `default_originate_route_policy` and `default_originate_inheritance_disable` attributes to `iosxr_router_bgp_neighbor_address_family` resource and data source - Add `timers_keepalive_interval`, `timers_holdtime` and `timers_minimum_acceptable_holdtime` attributes to `iosxr_router_bgp_neighbor_group` resource and data source - Make `index_sid_index` and `absolute_sid_label` attribute of `iosxr_router_ospf_area_interface` resource optional +- Add `iosxr_router_static_vrf_ipv4_unicast` resource and data source +- Add `iosxr_router_static_vrf_ipv4_multicast` resource and data source +- Add `iosxr_router_static_vrf_ipv6_unicast` resource and data source +- Add `iosxr_router_static_vrf_ipv6_multicast` resource and data source ## 0.4.0 diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 051d768d..c12fd023 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -12,6 +12,10 @@ description: |- - Add `next_hop_self`, `soft_reconfiguration_inbound_always`, `send_community_ebgp`, `send_community_ebgp_inheritance_disable`, `maximum_prefix_limit`, `maximum_prefix_threshold`, `maximum_prefix_restart`, `maximum_prefix_discard_extra_paths`, `maximum_prefix_warning_only`, `default_originate_route_policy` and `default_originate_inheritance_disable` attributes to `iosxr_router_bgp_neighbor_address_family` resource and data source - Add `timers_keepalive_interval`, `timers_holdtime` and `timers_minimum_acceptable_holdtime` attributes to `iosxr_router_bgp_neighbor_group` resource and data source - Make `index_sid_index` and `absolute_sid_label` attribute of `iosxr_router_ospf_area_interface` resource optional +- Add `iosxr_router_static_vrf_ipv4_unicast` resource and data source +- Add `iosxr_router_static_vrf_ipv4_multicast` resource and data source +- Add `iosxr_router_static_vrf_ipv6_unicast` resource and data source +- Add `iosxr_router_static_vrf_ipv6_multicast` resource and data source ## 0.4.0 diff --git a/docs/resources/router_static_vrf_ipv4_multicast.md b/docs/resources/router_static_vrf_ipv4_multicast.md index 24ba1442..dddd2bb4 100644 --- a/docs/resources/router_static_vrf_ipv4_multicast.md +++ b/docs/resources/router_static_vrf_ipv4_multicast.md @@ -250,5 +250,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import iosxr_router_static_vrf_ipv4_multicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv4/multicast/prefixes/prefix[prefix-address=100.0.1.0][prefix-length=%!d(string=24)]" +terraform import iosxr_router_static_vrf_ipv4_multicast.example ",," ``` diff --git a/docs/resources/router_static_vrf_ipv4_unicast.md b/docs/resources/router_static_vrf_ipv4_unicast.md index 890323e2..b1cbb501 100644 --- a/docs/resources/router_static_vrf_ipv4_unicast.md +++ b/docs/resources/router_static_vrf_ipv4_unicast.md @@ -250,5 +250,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import iosxr_router_static_vrf_ipv4_unicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv4/unicast/prefixes/prefix[prefix-address=100.0.1.0][prefix-length=%!d(string=24)]" +terraform import iosxr_router_static_vrf_ipv4_unicast.example ",," ``` diff --git a/docs/resources/router_static_vrf_ipv6_multicast.md b/docs/resources/router_static_vrf_ipv6_multicast.md index 2c66ec81..b728e2d5 100644 --- a/docs/resources/router_static_vrf_ipv6_multicast.md +++ b/docs/resources/router_static_vrf_ipv6_multicast.md @@ -250,5 +250,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import iosxr_router_static_vrf_ipv6_multicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv6/multicast/prefixes/prefix[prefix-address=1::][prefix-length=%!d(string=64)]" +terraform import iosxr_router_static_vrf_ipv6_multicast.example ",," ``` diff --git a/docs/resources/router_static_vrf_ipv6_unicast.md b/docs/resources/router_static_vrf_ipv6_unicast.md index 6a510476..54b0de01 100644 --- a/docs/resources/router_static_vrf_ipv6_unicast.md +++ b/docs/resources/router_static_vrf_ipv6_unicast.md @@ -250,5 +250,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import iosxr_router_static_vrf_ipv6_unicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv6/unicast/prefixes/prefix[prefix-address=1::][prefix-length=%!d(string=64)]" +terraform import iosxr_router_static_vrf_ipv6_unicast.example ",," ``` diff --git a/examples/data-sources/iosxr_router_static_vrf/data-source.tf b/examples/data-sources/iosxr_router_static_vrf/data-source.tf deleted file mode 100644 index d01dd98d..00000000 --- a/examples/data-sources/iosxr_router_static_vrf/data-source.tf +++ /dev/null @@ -1,3 +0,0 @@ -data "iosxr_router_static_vrf" "example" { - vrf_name = "VRF2" -} diff --git a/examples/resources/iosxr_router_static_vrf/import.sh b/examples/resources/iosxr_router_static_vrf/import.sh deleted file mode 100644 index 5b3bcacd..00000000 --- a/examples/resources/iosxr_router_static_vrf/import.sh +++ /dev/null @@ -1 +0,0 @@ -terraform import iosxr_router_static_vrf.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]" diff --git a/examples/resources/iosxr_router_static_vrf/resource.tf b/examples/resources/iosxr_router_static_vrf/resource.tf deleted file mode 100644 index 0efd11db..00000000 --- a/examples/resources/iosxr_router_static_vrf/resource.tf +++ /dev/null @@ -1,3 +0,0 @@ -resource "iosxr_router_static_vrf" "example" { - vrf_name = "VRF2" -} diff --git a/examples/resources/iosxr_router_static_vrf_ipv4_multicast/import.sh b/examples/resources/iosxr_router_static_vrf_ipv4_multicast/import.sh index 66dc31d8..a6113529 100644 --- a/examples/resources/iosxr_router_static_vrf_ipv4_multicast/import.sh +++ b/examples/resources/iosxr_router_static_vrf_ipv4_multicast/import.sh @@ -1 +1 @@ -terraform import iosxr_router_static_vrf_ipv4_multicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv4/multicast/prefixes/prefix[prefix-address=100.0.1.0][prefix-length=%!d(string=24)]" +terraform import iosxr_router_static_vrf_ipv4_multicast.example ",," diff --git a/examples/resources/iosxr_router_static_vrf_ipv4_unicast/import.sh b/examples/resources/iosxr_router_static_vrf_ipv4_unicast/import.sh index 40aabbe2..eb77c754 100644 --- a/examples/resources/iosxr_router_static_vrf_ipv4_unicast/import.sh +++ b/examples/resources/iosxr_router_static_vrf_ipv4_unicast/import.sh @@ -1 +1 @@ -terraform import iosxr_router_static_vrf_ipv4_unicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv4/unicast/prefixes/prefix[prefix-address=100.0.1.0][prefix-length=%!d(string=24)]" +terraform import iosxr_router_static_vrf_ipv4_unicast.example ",," diff --git a/examples/resources/iosxr_router_static_vrf_ipv6_multicast/import.sh b/examples/resources/iosxr_router_static_vrf_ipv6_multicast/import.sh index ee804dd6..e6dea4b7 100644 --- a/examples/resources/iosxr_router_static_vrf_ipv6_multicast/import.sh +++ b/examples/resources/iosxr_router_static_vrf_ipv6_multicast/import.sh @@ -1 +1 @@ -terraform import iosxr_router_static_vrf_ipv6_multicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv6/multicast/prefixes/prefix[prefix-address=1::][prefix-length=%!d(string=64)]" +terraform import iosxr_router_static_vrf_ipv6_multicast.example ",," diff --git a/examples/resources/iosxr_router_static_vrf_ipv6_unicast/import.sh b/examples/resources/iosxr_router_static_vrf_ipv6_unicast/import.sh index fbe6da8b..1a647792 100644 --- a/examples/resources/iosxr_router_static_vrf_ipv6_unicast/import.sh +++ b/examples/resources/iosxr_router_static_vrf_ipv6_unicast/import.sh @@ -1 +1 @@ -terraform import iosxr_router_static_vrf_ipv6_unicast.example "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv6/unicast/prefixes/prefix[prefix-address=1::][prefix-length=%!d(string=64)]" +terraform import iosxr_router_static_vrf_ipv6_unicast.example ",," diff --git a/gen/definitions/router_static_vrf_address_family_ipv4_multicast.yaml b/gen/definitions/router_static_vrf_ipv4_multicast.yaml similarity index 100% rename from gen/definitions/router_static_vrf_address_family_ipv4_multicast.yaml rename to gen/definitions/router_static_vrf_ipv4_multicast.yaml diff --git a/gen/definitions/router_static_vrf_address_family_ipv4_unicast.yaml b/gen/definitions/router_static_vrf_ipv4_unicast.yaml similarity index 100% rename from gen/definitions/router_static_vrf_address_family_ipv4_unicast.yaml rename to gen/definitions/router_static_vrf_ipv4_unicast.yaml diff --git a/gen/definitions/router_static_vrf_address_family_ipv6_multicast.yaml b/gen/definitions/router_static_vrf_ipv6_multicast.yaml similarity index 100% rename from gen/definitions/router_static_vrf_address_family_ipv6_multicast.yaml rename to gen/definitions/router_static_vrf_ipv6_multicast.yaml diff --git a/gen/definitions/router_static_vrf_address_family_ipv6_unicast.yaml b/gen/definitions/router_static_vrf_ipv6_unicast.yaml similarity index 100% rename from gen/definitions/router_static_vrf_address_family_ipv6_unicast.yaml rename to gen/definitions/router_static_vrf_ipv6_unicast.yaml diff --git a/internal/provider/data_source_iosxr_router_static_vrf.go b/internal/provider/data_source_iosxr_router_static_vrf.go deleted file mode 100644 index dcc752f5..00000000 --- a/internal/provider/data_source_iosxr_router_static_vrf.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright © 2023 Cisco Systems, Inc. and its affiliates. -// All rights reserved. -// -// Licensed under the Mozilla Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://mozilla.org/MPL/2.0/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// SPDX-License-Identifier: MPL-2.0 - -// Code generated by "gen/generator.go"; DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - - "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client" - "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" -) - -// Ensure the implementation satisfies the expected interfaces. -var ( - _ datasource.DataSource = &RouterStaticVRFDataSource{} - _ datasource.DataSourceWithConfigure = &RouterStaticVRFDataSource{} -) - -func NewRouterStaticVRFDataSource() datasource.DataSource { - return &RouterStaticVRFDataSource{} -} - -type RouterStaticVRFDataSource struct { - client *client.Client -} - -func (d *RouterStaticVRFDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_router_static_vrf" -} - -func (d *RouterStaticVRFDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - // This description is used by the documentation generator and the language server. - MarkdownDescription: "This data source can read the Router Static VRF configuration.", - - Attributes: map[string]schema.Attribute{ - "device": schema.StringAttribute{ - MarkdownDescription: "A device name from the provider configuration.", - Optional: true, - }, - "id": schema.StringAttribute{ - MarkdownDescription: "The path of the retrieved object.", - Computed: true, - }, - "vrf_name": schema.StringAttribute{ - MarkdownDescription: "VRF Static route configuration subcommands", - Required: true, - }, - }, - } -} - -func (d *RouterStaticVRFDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { - if req.ProviderData == nil { - return - } - - d.client = req.ProviderData.(*client.Client) -} - -func (d *RouterStaticVRFDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var config RouterStaticVRFData - - // Read config - diags := req.Config.Get(ctx, &config) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.getPath())) - - getResp, diags := d.client.Get(ctx, config.Device.ValueString(), config.getPath()) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - config.fromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal()) - config.Id = types.StringValue(config.getPath()) - - tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.getPath())) - - diags = resp.State.Set(ctx, &config) - resp.Diagnostics.Append(diags...) -} diff --git a/internal/provider/data_source_iosxr_router_static_vrf_test.go b/internal/provider/data_source_iosxr_router_static_vrf_test.go deleted file mode 100644 index 9f0404d3..00000000 --- a/internal/provider/data_source_iosxr_router_static_vrf_test.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright © 2023 Cisco Systems, Inc. and its affiliates. -// All rights reserved. -// -// Licensed under the Mozilla Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://mozilla.org/MPL/2.0/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// SPDX-License-Identifier: MPL-2.0 - -// Code generated by "gen/generator.go"; DO NOT EDIT. - -package provider - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" -) - -func TestAccDataSourceIosxrRouterStaticVRF(t *testing.T) { - var checks []resource.TestCheckFunc - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceIosxrRouterStaticVRFConfig(), - Check: resource.ComposeTestCheckFunc(checks...), - }, - }, - }) -} - -func testAccDataSourceIosxrRouterStaticVRFConfig() string { - config := `resource "iosxr_router_static_vrf" "test" {` + "\n" - config += ` delete_mode = "attributes"` + "\n" - config += ` vrf_name = "VRF2"` + "\n" - config += `}` + "\n" - - config += ` - data "iosxr_router_static_vrf" "test" { - vrf_name = "VRF2" - depends_on = [iosxr_router_static_vrf.test] - } - ` - return config -} diff --git a/internal/provider/model_iosxr_router_static_vrf.go b/internal/provider/model_iosxr_router_static_vrf.go deleted file mode 100644 index b900195a..00000000 --- a/internal/provider/model_iosxr_router_static_vrf.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright © 2023 Cisco Systems, Inc. and its affiliates. -// All rights reserved. -// -// Licensed under the Mozilla Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://mozilla.org/MPL/2.0/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// SPDX-License-Identifier: MPL-2.0 - -// Code generated by "gen/generator.go"; DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/tidwall/sjson" -) - -type RouterStaticVRF struct { - Device types.String `tfsdk:"device"` - Id types.String `tfsdk:"id"` - DeleteMode types.String `tfsdk:"delete_mode"` - VrfName types.String `tfsdk:"vrf_name"` -} - -type RouterStaticVRFData struct { - Device types.String `tfsdk:"device"` - Id types.String `tfsdk:"id"` - VrfName types.String `tfsdk:"vrf_name"` -} - -func (data RouterStaticVRF) getPath() string { - return fmt.Sprintf("Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=%s]", data.VrfName.ValueString()) -} - -func (data RouterStaticVRFData) getPath() string { - return fmt.Sprintf("Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=%s]", data.VrfName.ValueString()) -} - -func (data RouterStaticVRF) toBody(ctx context.Context) string { - body := "{}" - if !data.VrfName.IsNull() && !data.VrfName.IsUnknown() { - body, _ = sjson.Set(body, "vrf-name", data.VrfName.ValueString()) - } - return body -} - -func (data *RouterStaticVRF) updateFromBody(ctx context.Context, res []byte) { -} - -func (data *RouterStaticVRFData) fromBody(ctx context.Context, res []byte) { -} - -func (data *RouterStaticVRF) getDeletedItems(ctx context.Context, state RouterStaticVRF) []string { - deletedItems := make([]string, 0) - return deletedItems -} - -func (data *RouterStaticVRF) getEmptyLeafsDelete(ctx context.Context) []string { - emptyLeafsDelete := make([]string, 0) - return emptyLeafsDelete -} - -func (data *RouterStaticVRF) getDeletePaths(ctx context.Context) []string { - var deletePaths []string - return deletePaths -} diff --git a/internal/provider/model_iosxr_router_static_vrf_ipv4_multicast.go b/internal/provider/model_iosxr_router_static_vrf_ipv4_multicast.go index 2b288a1a..9bfdc800 100644 --- a/internal/provider/model_iosxr_router_static_vrf_ipv4_multicast.go +++ b/internal/provider/model_iosxr_router_static_vrf_ipv4_multicast.go @@ -738,6 +738,212 @@ func (data *RouterStaticVRFIPv4Multicast) updateFromBody(ctx context.Context, re } } +func (data *RouterStaticVRFIPv4Multicast) fromBody(ctx context.Context, res []byte) { + if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { + data.NexthopInterfaces = make([]RouterStaticVRFIPv4MulticastNexthopInterfaces, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4MulticastNexthopInterfaces{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaces = append(data.NexthopInterfaces, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-interface-addresses.nexthop-interface-address"); value.Exists() { + data.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv4MulticastNexthopInterfaceAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4MulticastNexthopInterfaceAddresses{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaceAddresses = append(data.NexthopInterfaceAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-addresses.nexthop-address"); value.Exists() { + data.NexthopAddresses = make([]RouterStaticVRFIPv4MulticastNexthopAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4MulticastNexthopAddresses{} + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopAddresses = append(data.NexthopAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "vrfs.vrf"); value.Exists() { + data.Vrfs = make([]RouterStaticVRFIPv4MulticastVrfs, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4MulticastVrfs{} + if cValue := v.Get("vrf-name"); cValue.Exists() { + item.VrfName = types.StringValue(cValue.String()) + } + if cValue := v.Get("nexthop-interfaces.nexthop-interface"); cValue.Exists() { + item.NexthopInterfaces = make([]RouterStaticVRFIPv4MulticastVrfsNexthopInterfaces, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv4MulticastVrfsNexthopInterfaces{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaces = append(item.NexthopInterfaces, cItem) + return true + }) + } + if cValue := v.Get("nexthop-interface-addresses.nexthop-interface-address"); cValue.Exists() { + item.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv4MulticastVrfsNexthopInterfaceAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv4MulticastVrfsNexthopInterfaceAddresses{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaceAddresses = append(item.NexthopInterfaceAddresses, cItem) + return true + }) + } + if cValue := v.Get("nexthop-addresses.nexthop-address"); cValue.Exists() { + item.NexthopAddresses = make([]RouterStaticVRFIPv4MulticastVrfsNexthopAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv4MulticastVrfsNexthopAddresses{} + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopAddresses = append(item.NexthopAddresses, cItem) + return true + }) + } + data.Vrfs = append(data.Vrfs, item) + return true + }) + } +} + func (data *RouterStaticVRFIPv4MulticastData) fromBody(ctx context.Context, res []byte) { if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { data.NexthopInterfaces = make([]RouterStaticVRFIPv4MulticastNexthopInterfaces, 0) diff --git a/internal/provider/model_iosxr_router_static_vrf_ipv4_unicast.go b/internal/provider/model_iosxr_router_static_vrf_ipv4_unicast.go index 82008684..8fcd4ec5 100644 --- a/internal/provider/model_iosxr_router_static_vrf_ipv4_unicast.go +++ b/internal/provider/model_iosxr_router_static_vrf_ipv4_unicast.go @@ -738,6 +738,212 @@ func (data *RouterStaticVRFIPv4Unicast) updateFromBody(ctx context.Context, res } } +func (data *RouterStaticVRFIPv4Unicast) fromBody(ctx context.Context, res []byte) { + if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { + data.NexthopInterfaces = make([]RouterStaticVRFIPv4UnicastNexthopInterfaces, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4UnicastNexthopInterfaces{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaces = append(data.NexthopInterfaces, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-interface-addresses.nexthop-interface-address"); value.Exists() { + data.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv4UnicastNexthopInterfaceAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4UnicastNexthopInterfaceAddresses{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaceAddresses = append(data.NexthopInterfaceAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-addresses.nexthop-address"); value.Exists() { + data.NexthopAddresses = make([]RouterStaticVRFIPv4UnicastNexthopAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4UnicastNexthopAddresses{} + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopAddresses = append(data.NexthopAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "vrfs.vrf"); value.Exists() { + data.Vrfs = make([]RouterStaticVRFIPv4UnicastVrfs, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv4UnicastVrfs{} + if cValue := v.Get("vrf-name"); cValue.Exists() { + item.VrfName = types.StringValue(cValue.String()) + } + if cValue := v.Get("nexthop-interfaces.nexthop-interface"); cValue.Exists() { + item.NexthopInterfaces = make([]RouterStaticVRFIPv4UnicastVrfsNexthopInterfaces, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv4UnicastVrfsNexthopInterfaces{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaces = append(item.NexthopInterfaces, cItem) + return true + }) + } + if cValue := v.Get("nexthop-interface-addresses.nexthop-interface-address"); cValue.Exists() { + item.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv4UnicastVrfsNexthopInterfaceAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv4UnicastVrfsNexthopInterfaceAddresses{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaceAddresses = append(item.NexthopInterfaceAddresses, cItem) + return true + }) + } + if cValue := v.Get("nexthop-addresses.nexthop-address"); cValue.Exists() { + item.NexthopAddresses = make([]RouterStaticVRFIPv4UnicastVrfsNexthopAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv4UnicastVrfsNexthopAddresses{} + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopAddresses = append(item.NexthopAddresses, cItem) + return true + }) + } + data.Vrfs = append(data.Vrfs, item) + return true + }) + } +} + func (data *RouterStaticVRFIPv4UnicastData) fromBody(ctx context.Context, res []byte) { if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { data.NexthopInterfaces = make([]RouterStaticVRFIPv4UnicastNexthopInterfaces, 0) diff --git a/internal/provider/model_iosxr_router_static_vrf_ipv6_multicast.go b/internal/provider/model_iosxr_router_static_vrf_ipv6_multicast.go index 0bb37e0b..e585613b 100644 --- a/internal/provider/model_iosxr_router_static_vrf_ipv6_multicast.go +++ b/internal/provider/model_iosxr_router_static_vrf_ipv6_multicast.go @@ -738,6 +738,212 @@ func (data *RouterStaticVRFIPv6Multicast) updateFromBody(ctx context.Context, re } } +func (data *RouterStaticVRFIPv6Multicast) fromBody(ctx context.Context, res []byte) { + if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { + data.NexthopInterfaces = make([]RouterStaticVRFIPv6MulticastNexthopInterfaces, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6MulticastNexthopInterfaces{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaces = append(data.NexthopInterfaces, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-interface-addresses.nexthop-interface-address"); value.Exists() { + data.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv6MulticastNexthopInterfaceAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6MulticastNexthopInterfaceAddresses{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaceAddresses = append(data.NexthopInterfaceAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-addresses.nexthop-address"); value.Exists() { + data.NexthopAddresses = make([]RouterStaticVRFIPv6MulticastNexthopAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6MulticastNexthopAddresses{} + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopAddresses = append(data.NexthopAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "vrfs.vrf"); value.Exists() { + data.Vrfs = make([]RouterStaticVRFIPv6MulticastVrfs, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6MulticastVrfs{} + if cValue := v.Get("vrf-name"); cValue.Exists() { + item.VrfName = types.StringValue(cValue.String()) + } + if cValue := v.Get("nexthop-interfaces.nexthop-interface"); cValue.Exists() { + item.NexthopInterfaces = make([]RouterStaticVRFIPv6MulticastVrfsNexthopInterfaces, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv6MulticastVrfsNexthopInterfaces{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaces = append(item.NexthopInterfaces, cItem) + return true + }) + } + if cValue := v.Get("nexthop-interface-addresses.nexthop-interface-address"); cValue.Exists() { + item.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv6MulticastVrfsNexthopInterfaceAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv6MulticastVrfsNexthopInterfaceAddresses{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaceAddresses = append(item.NexthopInterfaceAddresses, cItem) + return true + }) + } + if cValue := v.Get("nexthop-addresses.nexthop-address"); cValue.Exists() { + item.NexthopAddresses = make([]RouterStaticVRFIPv6MulticastVrfsNexthopAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv6MulticastVrfsNexthopAddresses{} + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopAddresses = append(item.NexthopAddresses, cItem) + return true + }) + } + data.Vrfs = append(data.Vrfs, item) + return true + }) + } +} + func (data *RouterStaticVRFIPv6MulticastData) fromBody(ctx context.Context, res []byte) { if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { data.NexthopInterfaces = make([]RouterStaticVRFIPv6MulticastNexthopInterfaces, 0) diff --git a/internal/provider/model_iosxr_router_static_vrf_ipv6_unicast.go b/internal/provider/model_iosxr_router_static_vrf_ipv6_unicast.go index 326ac9bf..1788c6dc 100644 --- a/internal/provider/model_iosxr_router_static_vrf_ipv6_unicast.go +++ b/internal/provider/model_iosxr_router_static_vrf_ipv6_unicast.go @@ -738,6 +738,212 @@ func (data *RouterStaticVRFIPv6Unicast) updateFromBody(ctx context.Context, res } } +func (data *RouterStaticVRFIPv6Unicast) fromBody(ctx context.Context, res []byte) { + if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { + data.NexthopInterfaces = make([]RouterStaticVRFIPv6UnicastNexthopInterfaces, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6UnicastNexthopInterfaces{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaces = append(data.NexthopInterfaces, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-interface-addresses.nexthop-interface-address"); value.Exists() { + data.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv6UnicastNexthopInterfaceAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6UnicastNexthopInterfaceAddresses{} + if cValue := v.Get("interface-name"); cValue.Exists() { + item.InterfaceName = types.StringValue(cValue.String()) + } + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopInterfaceAddresses = append(data.NexthopInterfaceAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "nexthop-addresses.nexthop-address"); value.Exists() { + data.NexthopAddresses = make([]RouterStaticVRFIPv6UnicastNexthopAddresses, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6UnicastNexthopAddresses{} + if cValue := v.Get("address"); cValue.Exists() { + item.Address = types.StringValue(cValue.String()) + } + if cValue := v.Get("description"); cValue.Exists() { + item.Description = types.StringValue(cValue.String()) + } + if cValue := v.Get("tag"); cValue.Exists() { + item.Tag = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("distance-metric"); cValue.Exists() { + item.DistanceMetric = types.Int64Value(cValue.Int()) + } + if cValue := v.Get("permanent"); cValue.Exists() { + item.Permanent = types.BoolValue(true) + } else { + item.Permanent = types.BoolValue(false) + } + if cValue := v.Get("track"); cValue.Exists() { + item.Track = types.StringValue(cValue.String()) + } + if cValue := v.Get("metric"); cValue.Exists() { + item.Metric = types.Int64Value(cValue.Int()) + } + data.NexthopAddresses = append(data.NexthopAddresses, item) + return true + }) + } + if value := gjson.GetBytes(res, "vrfs.vrf"); value.Exists() { + data.Vrfs = make([]RouterStaticVRFIPv6UnicastVrfs, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := RouterStaticVRFIPv6UnicastVrfs{} + if cValue := v.Get("vrf-name"); cValue.Exists() { + item.VrfName = types.StringValue(cValue.String()) + } + if cValue := v.Get("nexthop-interfaces.nexthop-interface"); cValue.Exists() { + item.NexthopInterfaces = make([]RouterStaticVRFIPv6UnicastVrfsNexthopInterfaces, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv6UnicastVrfsNexthopInterfaces{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaces = append(item.NexthopInterfaces, cItem) + return true + }) + } + if cValue := v.Get("nexthop-interface-addresses.nexthop-interface-address"); cValue.Exists() { + item.NexthopInterfaceAddresses = make([]RouterStaticVRFIPv6UnicastVrfsNexthopInterfaceAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv6UnicastVrfsNexthopInterfaceAddresses{} + if ccValue := cv.Get("interface-name"); ccValue.Exists() { + cItem.InterfaceName = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopInterfaceAddresses = append(item.NexthopInterfaceAddresses, cItem) + return true + }) + } + if cValue := v.Get("nexthop-addresses.nexthop-address"); cValue.Exists() { + item.NexthopAddresses = make([]RouterStaticVRFIPv6UnicastVrfsNexthopAddresses, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := RouterStaticVRFIPv6UnicastVrfsNexthopAddresses{} + if ccValue := cv.Get("address"); ccValue.Exists() { + cItem.Address = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("description"); ccValue.Exists() { + cItem.Description = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("tag"); ccValue.Exists() { + cItem.Tag = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("distance-metric"); ccValue.Exists() { + cItem.DistanceMetric = types.Int64Value(ccValue.Int()) + } + if ccValue := cv.Get("permanent"); ccValue.Exists() { + cItem.Permanent = types.BoolValue(true) + } else { + cItem.Permanent = types.BoolValue(false) + } + if ccValue := cv.Get("track"); ccValue.Exists() { + cItem.Track = types.StringValue(ccValue.String()) + } + if ccValue := cv.Get("metric"); ccValue.Exists() { + cItem.Metric = types.Int64Value(ccValue.Int()) + } + item.NexthopAddresses = append(item.NexthopAddresses, cItem) + return true + }) + } + data.Vrfs = append(data.Vrfs, item) + return true + }) + } +} + func (data *RouterStaticVRFIPv6UnicastData) fromBody(ctx context.Context, res []byte) { if value := gjson.GetBytes(res, "nexthop-interfaces.nexthop-interface"); value.Exists() { data.NexthopInterfaces = make([]RouterStaticVRFIPv6UnicastNexthopInterfaces, 0) diff --git a/internal/provider/resource_iosxr_router_static_vrf.go b/internal/provider/resource_iosxr_router_static_vrf.go deleted file mode 100644 index 87cfa561..00000000 --- a/internal/provider/resource_iosxr_router_static_vrf.go +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright © 2023 Cisco Systems, Inc. and its affiliates. -// All rights reserved. -// -// Licensed under the Mozilla Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://mozilla.org/MPL/2.0/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// SPDX-License-Identifier: MPL-2.0 - -// Code generated by "gen/generator.go"; DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - "regexp" - - "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client" - "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/helpers" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" -) - -func NewRouterStaticVRFResource() resource.Resource { - return &RouterStaticVRFResource{} -} - -type RouterStaticVRFResource struct { - client *client.Client -} - -func (r *RouterStaticVRFResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_router_static_vrf" -} - -func (r *RouterStaticVRFResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - // This description is used by the documentation generator and the language server. - MarkdownDescription: "This resource can manage the Router Static VRF configuration.", - - Attributes: map[string]schema.Attribute{ - "device": schema.StringAttribute{ - MarkdownDescription: "A device name from the provider configuration.", - Optional: true, - }, - "id": schema.StringAttribute{ - MarkdownDescription: "The path of the object.", - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - "delete_mode": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`.").AddStringEnumDescription("all", "attributes").String, - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOf("all", "attributes"), - }, - }, - "vrf_name": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("VRF Static route configuration subcommands").String, - Required: true, - Validators: []validator.String{ - stringvalidator.LengthBetween(1, 32), - stringvalidator.RegexMatches(regexp.MustCompile(`[\w\-\.:,_@#%$\+=\|;]+`), ""), - }, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - }, - } -} - -func (r *RouterStaticVRFResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { - if req.ProviderData == nil { - return - } - - r.client = req.ProviderData.(*client.Client) -} - -func (r *RouterStaticVRFResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var plan RouterStaticVRF - - // Read plan - diags := req.Plan.Get(ctx, &plan) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - var ops []client.SetOperation - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.getPath())) - - // Create object - body := plan.toBody(ctx) - ops = append(ops, client.SetOperation{Path: plan.getPath(), Body: body, Operation: client.Update}) - - emptyLeafsDelete := plan.getEmptyLeafsDelete(ctx) - tflog.Debug(ctx, fmt.Sprintf("List of empty leafs to delete: %+v", emptyLeafsDelete)) - - for _, i := range emptyLeafsDelete { - ops = append(ops, client.SetOperation{Path: i, Body: "", Operation: client.Delete}) - } - - _, diags = r.client.Set(ctx, plan.Device.ValueString(), ops...) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - plan.Id = types.StringValue(plan.getPath()) - - tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.getPath())) - - diags = resp.State.Set(ctx, &plan) - resp.Diagnostics.Append(diags...) -} - -func (r *RouterStaticVRFResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var state RouterStaticVRF - - // Read state - diags := req.State.Get(ctx, &state) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.ValueString())) - - getResp, diags := r.client.Get(ctx, state.Device.ValueString(), state.Id.ValueString()) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - state.updateFromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal()) - - tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) - - diags = resp.State.Set(ctx, &state) - resp.Diagnostics.Append(diags...) -} - -func (r *RouterStaticVRFResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var plan, state RouterStaticVRF - - // Read plan - diags := req.Plan.Get(ctx, &plan) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - // Read state - diags = req.State.Get(ctx, &state) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - var ops []client.SetOperation - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) - - // Update object - body := plan.toBody(ctx) - ops = append(ops, client.SetOperation{Path: plan.getPath(), Body: body, Operation: client.Update}) - - deletedListItems := plan.getDeletedItems(ctx, state) - tflog.Debug(ctx, fmt.Sprintf("Removed items to delete: %+v", deletedListItems)) - - for _, i := range deletedListItems { - ops = append(ops, client.SetOperation{Path: i, Body: "", Operation: client.Delete}) - } - - emptyLeafsDelete := plan.getEmptyLeafsDelete(ctx) - tflog.Debug(ctx, fmt.Sprintf("List of empty leafs to delete: %+v", emptyLeafsDelete)) - - for _, i := range emptyLeafsDelete { - ops = append(ops, client.SetOperation{Path: i, Body: "", Operation: client.Delete}) - } - - _, diags = r.client.Set(ctx, plan.Device.ValueString(), ops...) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Id.ValueString())) - - diags = resp.State.Set(ctx, &plan) - resp.Diagnostics.Append(diags...) -} - -func (r *RouterStaticVRFResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var state RouterStaticVRF - - // Read state - diags := req.State.Get(ctx, &state) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) - var ops []client.SetOperation - deleteMode := "all" - if state.DeleteMode.ValueString() == "all" { - deleteMode = "all" - } else if state.DeleteMode.ValueString() == "attributes" { - deleteMode = "attributes" - } - - if deleteMode == "all" { - ops = append(ops, client.SetOperation{Path: state.Id.ValueString(), Body: "", Operation: client.Delete}) - } else { - deletePaths := state.getDeletePaths(ctx) - tflog.Debug(ctx, fmt.Sprintf("Paths to delete: %+v", deletePaths)) - - for _, i := range deletePaths { - ops = append(ops, client.SetOperation{Path: i, Body: "", Operation: client.Delete}) - } - } - - _, diags = r.client.Set(ctx, state.Device.ValueString(), ops...) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString())) - - resp.State.RemoveResource(ctx) -} - -func (r *RouterStaticVRFResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) -} diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast.go b/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast.go index e2cc7144..376a8ec8 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast.go @@ -23,6 +23,8 @@ import ( "context" "fmt" "regexp" + "strconv" + "strings" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/helpers" @@ -532,6 +534,12 @@ func (r *RouterStaticVRFIPv4MulticastResource) Read(ctx context.Context, req res return } + import_ := false + if state.Id.ValueString() == "" { + import_ = true + state.Id = types.StringValue(state.getPath()) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.ValueString())) getResp, diags := r.client.Get(ctx, state.Device.ValueString(), state.Id.ValueString()) @@ -540,7 +548,12 @@ func (r *RouterStaticVRFIPv4MulticastResource) Read(ctx context.Context, req res return } - state.updateFromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal()) + respBody := getResp.Notification[0].Update[0].Val.GetJsonIetfVal() + if import_ { + state.fromBody(ctx, respBody) + } else { + state.updateFromBody(ctx, respBody) + } tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) @@ -641,5 +654,19 @@ func (r *RouterStaticVRFIPv4MulticastResource) Delete(ctx context.Context, req r } func (r *RouterStaticVRFIPv4MulticastResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 3 { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,,. Got: %q", req.ID), + ) + return + } + value0 := idParts[0] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("vrf_name"), value0)...) + value1 := idParts[1] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_address"), value1)...) + value2, _ := strconv.Atoi(idParts[2]) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_length"), value2)...) } diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast_test.go b/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast_test.go index e16ca6d3..290a92c3 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast_test.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv4_multicast_test.go @@ -82,7 +82,8 @@ func TestAccIosxrRouterStaticVRFIPv4Multicast(t *testing.T) { steps = append(steps, resource.TestStep{ ResourceName: "iosxr_router_static_vrf_ipv4_multicast.test", ImportState: true, - ImportStateId: "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv4/multicast/prefixes/prefix[prefix-address=100.0.1.0][prefix-length=%!d(string=24)]", + ImportStateId: "VRF2,100.0.1.0,24", + Check: resource.ComposeTestCheckFunc(checks...), }) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast.go b/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast.go index 1fa2c932..99f9ffff 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast.go @@ -23,6 +23,8 @@ import ( "context" "fmt" "regexp" + "strconv" + "strings" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/helpers" @@ -532,6 +534,12 @@ func (r *RouterStaticVRFIPv4UnicastResource) Read(ctx context.Context, req resou return } + import_ := false + if state.Id.ValueString() == "" { + import_ = true + state.Id = types.StringValue(state.getPath()) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.ValueString())) getResp, diags := r.client.Get(ctx, state.Device.ValueString(), state.Id.ValueString()) @@ -540,7 +548,12 @@ func (r *RouterStaticVRFIPv4UnicastResource) Read(ctx context.Context, req resou return } - state.updateFromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal()) + respBody := getResp.Notification[0].Update[0].Val.GetJsonIetfVal() + if import_ { + state.fromBody(ctx, respBody) + } else { + state.updateFromBody(ctx, respBody) + } tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) @@ -641,5 +654,19 @@ func (r *RouterStaticVRFIPv4UnicastResource) Delete(ctx context.Context, req res } func (r *RouterStaticVRFIPv4UnicastResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 3 { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,,. Got: %q", req.ID), + ) + return + } + value0 := idParts[0] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("vrf_name"), value0)...) + value1 := idParts[1] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_address"), value1)...) + value2, _ := strconv.Atoi(idParts[2]) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_length"), value2)...) } diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast_test.go b/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast_test.go index e79f5d7d..0084948c 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast_test.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv4_unicast_test.go @@ -82,7 +82,8 @@ func TestAccIosxrRouterStaticVRFIPv4Unicast(t *testing.T) { steps = append(steps, resource.TestStep{ ResourceName: "iosxr_router_static_vrf_ipv4_unicast.test", ImportState: true, - ImportStateId: "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv4/unicast/prefixes/prefix[prefix-address=100.0.1.0][prefix-length=%!d(string=24)]", + ImportStateId: "VRF2,100.0.1.0,24", + Check: resource.ComposeTestCheckFunc(checks...), }) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast.go b/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast.go index 566ddbb0..aaddee58 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast.go @@ -23,6 +23,8 @@ import ( "context" "fmt" "regexp" + "strconv" + "strings" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/helpers" @@ -537,6 +539,12 @@ func (r *RouterStaticVRFIPv6MulticastResource) Read(ctx context.Context, req res return } + import_ := false + if state.Id.ValueString() == "" { + import_ = true + state.Id = types.StringValue(state.getPath()) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.ValueString())) getResp, diags := r.client.Get(ctx, state.Device.ValueString(), state.Id.ValueString()) @@ -545,7 +553,12 @@ func (r *RouterStaticVRFIPv6MulticastResource) Read(ctx context.Context, req res return } - state.updateFromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal()) + respBody := getResp.Notification[0].Update[0].Val.GetJsonIetfVal() + if import_ { + state.fromBody(ctx, respBody) + } else { + state.updateFromBody(ctx, respBody) + } tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) @@ -646,5 +659,19 @@ func (r *RouterStaticVRFIPv6MulticastResource) Delete(ctx context.Context, req r } func (r *RouterStaticVRFIPv6MulticastResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 3 { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,,. Got: %q", req.ID), + ) + return + } + value0 := idParts[0] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("vrf_name"), value0)...) + value1 := idParts[1] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_address"), value1)...) + value2, _ := strconv.Atoi(idParts[2]) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_length"), value2)...) } diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast_test.go b/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast_test.go index 3c457c45..1095c64d 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast_test.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv6_multicast_test.go @@ -82,7 +82,8 @@ func TestAccIosxrRouterStaticVRFIPv6Multicast(t *testing.T) { steps = append(steps, resource.TestStep{ ResourceName: "iosxr_router_static_vrf_ipv6_multicast.test", ImportState: true, - ImportStateId: "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv6/multicast/prefixes/prefix[prefix-address=1::][prefix-length=%!d(string=64)]", + ImportStateId: "VRF2,1::,64", + Check: resource.ComposeTestCheckFunc(checks...), }) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast.go b/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast.go index 0f761e87..6b9c4bc2 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast.go @@ -23,6 +23,8 @@ import ( "context" "fmt" "regexp" + "strconv" + "strings" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client" "github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/helpers" @@ -537,6 +539,12 @@ func (r *RouterStaticVRFIPv6UnicastResource) Read(ctx context.Context, req resou return } + import_ := false + if state.Id.ValueString() == "" { + import_ = true + state.Id = types.StringValue(state.getPath()) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.ValueString())) getResp, diags := r.client.Get(ctx, state.Device.ValueString(), state.Id.ValueString()) @@ -545,7 +553,12 @@ func (r *RouterStaticVRFIPv6UnicastResource) Read(ctx context.Context, req resou return } - state.updateFromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal()) + respBody := getResp.Notification[0].Update[0].Val.GetJsonIetfVal() + if import_ { + state.fromBody(ctx, respBody) + } else { + state.updateFromBody(ctx, respBody) + } tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) @@ -646,5 +659,19 @@ func (r *RouterStaticVRFIPv6UnicastResource) Delete(ctx context.Context, req res } func (r *RouterStaticVRFIPv6UnicastResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 3 { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,,. Got: %q", req.ID), + ) + return + } + value0 := idParts[0] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("vrf_name"), value0)...) + value1 := idParts[1] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_address"), value1)...) + value2, _ := strconv.Atoi(idParts[2]) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prefix_length"), value2)...) } diff --git a/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast_test.go b/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast_test.go index 3b299419..3714a53e 100644 --- a/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast_test.go +++ b/internal/provider/resource_iosxr_router_static_vrf_ipv6_unicast_test.go @@ -82,7 +82,8 @@ func TestAccIosxrRouterStaticVRFIPv6Unicast(t *testing.T) { steps = append(steps, resource.TestStep{ ResourceName: "iosxr_router_static_vrf_ipv6_unicast.test", ImportState: true, - ImportStateId: "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]/address-family/ipv6/unicast/prefixes/prefix[prefix-address=1::][prefix-length=%!d(string=64)]", + ImportStateId: "VRF2,1::,64", + Check: resource.ComposeTestCheckFunc(checks...), }) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/internal/provider/resource_iosxr_router_static_vrf_test.go b/internal/provider/resource_iosxr_router_static_vrf_test.go deleted file mode 100644 index 767d1e7b..00000000 --- a/internal/provider/resource_iosxr_router_static_vrf_test.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright © 2023 Cisco Systems, Inc. and its affiliates. -// All rights reserved. -// -// Licensed under the Mozilla Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://mozilla.org/MPL/2.0/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// SPDX-License-Identifier: MPL-2.0 - -// Code generated by "gen/generator.go"; DO NOT EDIT. - -package provider - -import ( - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" -) - -func TestAccIosxrRouterStaticVRF(t *testing.T) { - var checks []resource.TestCheckFunc - checks = append(checks, resource.TestCheckResourceAttr("iosxr_router_static_vrf.test", "vrf_name", "VRF2")) - var steps []resource.TestStep - if os.Getenv("SKIP_MINIMUM_TEST") == "" { - steps = append(steps, resource.TestStep{ - Config: testAccIosxrRouterStaticVRFConfig_minimum(), - }) - } - steps = append(steps, resource.TestStep{ - Config: testAccIosxrRouterStaticVRFConfig_all(), - Check: resource.ComposeTestCheckFunc(checks...), - }) - steps = append(steps, resource.TestStep{ - ResourceName: "iosxr_router_static_vrf.test", - ImportState: true, - ImportStateId: "Cisco-IOS-XR-um-router-static-cfg:/router/static/vrfs/vrf[vrf-name=VRF2]", - }) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - Steps: steps, - }) -} - -func testAccIosxrRouterStaticVRFConfig_minimum() string { - config := `resource "iosxr_router_static_vrf" "test" {` + "\n" - config += ` vrf_name = "VRF2"` + "\n" - config += `}` + "\n" - return config -} - -func testAccIosxrRouterStaticVRFConfig_all() string { - config := `resource "iosxr_router_static_vrf" "test" {` + "\n" - config += ` vrf_name = "VRF2"` + "\n" - config += `}` + "\n" - return config -} diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 051d768d..c12fd023 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -12,6 +12,10 @@ description: |- - Add `next_hop_self`, `soft_reconfiguration_inbound_always`, `send_community_ebgp`, `send_community_ebgp_inheritance_disable`, `maximum_prefix_limit`, `maximum_prefix_threshold`, `maximum_prefix_restart`, `maximum_prefix_discard_extra_paths`, `maximum_prefix_warning_only`, `default_originate_route_policy` and `default_originate_inheritance_disable` attributes to `iosxr_router_bgp_neighbor_address_family` resource and data source - Add `timers_keepalive_interval`, `timers_holdtime` and `timers_minimum_acceptable_holdtime` attributes to `iosxr_router_bgp_neighbor_group` resource and data source - Make `index_sid_index` and `absolute_sid_label` attribute of `iosxr_router_ospf_area_interface` resource optional +- Add `iosxr_router_static_vrf_ipv4_unicast` resource and data source +- Add `iosxr_router_static_vrf_ipv4_multicast` resource and data source +- Add `iosxr_router_static_vrf_ipv6_unicast` resource and data source +- Add `iosxr_router_static_vrf_ipv6_multicast` resource and data source ## 0.4.0