diff --git a/CHANGELOG.md b/CHANGELOG.md index 39447ca..65b2e2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.11 (unreleased) + +- BREAKING CHANGE: Renamed `catalystcenter_peer_transit_network` to `catalystcenter_transit_network` resource 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 - Add `catalystcenter_fabric_l2_handoff` resource and data source diff --git a/docs/data-sources/transit_peer_network.md b/docs/data-sources/transit_peer_network.md deleted file mode 100644 index 892ca67..0000000 --- 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 82fd486..c7b27ea 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.1.11 (unreleased) + +- BREAKING CHANGE: Renamed `catalystcenter_peer_transit_network` to `catalystcenter_transit_network` resource 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 - Add `catalystcenter_fabric_l2_handoff` resource and data source diff --git a/docs/resources/transit_peer_network.md b/docs/resources/transit_peer_network.md deleted file mode 100644 index 381af68..0000000 --- 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_peer_network/data-source.tf b/examples/data-sources/catalystcenter_transit_peer_network/data-source.tf deleted file mode 100644 index c4ae4e1..0000000 --- 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_peer_network/import.sh b/examples/resources/catalystcenter_transit_peer_network/import.sh deleted file mode 100644 index 4f811ef..0000000 --- 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 655cd66..0000000 --- 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 4741cd2..e8472b3 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_peer_network.yaml b/gen/definitions/transit_peer_network.yaml deleted file mode 100644 index dff8cee..0000000 --- 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 11cd64f..35cb7c4 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_network_test.go b/internal/provider/data_source_catalystcenter_transit_network_test.go index 5a0d2d2..7927cd8 100644 --- a/internal/provider/data_source_catalystcenter_transit_network_test.go +++ b/internal/provider/data_source_catalystcenter_transit_network_test.go @@ -62,6 +62,7 @@ func testAccDataSourceCcTransitNetworkConfig() string { config += ` data "catalystcenter_transit_network" "test" { name = "TRANSIT_1" + depends_on = [catalystcenter_transit_network.test] } ` return config diff --git a/internal/provider/data_source_catalystcenter_transit_peer_network.go b/internal/provider/data_source_catalystcenter_transit_peer_network.go deleted file mode 100644 index 60fa9a4..0000000 --- a/internal/provider/data_source_catalystcenter_transit_peer_network.go +++ /dev/null @@ -1,139 +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" - "fmt" - "net/url" - - "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-log/tflog" - cc "github.com/netascode/go-catalystcenter" -) - -// End of section. //template:end imports - -// Section below is generated&owned by "gen/generator.go". //template:begin model - -// Ensure the implementation satisfies the expected interfaces. -var ( - _ datasource.DataSource = &TransitPeerNetworkDataSource{} - _ datasource.DataSourceWithConfigure = &TransitPeerNetworkDataSource{} -) - -func NewTransitPeerNetworkDataSource() datasource.DataSource { - return &TransitPeerNetworkDataSource{} -} - -type TransitPeerNetworkDataSource 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 *TransitPeerNetworkDataSource) 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.", - - 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", - Required: true, - }, - "transit_peer_network_type": schema.StringAttribute{ - MarkdownDescription: "Transit Peer Network Type", - Computed: true, - }, - "routing_protocol_name": schema.StringAttribute{ - MarkdownDescription: "Routing Protocol Name", - Computed: true, - }, - "autonomous_system_number": schema.StringAttribute{ - MarkdownDescription: "Autonomous System Number", - Computed: true, - }, - "transit_control_plane_settings": schema.ListNestedAttribute{ - MarkdownDescription: "Transit Control Plane Settings info", - 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) { - if req.ProviderData == nil { - return - } - - d.client = req.ProviderData.(*CcProviderData).Client -} - -// 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 - - // 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.Id.String())) - - params := "" - params += "?transitPeerNetworkName=" + url.QueryEscape(config.TransitPeerNetworkName.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)) - return - } - - config.fromBody(ctx, res) - - tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString())) - - diags = resp.State.Set(ctx, &config) - resp.Diagnostics.Append(diags...) -} - -// End of section. //template:end read diff --git a/internal/provider/data_source_catalystcenter_transit_peer_network_test.go b/internal/provider/data_source_catalystcenter_transit_peer_network_test.go deleted file mode 100644 index ba34663..0000000 --- a/internal/provider/data_source_catalystcenter_transit_peer_network_test.go +++ /dev/null @@ -1,71 +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 ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" -) - -// End of section. //template:end imports - -// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource -func TestAccDataSourceCcTransitPeerNetwork(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")) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceCcTransitPeerNetworkConfig(), - Check: resource.ComposeTestCheckFunc(checks...), - }, - }, - }) -} - -// End of section. //template:end testAccDataSource - -// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites -// 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" - 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] - } - ` - return config -} - -// End of section. //template:end testAccDataSourceConfig 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 ad90a6e..0000000 --- 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 e5e97aa..a2f82da 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -281,7 +281,6 @@ func (p *CcProvider) Resources(ctx context.Context) []func() resource.Resource { NewTemplateResource, NewTemplateVersionResource, NewTransitNetworkResource, - NewTransitPeerNetworkResource, NewUserResource, NewVirtualNetworkIPPoolResource, NewVirtualNetworkToFabricSiteResource, @@ -329,7 +328,6 @@ func (p *CcProvider) DataSources(ctx context.Context) []func() datasource.DataSo NewTemplateDataSource, NewTemplateVersionDataSource, NewTransitNetworkDataSource, - NewTransitPeerNetworkDataSource, 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 47cf394..7e8f833 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_peer_network.go deleted file mode 100644 index 1ee101a..0000000 --- a/internal/provider/resource_catalystcenter_transit_peer_network.go +++ /dev/null @@ -1,288 +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" - "fmt" - "net/url" - "strings" - - "github.com/CiscoDevNet/terraform-provider-catalystcenter/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" - cc "github.com/netascode/go-catalystcenter" -) - -// End of section. //template:end imports - -// 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{} - -func NewTransitPeerNetworkResource() resource.Resource { - return &TransitPeerNetworkResource{} -} - -type TransitPeerNetworkResource 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 *TransitPeerNetworkResource) 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, - - Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{ - MarkdownDescription: "The id of the object", - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - "transit_peer_network_name": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Transit Peer 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, - Required: true, - Validators: []validator.String{ - stringvalidator.OneOf("ip_transit", "sda_transit_with_lisp_bgp", "sda_transit_with_pub_sub"), - }, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "routing_protocol_name": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Routing Protocol Name").AddStringEnumDescription("BGP").String, - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOf("BGP"), - }, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "autonomous_system_number": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Autonomous System Number").String, - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "transit_control_plane_settings": schema.ListNestedAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Transit Control Plane Settings info").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) { - if req.ProviderData == nil { - return - } - - r.client = req.ProviderData.(*CcProviderData).Client -} - -// 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 - - // Read plan - diags := req.Plan.Get(ctx, &plan) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) - - // Create object - body := plan.toBody(ctx, TransitPeerNetwork{}) - - params := "" - res, err := r.client.Post(plan.getPath()+params, body) - if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) - return - } - params = "" - params += "?transitPeerNetworkName=" + url.QueryEscape(plan.TransitPeerNetworkName.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()) - - tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Id.ValueString())) - - diags = resp.State.Set(ctx, &plan) - resp.Diagnostics.Append(diags...) -} - -// 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 - - // 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.String())) - - params := "" - params += "?transitPeerNetworkName=" + url.QueryEscape(state.TransitPeerNetworkName.ValueString()) - res, err := r.client.Get(state.getPath() + params) - if err != nil && strings.Contains(err.Error(), "StatusCode 404") { - resp.State.RemoveResource(ctx) - return - } else if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) - return - } - - // If every attribute is set to null we are dealing with an import operation and therefore reading all attributes - if state.isNull(ctx, res) { - state.fromBody(ctx, res) - } else { - state.updateFromBody(ctx, res) - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) - - diags = resp.State.Set(ctx, &state) - resp.Diagnostics.Append(diags...) -} - -// 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 - - // 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 - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) - - tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Id.ValueString())) - - diags = resp.State.Set(ctx, &plan) - resp.Diagnostics.Append(diags...) -} - -// 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 - - // 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())) - params := "?transitPeerNetworkName=" + url.QueryEscape(state.TransitPeerNetworkName.ValueString()) - res, err := r.client.Delete(state.getPath() + params) - if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) - return - } - - tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString())) - - resp.State.RemoveResource(ctx) -} - -// 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) { - 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), - ) - return - } - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("transit_peer_network_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_peer_network_test.go deleted file mode 100644 index 62fa7c4..0000000 --- a/internal/provider/resource_catalystcenter_transit_peer_network_test.go +++ /dev/null @@ -1,77 +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 ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" -) - -// End of section. //template:end imports - -// Section below is generated&owned by "gen/generator.go". //template:begin testAcc -func TestAccCcTransitPeerNetwork(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")) - - var steps []resource.TestStep - steps = append(steps, resource.TestStep{ - Config: testAccCcTransitPeerNetworkConfig_all(), - Check: resource.ComposeTestCheckFunc(checks...), - }) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - Steps: steps, - }) -} - -// End of section. //template:end testAcc - -// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites -// 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" - config += `}` + "\n" - return config -} - -// 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" - config += ` routing_protocol_name = "BGP"` + "\n" - config += ` autonomous_system_number = "65010"` + "\n" - config += `}` + "\n" - return config -} - -// End of section. //template:end testAccConfigAll diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 82fd486..c7b27ea 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.1.11 (unreleased) + +- BREAKING CHANGE: Renamed `catalystcenter_peer_transit_network` to `catalystcenter_transit_network` resource 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 - Add `catalystcenter_fabric_l2_handoff` resource and data source