diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b1f605..93663d6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `catalystcenter_wireless_ssid` resource and data source - Add `catalystcenter_site` data source - Add `catalystcenter_fabric_port_assignment` resource and data source +- BREAKING CHANGE: Replace `catalystcenter_peer_transit_network` with `catalystcenter_transit_network` resource and data source to use `/dna/intent/api/v1/sda/transitNetworks` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+ ## 0.1.10 diff --git a/docs/data-sources/transit_network.md b/docs/data-sources/transit_network.md new file mode 100644 index 00000000..3ca47152 --- /dev/null +++ b/docs/data-sources/transit_network.md @@ -0,0 +1,35 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "catalystcenter_transit_network Data Source - terraform-provider-catalystcenter" +subcategory: "SDA" +description: |- + This data source can read the Transit Network. +--- + +# catalystcenter_transit_network (Data Source) + +This data source can read the Transit Network. + +## Example Usage + +```terraform +data "catalystcenter_transit_network" "example" { + name = "TRANSIT_1" +} +``` + + +## Schema + +### Required + +- `name` (String) Transit Network Name + +### Read-Only + +- `autonomous_system_number` (String) Autonomous System Number +- `control_plane_network_device_ids` (Set of String) List of network device IDs that will be used as control plane nodes +- `id` (String) The id of the object +- `is_multicast_over_transit_enabled` (Boolean) Set this to true to enable multicast over SD-Access transit +- `routing_protocol_name` (String) Routing Protocol Name +- `type` (String) Transit Network Type diff --git a/docs/data-sources/transit_peer_network.md b/docs/data-sources/transit_peer_network.md deleted file mode 100644 index 892ca67a..00000000 --- a/docs/data-sources/transit_peer_network.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "catalystcenter_transit_peer_network Data Source - terraform-provider-catalystcenter" -subcategory: "SDA" -description: |- - This data source can read the Transit Peer Network. ---- - -# catalystcenter_transit_peer_network (Data Source) - -This data source can read the Transit Peer Network. - -## Example Usage - -```terraform -data "catalystcenter_transit_peer_network" "example" { - transit_peer_network_name = "TRANSIT_1" -} -``` - - -## Schema - -### Required - -- `transit_peer_network_name` (String) Transit Peer Network Name - -### Read-Only - -- `autonomous_system_number` (String) Autonomous System Number -- `id` (String) The id of the object -- `routing_protocol_name` (String) Routing Protocol Name -- `transit_control_plane_settings` (Attributes List) Transit Control Plane Settings info (see [below for nested schema](#nestedatt--transit_control_plane_settings)) -- `transit_peer_network_type` (String) Transit Peer Network Type - - -### Nested Schema for `transit_control_plane_settings` - -Read-Only: - -- `device_management_ip_address` (String) Device Management Ip Address of provisioned device -- `site_name_hierarchy` (String) Site Name Hierarchy where device is provisioned diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 3dee833d..f3ea7c76 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -13,6 +13,7 @@ description: |- - Add `catalystcenter_wireless_ssid` resource and data source - Add `catalystcenter_site` data source - Add `catalystcenter_fabric_port_assignment` resource and data source +- BREAKING CHANGE: Replace `catalystcenter_peer_transit_network` with `catalystcenter_transit_network` resource and data source to use `/dna/intent/api/v1/sda/transitNetworks` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+ ## 0.1.10 diff --git a/docs/resources/transit_network.md b/docs/resources/transit_network.md new file mode 100644 index 00000000..079fa509 --- /dev/null +++ b/docs/resources/transit_network.md @@ -0,0 +1,51 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "catalystcenter_transit_network Resource - terraform-provider-catalystcenter" +subcategory: "SDA" +description: |- + This resource can manage a Transit Network. +--- + +# catalystcenter_transit_network (Resource) + +This resource can manage a Transit Network. + +## Example Usage + +```terraform +resource "catalystcenter_transit_network" "example" { + name = "TRANSIT_1" + type = "IP_BASED_TRANSIT" + routing_protocol_name = "BGP" + autonomous_system_number = "65010" +} +``` + + +## Schema + +### Required + +- `name` (String) Transit Network Name +- `type` (String) Transit Network Type + - Choices: `IP_BASED_TRANSIT`, `SDA_LISP_PUB_SUB_TRANSIT`, `SDA_LISP_BGP_TRANSIT` + +### Optional + +- `autonomous_system_number` (String) Autonomous System Number +- `control_plane_network_device_ids` (Set of String) List of network device IDs that will be used as control plane nodes +- `is_multicast_over_transit_enabled` (Boolean) Set this to true to enable multicast over SD-Access transit +- `routing_protocol_name` (String) Routing Protocol Name + - Choices: `BGP` + +### Read-Only + +- `id` (String) The id of the object + +## Import + +Import is supported using the following syntax: + +```shell +terraform import catalystcenter_transit_network.example "" +``` diff --git a/docs/resources/transit_peer_network.md b/docs/resources/transit_peer_network.md deleted file mode 100644 index 381af689..00000000 --- a/docs/resources/transit_peer_network.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "catalystcenter_transit_peer_network Resource - terraform-provider-catalystcenter" -subcategory: "SDA" -description: |- - This resource can manage a Transit Peer Network. ---- - -# catalystcenter_transit_peer_network (Resource) - -This resource can manage a Transit Peer Network. - -## Example Usage - -```terraform -resource "catalystcenter_transit_peer_network" "example" { - transit_peer_network_name = "TRANSIT_1" - transit_peer_network_type = "ip_transit" - routing_protocol_name = "BGP" - autonomous_system_number = "65010" -} -``` - - -## Schema - -### Required - -- `transit_peer_network_name` (String) Transit Peer Network Name -- `transit_peer_network_type` (String) Transit Peer Network Type - - Choices: `ip_transit`, `sda_transit_with_lisp_bgp`, `sda_transit_with_pub_sub` - -### Optional - -- `autonomous_system_number` (String) Autonomous System Number -- `routing_protocol_name` (String) Routing Protocol Name - - Choices: `BGP` -- `transit_control_plane_settings` (Attributes List) Transit Control Plane Settings info (see [below for nested schema](#nestedatt--transit_control_plane_settings)) - -### Read-Only - -- `id` (String) The id of the object - - -### Nested Schema for `transit_control_plane_settings` - -Optional: - -- `device_management_ip_address` (String) Device Management Ip Address of provisioned device -- `site_name_hierarchy` (String) Site Name Hierarchy where device is provisioned - -## Import - -Import is supported using the following syntax: - -```shell -terraform import catalystcenter_transit_peer_network.example "" -``` diff --git a/examples/data-sources/catalystcenter_transit_network/data-source.tf b/examples/data-sources/catalystcenter_transit_network/data-source.tf new file mode 100644 index 00000000..1dc81036 --- /dev/null +++ b/examples/data-sources/catalystcenter_transit_network/data-source.tf @@ -0,0 +1,3 @@ +data "catalystcenter_transit_network" "example" { + name = "TRANSIT_1" +} diff --git a/examples/data-sources/catalystcenter_transit_peer_network/data-source.tf b/examples/data-sources/catalystcenter_transit_peer_network/data-source.tf deleted file mode 100644 index c4ae4e17..00000000 --- a/examples/data-sources/catalystcenter_transit_peer_network/data-source.tf +++ /dev/null @@ -1,3 +0,0 @@ -data "catalystcenter_transit_peer_network" "example" { - transit_peer_network_name = "TRANSIT_1" -} diff --git a/examples/resources/catalystcenter_transit_network/import.sh b/examples/resources/catalystcenter_transit_network/import.sh new file mode 100644 index 00000000..9724ddde --- /dev/null +++ b/examples/resources/catalystcenter_transit_network/import.sh @@ -0,0 +1 @@ +terraform import catalystcenter_transit_network.example "" diff --git a/examples/resources/catalystcenter_transit_network/resource.tf b/examples/resources/catalystcenter_transit_network/resource.tf new file mode 100644 index 00000000..ea8fed2b --- /dev/null +++ b/examples/resources/catalystcenter_transit_network/resource.tf @@ -0,0 +1,6 @@ +resource "catalystcenter_transit_network" "example" { + name = "TRANSIT_1" + type = "IP_BASED_TRANSIT" + routing_protocol_name = "BGP" + autonomous_system_number = "65010" +} diff --git a/examples/resources/catalystcenter_transit_peer_network/import.sh b/examples/resources/catalystcenter_transit_peer_network/import.sh deleted file mode 100644 index 4f811efd..00000000 --- a/examples/resources/catalystcenter_transit_peer_network/import.sh +++ /dev/null @@ -1 +0,0 @@ -terraform import catalystcenter_transit_peer_network.example "" diff --git a/examples/resources/catalystcenter_transit_peer_network/resource.tf b/examples/resources/catalystcenter_transit_peer_network/resource.tf deleted file mode 100644 index 655cd66c..00000000 --- a/examples/resources/catalystcenter_transit_peer_network/resource.tf +++ /dev/null @@ -1,6 +0,0 @@ -resource "catalystcenter_transit_peer_network" "example" { - transit_peer_network_name = "TRANSIT_1" - transit_peer_network_type = "ip_transit" - routing_protocol_name = "BGP" - autonomous_system_number = "65010" -} diff --git a/gen/definitions/fabric_l3_handoff_ip_transit.yaml b/gen/definitions/fabric_l3_handoff_ip_transit.yaml index 4741cd23..e8472b37 100644 --- a/gen/definitions/fabric_l3_handoff_ip_transit.yaml +++ b/gen/definitions/fabric_l3_handoff_ip_transit.yaml @@ -37,7 +37,7 @@ attributes: mandatory: true description: ID of the transit network of the layer 3 handoff ip transit example: d71c847b-e9c2-4f13-928c-223372b72b06 - test_value: catalystcenter_transit_peer_network.test.id + test_value: catalystcenter_transit_network.test.id - model_name: interfaceName data_path: '0' requires_replace: true @@ -117,9 +117,9 @@ test_prerequisites: | authentication_profile_name = "No Authentication" depends_on = [catalystcenter_area.test] } - resource "catalystcenter_transit_peer_network" "test" { - transit_peer_network_name = "TRANSIT_1" - transit_peer_network_type = "ip_transit" + resource "catalystcenter_transit_network" "test" { + name = "TRANSIT_1" + type = "IP_BASED_TRANSIT" routing_protocol_name = "BGP" autonomous_system_number = "65010" } \ No newline at end of file diff --git a/gen/definitions/transit_network.yaml b/gen/definitions/transit_network.yaml new file mode 100644 index 00000000..b27b6d3c --- /dev/null +++ b/gen/definitions/transit_network.yaml @@ -0,0 +1,58 @@ +--- +name: Transit Network +rest_endpoint: /dna/intent/api/v1/sda/transitNetworks +id_from_query_path: response.0 +id_from_query_path_attribute: id +import_no_id: true +data_source_no_id: true +put_no_id: true +put_id_include_path: 0.id +skip_minimum_test: true +doc_category: SDA +attributes: + - model_name: name + type: String + data_path: "0" + response_data_path: response.0.name + query_param: true + mandatory: true + requires_replace: true + description: Transit Network Name + example: TRANSIT_1 + - model_name: type + data_path: "0" + response_data_path: response.0.type + type: String + mandatory: true + description: Transit Network Type + enum_values: [IP_BASED_TRANSIT, SDA_LISP_PUB_SUB_TRANSIT, SDA_LISP_BGP_TRANSIT] + requires_replace: true + example: IP_BASED_TRANSIT + - model_name: routingProtocolName + data_path: "0.ipTransitSettings" + response_data_path: response.0.ipTransitSettings.routingProtocolName + type: String + requires_replace: true + description: Routing Protocol Name + enum_values: [BGP] + example: BGP + - model_name: autonomousSystemNumber + data_path: "0.ipTransitSettings" + response_data_path: response.0.ipTransitSettings.autonomousSystemNumber + type: String + requires_replace: true + description: Autonomous System Number + example: "65010" + - model_name: controlPlaneNetworkDeviceIds + data_path: "0.sdaTransitSettings" + response_data_path: response.0.sdaTransitSettings.controlPlaneNetworkDeviceIds + exclude_test: true + type: Set + element_type: String + description: List of network device IDs that will be used as control plane nodes + - model_name: isMulticastOverTransitEnabled + data_path: "0.sdaTransitSettings" + response_data_path: response.0.sdaTransitSettings.isMulticastOverTransitEnabled + exclude_test: true + type: Bool + description: Set this to true to enable multicast over SD-Access transit \ No newline at end of file diff --git a/gen/definitions/transit_peer_network.yaml b/gen/definitions/transit_peer_network.yaml deleted file mode 100644 index dff8cee5..00000000 --- a/gen/definitions/transit_peer_network.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -name: Transit Peer Network -rest_endpoint: /dna/intent/api/v1/business/sda/transit-peer-network -id_from_query_path: . -id_from_query_path_attribute: transitPeerNetworkId -import_no_id: true -data_source_no_id: true -no_update: true -skip_minimum_test: true -doc_category: SDA -attributes: - - model_name: transitPeerNetworkName - type: String - query_param: true - delete_query_param: true - mandatory: true - requires_replace: true - description: Transit Peer Network Name - example: TRANSIT_1 - - model_name: transitPeerNetworkType - type: String - mandatory: true - description: Transit Peer Network Type - enum_values: [ip_transit, sda_transit_with_lisp_bgp, sda_transit_with_pub_sub] - requires_replace: true # PUT not implemented - example: ip_transit - - model_name: routingProtocolName - data_path: ipTransitSettings - type: String - requires_replace: true - description: Routing Protocol Name - enum_values: [BGP] - example: BGP - - model_name: autonomousSystemNumber - data_path: ipTransitSettings - type: String - requires_replace: true - description: Autonomous System Number - example: "65010" - - model_name: transitControlPlaneSettings - data_path: sdaTransitSettings - write_only: true - exclude_test: true - type: List - description: Transit Control Plane Settings info - attributes: - - model_name: siteNameHierarchy - requires_replace: true - type: String - description: Site Name Hierarchy where device is provisioned - example: "Global/Area1" - - model_name: deviceManagementIpAddress - requires_replace: true - type: String - description: Device Management Ip Address of provisioned device - example: "10.0.0.1" \ No newline at end of file diff --git a/internal/provider/data_source_catalystcenter_fabric_l3_handoff_ip_transit_test.go b/internal/provider/data_source_catalystcenter_fabric_l3_handoff_ip_transit_test.go index 11cd64f7..35cb7c4e 100644 --- a/internal/provider/data_source_catalystcenter_fabric_l3_handoff_ip_transit_test.go +++ b/internal/provider/data_source_catalystcenter_fabric_l3_handoff_ip_transit_test.go @@ -66,9 +66,9 @@ resource "catalystcenter_fabric_site" "test" { authentication_profile_name = "No Authentication" depends_on = [catalystcenter_area.test] } -resource "catalystcenter_transit_peer_network" "test" { - transit_peer_network_name = "TRANSIT_1" - transit_peer_network_type = "ip_transit" +resource "catalystcenter_transit_network" "test" { + name = "TRANSIT_1" + type = "IP_BASED_TRANSIT" routing_protocol_name = "BGP" autonomous_system_number = "65010" } @@ -81,7 +81,7 @@ func testAccDataSourceCcFabricL3HandoffIPTransitConfig() string { config := `resource "catalystcenter_fabric_l3_handoff_ip_transit" "test" {` + "\n" config += ` network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"` + "\n" config += ` fabric_id = catalystcenter_fabric_site.test.id` + "\n" - config += ` transit_network_id = catalystcenter_transit_peer_network.test.id` + "\n" + config += ` transit_network_id = catalystcenter_transit_network.test.id` + "\n" config += ` interface_name = "TenGigabitEthernet1/0/2"` + "\n" config += ` virtual_network_name = "SDA_VN1"` + "\n" config += ` vlan_id = 205` + "\n" diff --git a/internal/provider/data_source_catalystcenter_transit_peer_network.go b/internal/provider/data_source_catalystcenter_transit_network.go similarity index 59% rename from internal/provider/data_source_catalystcenter_transit_peer_network.go rename to internal/provider/data_source_catalystcenter_transit_network.go index 60fa9a44..1ff97618 100644 --- a/internal/provider/data_source_catalystcenter_transit_peer_network.go +++ b/internal/provider/data_source_catalystcenter_transit_network.go @@ -25,6 +25,7 @@ import ( "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" cc "github.com/netascode/go-catalystcenter" ) @@ -35,38 +36,38 @@ import ( // Ensure the implementation satisfies the expected interfaces. var ( - _ datasource.DataSource = &TransitPeerNetworkDataSource{} - _ datasource.DataSourceWithConfigure = &TransitPeerNetworkDataSource{} + _ datasource.DataSource = &TransitNetworkDataSource{} + _ datasource.DataSourceWithConfigure = &TransitNetworkDataSource{} ) -func NewTransitPeerNetworkDataSource() datasource.DataSource { - return &TransitPeerNetworkDataSource{} +func NewTransitNetworkDataSource() datasource.DataSource { + return &TransitNetworkDataSource{} } -type TransitPeerNetworkDataSource struct { +type TransitNetworkDataSource struct { client *cc.Client } -func (d *TransitPeerNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_transit_peer_network" +func (d *TransitNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transit_network" } -func (d *TransitPeerNetworkDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *TransitNetworkDataSource) 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 Transit Peer Network.", + MarkdownDescription: "This data source can read the Transit Network.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ MarkdownDescription: "The id of the object", Computed: true, }, - "transit_peer_network_name": schema.StringAttribute{ - MarkdownDescription: "Transit Peer Network Name", + "name": schema.StringAttribute{ + MarkdownDescription: "Transit Network Name", Required: true, }, - "transit_peer_network_type": schema.StringAttribute{ - MarkdownDescription: "Transit Peer Network Type", + "type": schema.StringAttribute{ + MarkdownDescription: "Transit Network Type", Computed: true, }, "routing_protocol_name": schema.StringAttribute{ @@ -77,27 +78,20 @@ func (d *TransitPeerNetworkDataSource) Schema(ctx context.Context, req datasourc MarkdownDescription: "Autonomous System Number", Computed: true, }, - "transit_control_plane_settings": schema.ListNestedAttribute{ - MarkdownDescription: "Transit Control Plane Settings info", + "control_plane_network_device_ids": schema.SetAttribute{ + MarkdownDescription: "List of network device IDs that will be used as control plane nodes", + ElementType: types.StringType, + Computed: true, + }, + "is_multicast_over_transit_enabled": schema.BoolAttribute{ + MarkdownDescription: "Set this to true to enable multicast over SD-Access transit", Computed: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "site_name_hierarchy": schema.StringAttribute{ - MarkdownDescription: "Site Name Hierarchy where device is provisioned", - Computed: true, - }, - "device_management_ip_address": schema.StringAttribute{ - MarkdownDescription: "Device Management Ip Address of provisioned device", - Computed: true, - }, - }, - }, }, }, } } -func (d *TransitPeerNetworkDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { +func (d *TransitNetworkDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { if req.ProviderData == nil { return } @@ -108,8 +102,8 @@ func (d *TransitPeerNetworkDataSource) Configure(_ context.Context, req datasour // End of section. //template:end model // Section below is generated&owned by "gen/generator.go". //template:begin read -func (d *TransitPeerNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var config TransitPeerNetwork +func (d *TransitNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config TransitNetwork // Read config diags := req.Config.Get(ctx, &config) @@ -121,7 +115,7 @@ func (d *TransitPeerNetworkDataSource) Read(ctx context.Context, req datasource. tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) params := "" - params += "?transitPeerNetworkName=" + url.QueryEscape(config.TransitPeerNetworkName.ValueString()) + params += "?name=" + url.QueryEscape(config.Name.ValueString()) res, err := d.client.Get(config.getPath() + params) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) diff --git a/internal/provider/data_source_catalystcenter_transit_peer_network_test.go b/internal/provider/data_source_catalystcenter_transit_network_test.go similarity index 70% rename from internal/provider/data_source_catalystcenter_transit_peer_network_test.go rename to internal/provider/data_source_catalystcenter_transit_network_test.go index ba346637..7927cd8f 100644 --- a/internal/provider/data_source_catalystcenter_transit_peer_network_test.go +++ b/internal/provider/data_source_catalystcenter_transit_network_test.go @@ -27,18 +27,18 @@ import ( // End of section. //template:end imports // Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource -func TestAccDataSourceCcTransitPeerNetwork(t *testing.T) { +func TestAccDataSourceCcTransitNetwork(t *testing.T) { var checks []resource.TestCheckFunc - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_peer_network.test", "transit_peer_network_name", "TRANSIT_1")) - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_peer_network.test", "transit_peer_network_type", "ip_transit")) - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_peer_network.test", "routing_protocol_name", "BGP")) - checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_peer_network.test", "autonomous_system_number", "65010")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_network.test", "name", "TRANSIT_1")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_network.test", "type", "IP_BASED_TRANSIT")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_network.test", "routing_protocol_name", "BGP")) + checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_transit_network.test", "autonomous_system_number", "65010")) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDataSourceCcTransitPeerNetworkConfig(), + Config: testAccDataSourceCcTransitNetworkConfig(), Check: resource.ComposeTestCheckFunc(checks...), }, }, @@ -51,18 +51,18 @@ func TestAccDataSourceCcTransitPeerNetwork(t *testing.T) { // End of section. //template:end testPrerequisites // Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig -func testAccDataSourceCcTransitPeerNetworkConfig() string { - config := `resource "catalystcenter_transit_peer_network" "test" {` + "\n" - config += ` transit_peer_network_name = "TRANSIT_1"` + "\n" - config += ` transit_peer_network_type = "ip_transit"` + "\n" +func testAccDataSourceCcTransitNetworkConfig() string { + config := `resource "catalystcenter_transit_network" "test" {` + "\n" + config += ` name = "TRANSIT_1"` + "\n" + config += ` type = "IP_BASED_TRANSIT"` + "\n" config += ` routing_protocol_name = "BGP"` + "\n" config += ` autonomous_system_number = "65010"` + "\n" config += `}` + "\n" config += ` - data "catalystcenter_transit_peer_network" "test" { - transit_peer_network_name = "TRANSIT_1" - depends_on = [catalystcenter_transit_peer_network.test] + data "catalystcenter_transit_network" "test" { + name = "TRANSIT_1" + depends_on = [catalystcenter_transit_network.test] } ` return config diff --git a/internal/provider/model_catalystcenter_transit_network.go b/internal/provider/model_catalystcenter_transit_network.go new file mode 100644 index 00000000..55a6cbb2 --- /dev/null +++ b/internal/provider/model_catalystcenter_transit_network.go @@ -0,0 +1,188 @@ +// 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 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + + "github.com/CiscoDevNet/terraform-provider-catalystcenter/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin types +type TransitNetwork struct { + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Type types.String `tfsdk:"type"` + RoutingProtocolName types.String `tfsdk:"routing_protocol_name"` + AutonomousSystemNumber types.String `tfsdk:"autonomous_system_number"` + ControlPlaneNetworkDeviceIds types.Set `tfsdk:"control_plane_network_device_ids"` + IsMulticastOverTransitEnabled types.Bool `tfsdk:"is_multicast_over_transit_enabled"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data TransitNetwork) getPath() string { + return "/dna/intent/api/v1/sda/transitNetworks" +} + +// End of section. //template:end getPath + +// Section below is generated&owned by "gen/generator.go". //template:begin getPathDelete + +// End of section. //template:end getPathDelete + +// Section below is generated&owned by "gen/generator.go". //template:begin toBody +func (data TransitNetwork) toBody(ctx context.Context, state TransitNetwork) string { + body := "" + put := false + if state.Id.ValueString() != "" { + put = true + body, _ = sjson.Set(body, "0.id", state.Id.ValueString()) + } + _ = put + if !data.Name.IsNull() { + body, _ = sjson.Set(body, "0.name", data.Name.ValueString()) + } + if !data.Type.IsNull() { + body, _ = sjson.Set(body, "0.type", data.Type.ValueString()) + } + if !data.RoutingProtocolName.IsNull() { + body, _ = sjson.Set(body, "0.ipTransitSettings.routingProtocolName", data.RoutingProtocolName.ValueString()) + } + if !data.AutonomousSystemNumber.IsNull() { + body, _ = sjson.Set(body, "0.ipTransitSettings.autonomousSystemNumber", data.AutonomousSystemNumber.ValueString()) + } + if !data.ControlPlaneNetworkDeviceIds.IsNull() { + var values []string + data.ControlPlaneNetworkDeviceIds.ElementsAs(ctx, &values, false) + body, _ = sjson.Set(body, "0.sdaTransitSettings.controlPlaneNetworkDeviceIds", values) + } + if !data.IsMulticastOverTransitEnabled.IsNull() { + body, _ = sjson.Set(body, "0.sdaTransitSettings.isMulticastOverTransitEnabled", data.IsMulticastOverTransitEnabled.ValueBool()) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *TransitNetwork) fromBody(ctx context.Context, res gjson.Result) { + // Retrieve the 'id' attribute, if Data Source doesn't require id + if value := res.Get("response.0.id"); value.Exists() { + data.Id = types.StringValue(value.String()) + } else { + data.Id = types.StringNull() + } + if value := res.Get("response.0.name"); value.Exists() { + data.Name = types.StringValue(value.String()) + } else { + data.Name = types.StringNull() + } + if value := res.Get("response.0.type"); value.Exists() { + data.Type = types.StringValue(value.String()) + } else { + data.Type = types.StringNull() + } + if value := res.Get("response.0.ipTransitSettings.routingProtocolName"); value.Exists() { + data.RoutingProtocolName = types.StringValue(value.String()) + } else { + data.RoutingProtocolName = types.StringNull() + } + if value := res.Get("response.0.ipTransitSettings.autonomousSystemNumber"); value.Exists() { + data.AutonomousSystemNumber = types.StringValue(value.String()) + } else { + data.AutonomousSystemNumber = types.StringNull() + } + if value := res.Get("response.0.sdaTransitSettings.controlPlaneNetworkDeviceIds"); value.Exists() && len(value.Array()) > 0 { + data.ControlPlaneNetworkDeviceIds = helpers.GetStringSet(value.Array()) + } else { + data.ControlPlaneNetworkDeviceIds = types.SetNull(types.StringType) + } + if value := res.Get("response.0.sdaTransitSettings.isMulticastOverTransitEnabled"); value.Exists() { + data.IsMulticastOverTransitEnabled = types.BoolValue(value.Bool()) + } else { + data.IsMulticastOverTransitEnabled = types.BoolNull() + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *TransitNetwork) updateFromBody(ctx context.Context, res gjson.Result) { + if value := res.Get("response.0.name"); value.Exists() && !data.Name.IsNull() { + data.Name = types.StringValue(value.String()) + } else { + data.Name = types.StringNull() + } + if value := res.Get("response.0.type"); value.Exists() && !data.Type.IsNull() { + data.Type = types.StringValue(value.String()) + } else { + data.Type = types.StringNull() + } + if value := res.Get("response.0.ipTransitSettings.routingProtocolName"); value.Exists() && !data.RoutingProtocolName.IsNull() { + data.RoutingProtocolName = types.StringValue(value.String()) + } else { + data.RoutingProtocolName = types.StringNull() + } + if value := res.Get("response.0.ipTransitSettings.autonomousSystemNumber"); value.Exists() && !data.AutonomousSystemNumber.IsNull() { + data.AutonomousSystemNumber = types.StringValue(value.String()) + } else { + data.AutonomousSystemNumber = types.StringNull() + } + if value := res.Get("response.0.sdaTransitSettings.controlPlaneNetworkDeviceIds"); value.Exists() && !data.ControlPlaneNetworkDeviceIds.IsNull() { + data.ControlPlaneNetworkDeviceIds = helpers.GetStringSet(value.Array()) + } else { + data.ControlPlaneNetworkDeviceIds = types.SetNull(types.StringType) + } + if value := res.Get("response.0.sdaTransitSettings.isMulticastOverTransitEnabled"); value.Exists() && !data.IsMulticastOverTransitEnabled.IsNull() { + data.IsMulticastOverTransitEnabled = types.BoolValue(value.Bool()) + } else { + data.IsMulticastOverTransitEnabled = types.BoolNull() + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *TransitNetwork) isNull(ctx context.Context, res gjson.Result) bool { + if !data.Type.IsNull() { + return false + } + if !data.RoutingProtocolName.IsNull() { + return false + } + if !data.AutonomousSystemNumber.IsNull() { + return false + } + if !data.ControlPlaneNetworkDeviceIds.IsNull() { + return false + } + if !data.IsMulticastOverTransitEnabled.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_catalystcenter_transit_peer_network.go b/internal/provider/model_catalystcenter_transit_peer_network.go deleted file mode 100644 index ad90a6eb..00000000 --- a/internal/provider/model_catalystcenter_transit_peer_network.go +++ /dev/null @@ -1,172 +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 - -package provider - -// Section below is generated&owned by "gen/generator.go". //template:begin imports -import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/tidwall/gjson" - "github.com/tidwall/sjson" -) - -// End of section. //template:end imports - -// Section below is generated&owned by "gen/generator.go". //template:begin types -type TransitPeerNetwork struct { - Id types.String `tfsdk:"id"` - TransitPeerNetworkName types.String `tfsdk:"transit_peer_network_name"` - TransitPeerNetworkType types.String `tfsdk:"transit_peer_network_type"` - RoutingProtocolName types.String `tfsdk:"routing_protocol_name"` - AutonomousSystemNumber types.String `tfsdk:"autonomous_system_number"` - TransitControlPlaneSettings []TransitPeerNetworkTransitControlPlaneSettings `tfsdk:"transit_control_plane_settings"` -} - -type TransitPeerNetworkTransitControlPlaneSettings struct { - SiteNameHierarchy types.String `tfsdk:"site_name_hierarchy"` - DeviceManagementIpAddress types.String `tfsdk:"device_management_ip_address"` -} - -// End of section. //template:end types - -// Section below is generated&owned by "gen/generator.go". //template:begin getPath -func (data TransitPeerNetwork) getPath() string { - return "/dna/intent/api/v1/business/sda/transit-peer-network" -} - -// End of section. //template:end getPath - -// Section below is generated&owned by "gen/generator.go". //template:begin getPathDelete - -// End of section. //template:end getPathDelete - -// Section below is generated&owned by "gen/generator.go". //template:begin toBody -func (data TransitPeerNetwork) toBody(ctx context.Context, state TransitPeerNetwork) string { - body := "" - put := false - if state.Id.ValueString() != "" { - put = true - } - _ = put - if !data.TransitPeerNetworkName.IsNull() { - body, _ = sjson.Set(body, "transitPeerNetworkName", data.TransitPeerNetworkName.ValueString()) - } - if !data.TransitPeerNetworkType.IsNull() { - body, _ = sjson.Set(body, "transitPeerNetworkType", data.TransitPeerNetworkType.ValueString()) - } - if !data.RoutingProtocolName.IsNull() { - body, _ = sjson.Set(body, "ipTransitSettings.routingProtocolName", data.RoutingProtocolName.ValueString()) - } - if !data.AutonomousSystemNumber.IsNull() { - body, _ = sjson.Set(body, "ipTransitSettings.autonomousSystemNumber", data.AutonomousSystemNumber.ValueString()) - } - if len(data.TransitControlPlaneSettings) > 0 { - body, _ = sjson.Set(body, "sdaTransitSettings.transitControlPlaneSettings", []interface{}{}) - for _, item := range data.TransitControlPlaneSettings { - itemBody := "" - if !item.SiteNameHierarchy.IsNull() { - itemBody, _ = sjson.Set(itemBody, "siteNameHierarchy", item.SiteNameHierarchy.ValueString()) - } - if !item.DeviceManagementIpAddress.IsNull() { - itemBody, _ = sjson.Set(itemBody, "deviceManagementIpAddress", item.DeviceManagementIpAddress.ValueString()) - } - body, _ = sjson.SetRaw(body, "sdaTransitSettings.transitControlPlaneSettings.-1", itemBody) - } - } - return body -} - -// End of section. //template:end toBody - -// Section below is generated&owned by "gen/generator.go". //template:begin fromBody -func (data *TransitPeerNetwork) fromBody(ctx context.Context, res gjson.Result) { - // Retrieve the 'id' attribute, if Data Source doesn't require id - if value := res.Get("transitPeerNetworkId"); value.Exists() { - data.Id = types.StringValue(value.String()) - } else { - data.Id = types.StringNull() - } - if value := res.Get("transitPeerNetworkName"); value.Exists() { - data.TransitPeerNetworkName = types.StringValue(value.String()) - } else { - data.TransitPeerNetworkName = types.StringNull() - } - if value := res.Get("transitPeerNetworkType"); value.Exists() { - data.TransitPeerNetworkType = types.StringValue(value.String()) - } else { - data.TransitPeerNetworkType = types.StringNull() - } - if value := res.Get("ipTransitSettings.routingProtocolName"); value.Exists() { - data.RoutingProtocolName = types.StringValue(value.String()) - } else { - data.RoutingProtocolName = types.StringNull() - } - if value := res.Get("ipTransitSettings.autonomousSystemNumber"); value.Exists() { - data.AutonomousSystemNumber = types.StringValue(value.String()) - } else { - data.AutonomousSystemNumber = types.StringNull() - } -} - -// End of section. //template:end fromBody - -// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody -func (data *TransitPeerNetwork) updateFromBody(ctx context.Context, res gjson.Result) { - if value := res.Get("transitPeerNetworkName"); value.Exists() && !data.TransitPeerNetworkName.IsNull() { - data.TransitPeerNetworkName = types.StringValue(value.String()) - } else { - data.TransitPeerNetworkName = types.StringNull() - } - if value := res.Get("transitPeerNetworkType"); value.Exists() && !data.TransitPeerNetworkType.IsNull() { - data.TransitPeerNetworkType = types.StringValue(value.String()) - } else { - data.TransitPeerNetworkType = types.StringNull() - } - if value := res.Get("ipTransitSettings.routingProtocolName"); value.Exists() && !data.RoutingProtocolName.IsNull() { - data.RoutingProtocolName = types.StringValue(value.String()) - } else { - data.RoutingProtocolName = types.StringNull() - } - if value := res.Get("ipTransitSettings.autonomousSystemNumber"); value.Exists() && !data.AutonomousSystemNumber.IsNull() { - data.AutonomousSystemNumber = types.StringValue(value.String()) - } else { - data.AutonomousSystemNumber = types.StringNull() - } -} - -// End of section. //template:end updateFromBody - -// Section below is generated&owned by "gen/generator.go". //template:begin isNull -func (data *TransitPeerNetwork) isNull(ctx context.Context, res gjson.Result) bool { - if !data.TransitPeerNetworkType.IsNull() { - return false - } - if !data.RoutingProtocolName.IsNull() { - return false - } - if !data.AutonomousSystemNumber.IsNull() { - return false - } - if len(data.TransitControlPlaneSettings) > 0 { - return false - } - return true -} - -// End of section. //template:end isNull diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 2b147ba5..4f347702 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -282,7 +282,7 @@ func (p *CcProvider) Resources(ctx context.Context) []func() resource.Resource { NewTagResource, NewTemplateResource, NewTemplateVersionResource, - NewTransitPeerNetworkResource, + NewTransitNetworkResource, NewUserResource, NewVirtualNetworkIPPoolResource, NewVirtualNetworkToFabricSiteResource, @@ -333,7 +333,7 @@ func (p *CcProvider) DataSources(ctx context.Context) []func() datasource.DataSo NewTagDataSource, NewTemplateDataSource, NewTemplateVersionDataSource, - NewTransitPeerNetworkDataSource, + NewTransitNetworkDataSource, NewUserDataSource, NewWirelessEnterpriseSSIDDataSource, NewWirelessProfileDataSource, diff --git a/internal/provider/resource_catalystcenter_fabric_l3_handoff_ip_transit_test.go b/internal/provider/resource_catalystcenter_fabric_l3_handoff_ip_transit_test.go index 47cf3946..7e8f8334 100644 --- a/internal/provider/resource_catalystcenter_fabric_l3_handoff_ip_transit_test.go +++ b/internal/provider/resource_catalystcenter_fabric_l3_handoff_ip_transit_test.go @@ -73,9 +73,9 @@ resource "catalystcenter_fabric_site" "test" { authentication_profile_name = "No Authentication" depends_on = [catalystcenter_area.test] } -resource "catalystcenter_transit_peer_network" "test" { - transit_peer_network_name = "TRANSIT_1" - transit_peer_network_type = "ip_transit" +resource "catalystcenter_transit_network" "test" { + name = "TRANSIT_1" + type = "IP_BASED_TRANSIT" routing_protocol_name = "BGP" autonomous_system_number = "65010" } @@ -88,7 +88,7 @@ func testAccCcFabricL3HandoffIPTransitConfig_minimum() string { config := `resource "catalystcenter_fabric_l3_handoff_ip_transit" "test" {` + "\n" config += ` network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"` + "\n" config += ` fabric_id = catalystcenter_fabric_site.test.id` + "\n" - config += ` transit_network_id = catalystcenter_transit_peer_network.test.id` + "\n" + config += ` transit_network_id = catalystcenter_transit_network.test.id` + "\n" config += ` virtual_network_name = "SDA_VN1"` + "\n" config += ` vlan_id = 205` + "\n" config += `}` + "\n" @@ -102,7 +102,7 @@ func testAccCcFabricL3HandoffIPTransitConfig_all() string { config := `resource "catalystcenter_fabric_l3_handoff_ip_transit" "test" {` + "\n" config += ` network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"` + "\n" config += ` fabric_id = catalystcenter_fabric_site.test.id` + "\n" - config += ` transit_network_id = catalystcenter_transit_peer_network.test.id` + "\n" + config += ` transit_network_id = catalystcenter_transit_network.test.id` + "\n" config += ` interface_name = "TenGigabitEthernet1/0/2"` + "\n" config += ` virtual_network_name = "SDA_VN1"` + "\n" config += ` vlan_id = 205` + "\n" diff --git a/internal/provider/resource_catalystcenter_transit_peer_network.go b/internal/provider/resource_catalystcenter_transit_network.go similarity index 67% rename from internal/provider/resource_catalystcenter_transit_peer_network.go rename to internal/provider/resource_catalystcenter_transit_network.go index 1ee101a7..5d92466a 100644 --- a/internal/provider/resource_catalystcenter_transit_peer_network.go +++ b/internal/provider/resource_catalystcenter_transit_network.go @@ -42,25 +42,25 @@ import ( // Section below is generated&owned by "gen/generator.go". //template:begin model // Ensure provider defined types fully satisfy framework interfaces -var _ resource.Resource = &TransitPeerNetworkResource{} -var _ resource.ResourceWithImportState = &TransitPeerNetworkResource{} +var _ resource.Resource = &TransitNetworkResource{} +var _ resource.ResourceWithImportState = &TransitNetworkResource{} -func NewTransitPeerNetworkResource() resource.Resource { - return &TransitPeerNetworkResource{} +func NewTransitNetworkResource() resource.Resource { + return &TransitNetworkResource{} } -type TransitPeerNetworkResource struct { +type TransitNetworkResource struct { client *cc.Client } -func (r *TransitPeerNetworkResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_transit_peer_network" +func (r *TransitNetworkResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transit_network" } -func (r *TransitPeerNetworkResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *TransitNetworkResource) 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: helpers.NewAttributeDescription("This resource can manage a Transit Peer Network.").String, + MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Transit Network.").String, Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -70,18 +70,18 @@ func (r *TransitPeerNetworkResource) Schema(ctx context.Context, req resource.Sc stringplanmodifier.UseStateForUnknown(), }, }, - "transit_peer_network_name": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Transit Peer Network Name").String, + "name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Transit Network Name").String, Required: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, }, - "transit_peer_network_type": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Transit Peer Network Type").AddStringEnumDescription("ip_transit", "sda_transit_with_lisp_bgp", "sda_transit_with_pub_sub").String, + "type": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Transit Network Type").AddStringEnumDescription("IP_BASED_TRANSIT", "SDA_LISP_PUB_SUB_TRANSIT", "SDA_LISP_BGP_TRANSIT").String, Required: true, Validators: []validator.String{ - stringvalidator.OneOf("ip_transit", "sda_transit_with_lisp_bgp", "sda_transit_with_pub_sub"), + stringvalidator.OneOf("IP_BASED_TRANSIT", "SDA_LISP_PUB_SUB_TRANSIT", "SDA_LISP_BGP_TRANSIT"), }, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), @@ -104,33 +104,20 @@ func (r *TransitPeerNetworkResource) Schema(ctx context.Context, req resource.Sc stringplanmodifier.RequiresReplace(), }, }, - "transit_control_plane_settings": schema.ListNestedAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Transit Control Plane Settings info").String, + "control_plane_network_device_ids": schema.SetAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("List of network device IDs that will be used as control plane nodes").String, + ElementType: types.StringType, + Optional: true, + }, + "is_multicast_over_transit_enabled": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set this to true to enable multicast over SD-Access transit").String, Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "site_name_hierarchy": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Site Name Hierarchy where device is provisioned").String, - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "device_management_ip_address": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Device Management Ip Address of provisioned device").String, - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - }, - }, }, }, } } -func (r *TransitPeerNetworkResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { +func (r *TransitNetworkResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { if req.ProviderData == nil { return } @@ -141,8 +128,8 @@ func (r *TransitPeerNetworkResource) Configure(_ context.Context, req resource.C // End of section. //template:end model // Section below is generated&owned by "gen/generator.go". //template:begin create -func (r *TransitPeerNetworkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var plan TransitPeerNetwork +func (r *TransitNetworkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan TransitNetwork // Read plan diags := req.Plan.Get(ctx, &plan) @@ -154,7 +141,7 @@ func (r *TransitPeerNetworkResource) Create(ctx context.Context, req resource.Cr tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object - body := plan.toBody(ctx, TransitPeerNetwork{}) + body := plan.toBody(ctx, TransitNetwork{}) params := "" res, err := r.client.Post(plan.getPath()+params, body) @@ -163,13 +150,13 @@ func (r *TransitPeerNetworkResource) Create(ctx context.Context, req resource.Cr return } params = "" - params += "?transitPeerNetworkName=" + url.QueryEscape(plan.TransitPeerNetworkName.ValueString()) + params += "?name=" + url.QueryEscape(plan.Name.ValueString()) res, err = r.client.Get(plan.getPath() + params) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) return } - plan.Id = types.StringValue(res.Get("transitPeerNetworkId").String()) + plan.Id = types.StringValue(res.Get("response.0.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Id.ValueString())) @@ -180,8 +167,8 @@ func (r *TransitPeerNetworkResource) Create(ctx context.Context, req resource.Cr // End of section. //template:end create // Section below is generated&owned by "gen/generator.go". //template:begin read -func (r *TransitPeerNetworkResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var state TransitPeerNetwork +func (r *TransitNetworkResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TransitNetwork // Read state diags := req.State.Get(ctx, &state) @@ -193,7 +180,7 @@ func (r *TransitPeerNetworkResource) Read(ctx context.Context, req resource.Read tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) params := "" - params += "?transitPeerNetworkName=" + url.QueryEscape(state.TransitPeerNetworkName.ValueString()) + params += "?name=" + url.QueryEscape(state.Name.ValueString()) res, err := r.client.Get(state.getPath() + params) if err != nil && strings.Contains(err.Error(), "StatusCode 404") { resp.State.RemoveResource(ctx) @@ -219,8 +206,8 @@ func (r *TransitPeerNetworkResource) Read(ctx context.Context, req resource.Read // End of section. //template:end read // Section below is generated&owned by "gen/generator.go". //template:begin update -func (r *TransitPeerNetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var plan, state TransitPeerNetwork +func (r *TransitNetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state TransitNetwork // Read plan diags := req.Plan.Get(ctx, &plan) @@ -237,6 +224,14 @@ func (r *TransitPeerNetworkResource) Update(ctx context.Context, req resource.Up tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) + body := plan.toBody(ctx, state) + params := "" + res, err := r.client.Put(plan.getPath()+params, body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) + return + } + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Id.ValueString())) diags = resp.State.Set(ctx, &plan) @@ -246,8 +241,8 @@ func (r *TransitPeerNetworkResource) Update(ctx context.Context, req resource.Up // End of section. //template:end update // Section below is generated&owned by "gen/generator.go". //template:begin delete -func (r *TransitPeerNetworkResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var state TransitPeerNetwork +func (r *TransitNetworkResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TransitNetwork // Read state diags := req.State.Get(ctx, &state) @@ -257,8 +252,7 @@ func (r *TransitPeerNetworkResource) Delete(ctx context.Context, req resource.De } tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) - params := "?transitPeerNetworkName=" + url.QueryEscape(state.TransitPeerNetworkName.ValueString()) - res, err := r.client.Delete(state.getPath() + params) + res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) return @@ -272,17 +266,17 @@ func (r *TransitPeerNetworkResource) Delete(ctx context.Context, req resource.De // End of section. //template:end delete // Section below is generated&owned by "gen/generator.go". //template:begin import -func (r *TransitPeerNetworkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *TransitNetworkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, ",") if len(idParts) != 1 || idParts[0] == "" { resp.Diagnostics.AddError( "Unexpected Import Identifier", - fmt.Sprintf("Expected import identifier with format: . Got: %q", req.ID), + fmt.Sprintf("Expected import identifier with format: . Got: %q", req.ID), ) return } - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("transit_peer_network_name"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[0])...) } // End of section. //template:end import diff --git a/internal/provider/resource_catalystcenter_transit_peer_network_test.go b/internal/provider/resource_catalystcenter_transit_network_test.go similarity index 71% rename from internal/provider/resource_catalystcenter_transit_peer_network_test.go rename to internal/provider/resource_catalystcenter_transit_network_test.go index 62fa7c4e..5b11729d 100644 --- a/internal/provider/resource_catalystcenter_transit_peer_network_test.go +++ b/internal/provider/resource_catalystcenter_transit_network_test.go @@ -27,16 +27,16 @@ import ( // End of section. //template:end imports // Section below is generated&owned by "gen/generator.go". //template:begin testAcc -func TestAccCcTransitPeerNetwork(t *testing.T) { +func TestAccCcTransitNetwork(t *testing.T) { var checks []resource.TestCheckFunc - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_peer_network.test", "transit_peer_network_name", "TRANSIT_1")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_peer_network.test", "transit_peer_network_type", "ip_transit")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_peer_network.test", "routing_protocol_name", "BGP")) - checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_peer_network.test", "autonomous_system_number", "65010")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_network.test", "name", "TRANSIT_1")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_network.test", "type", "IP_BASED_TRANSIT")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_network.test", "routing_protocol_name", "BGP")) + checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_transit_network.test", "autonomous_system_number", "65010")) var steps []resource.TestStep steps = append(steps, resource.TestStep{ - Config: testAccCcTransitPeerNetworkConfig_all(), + Config: testAccCcTransitNetworkConfig_all(), Check: resource.ComposeTestCheckFunc(checks...), }) @@ -53,10 +53,10 @@ func TestAccCcTransitPeerNetwork(t *testing.T) { // End of section. //template:end testPrerequisites // Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimal -func testAccCcTransitPeerNetworkConfig_minimum() string { - config := `resource "catalystcenter_transit_peer_network" "test" {` + "\n" - config += ` transit_peer_network_name = "TRANSIT_1"` + "\n" - config += ` transit_peer_network_type = "ip_transit"` + "\n" +func testAccCcTransitNetworkConfig_minimum() string { + config := `resource "catalystcenter_transit_network" "test" {` + "\n" + config += ` name = "TRANSIT_1"` + "\n" + config += ` type = "IP_BASED_TRANSIT"` + "\n" config += `}` + "\n" return config } @@ -64,10 +64,10 @@ func testAccCcTransitPeerNetworkConfig_minimum() string { // End of section. //template:end testAccConfigMinimal // Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll -func testAccCcTransitPeerNetworkConfig_all() string { - config := `resource "catalystcenter_transit_peer_network" "test" {` + "\n" - config += ` transit_peer_network_name = "TRANSIT_1"` + "\n" - config += ` transit_peer_network_type = "ip_transit"` + "\n" +func testAccCcTransitNetworkConfig_all() string { + config := `resource "catalystcenter_transit_network" "test" {` + "\n" + config += ` name = "TRANSIT_1"` + "\n" + config += ` type = "IP_BASED_TRANSIT"` + "\n" config += ` routing_protocol_name = "BGP"` + "\n" config += ` autonomous_system_number = "65010"` + "\n" config += `}` + "\n" diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 7763f7e6..a35fa644 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -13,6 +13,7 @@ description: |- - Add `catalystcenter_wireless_ssid` resource and data source - Add `catalystcenter_site` data source - Add `catalystcenter_fabric_vlan_to_ssid` resource and data source +- BREAKING CHANGE: Replace `catalystcenter_peer_transit_network` with `catalystcenter_transit_network` resource and data source to use `/dna/intent/api/v1/sda/transitNetworks` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+ ## 0.1.10