From 6887ffe6ab71c85143f9b6d36a91fb0baceb953c Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 12 Aug 2024 11:22:45 +0200 Subject: [PATCH 1/2] Modified Transit to use new API --- docs/data-sources/transit_network.md | 35 +++ docs/resources/transit_network.md | 51 ++++ .../data-source.tf | 3 + .../catalystcenter_transit_network/import.sh | 1 + .../resource.tf | 6 + gen/definitions/transit_network.yaml | 58 ++++ ...a_source_catalystcenter_transit_network.go | 133 +++++++++ ...rce_catalystcenter_transit_network_test.go | 70 +++++ .../model_catalystcenter_transit_network.go | 188 ++++++++++++ internal/provider/provider.go | 2 + ...resource_catalystcenter_transit_network.go | 282 ++++++++++++++++++ ...rce_catalystcenter_transit_network_test.go | 77 +++++ 12 files changed, 906 insertions(+) create mode 100644 docs/data-sources/transit_network.md create mode 100644 docs/resources/transit_network.md create mode 100644 examples/data-sources/catalystcenter_transit_network/data-source.tf create mode 100644 examples/resources/catalystcenter_transit_network/import.sh create mode 100644 examples/resources/catalystcenter_transit_network/resource.tf create mode 100644 gen/definitions/transit_network.yaml create mode 100644 internal/provider/data_source_catalystcenter_transit_network.go create mode 100644 internal/provider/data_source_catalystcenter_transit_network_test.go create mode 100644 internal/provider/model_catalystcenter_transit_network.go create mode 100644 internal/provider/resource_catalystcenter_transit_network.go create mode 100644 internal/provider/resource_catalystcenter_transit_network_test.go 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/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/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/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/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/internal/provider/data_source_catalystcenter_transit_network.go b/internal/provider/data_source_catalystcenter_transit_network.go new file mode 100644 index 00000000..1ff97618 --- /dev/null +++ b/internal/provider/data_source_catalystcenter_transit_network.go @@ -0,0 +1,133 @@ +// 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-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 the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &TransitNetworkDataSource{} + _ datasource.DataSourceWithConfigure = &TransitNetworkDataSource{} +) + +func NewTransitNetworkDataSource() datasource.DataSource { + return &TransitNetworkDataSource{} +} + +type TransitNetworkDataSource struct { + client *cc.Client +} + +func (d *TransitNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transit_network" +} + +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 Network.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "Transit Network Name", + Required: true, + }, + "type": schema.StringAttribute{ + MarkdownDescription: "Transit 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, + }, + "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, + }, + }, + } +} + +func (d *TransitNetworkDataSource) 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 *TransitNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config TransitNetwork + + // 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 += "?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)) + 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_network_test.go b/internal/provider/data_source_catalystcenter_transit_network_test.go new file mode 100644 index 00000000..5a0d2d2d --- /dev/null +++ b/internal/provider/data_source_catalystcenter_transit_network_test.go @@ -0,0 +1,70 @@ +// 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 TestAccDataSourceCcTransitNetwork(t *testing.T) { + var checks []resource.TestCheckFunc + 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: testAccDataSourceCcTransitNetworkConfig(), + 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 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_network" "test" { + name = "TRANSIT_1" + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig 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/provider.go b/internal/provider/provider.go index 4f4db7d6..e5e97aa2 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -280,6 +280,7 @@ func (p *CcProvider) Resources(ctx context.Context) []func() resource.Resource { NewTagResource, NewTemplateResource, NewTemplateVersionResource, + NewTransitNetworkResource, NewTransitPeerNetworkResource, NewUserResource, NewVirtualNetworkIPPoolResource, @@ -327,6 +328,7 @@ func (p *CcProvider) DataSources(ctx context.Context) []func() datasource.DataSo NewTagDataSource, NewTemplateDataSource, NewTemplateVersionDataSource, + NewTransitNetworkDataSource, NewTransitPeerNetworkDataSource, NewUserDataSource, NewWirelessEnterpriseSSIDDataSource, diff --git a/internal/provider/resource_catalystcenter_transit_network.go b/internal/provider/resource_catalystcenter_transit_network.go new file mode 100644 index 00000000..5d92466a --- /dev/null +++ b/internal/provider/resource_catalystcenter_transit_network.go @@ -0,0 +1,282 @@ +// 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 = &TransitNetworkResource{} +var _ resource.ResourceWithImportState = &TransitNetworkResource{} + +func NewTransitNetworkResource() resource.Resource { + return &TransitNetworkResource{} +} + +type TransitNetworkResource struct { + client *cc.Client +} + +func (r *TransitNetworkResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transit_network" +} + +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 Network.").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Transit Network Name").String, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "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_BASED_TRANSIT", "SDA_LISP_PUB_SUB_TRANSIT", "SDA_LISP_BGP_TRANSIT"), + }, + 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(), + }, + }, + "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, + }, + }, + } +} + +func (r *TransitNetworkResource) 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 *TransitNetworkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan TransitNetwork + + // 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, TransitNetwork{}) + + 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 += "?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("response.0.id").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 *TransitNetworkResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TransitNetwork + + // 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 += "?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) + 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 *TransitNetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state TransitNetwork + + // 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())) + + 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) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end update + +// Section below is generated&owned by "gen/generator.go". //template:begin delete +func (r *TransitNetworkResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TransitNetwork + + // 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())) + 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 + } + + 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 *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), + ) + return + } + 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_network_test.go b/internal/provider/resource_catalystcenter_transit_network_test.go new file mode 100644 index 00000000..5b11729d --- /dev/null +++ b/internal/provider/resource_catalystcenter_transit_network_test.go @@ -0,0 +1,77 @@ +// 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 TestAccCcTransitNetwork(t *testing.T) { + var checks []resource.TestCheckFunc + 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: testAccCcTransitNetworkConfig_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 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 +} + +// End of section. //template:end testAccConfigMinimal + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +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" + return config +} + +// End of section. //template:end testAccConfigAll From 2c3d9078e80c83625e9e13dd7c14d5ac7a658f4e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 12 Aug 2024 11:45:27 +0200 Subject: [PATCH 2/2] Changed Transit_Peer_Network to TransitNetwork --- CHANGELOG.md | 4 + docs/data-sources/transit_peer_network.md | 42 --- docs/guides/changelog.md | 4 + docs/resources/transit_peer_network.md | 58 ---- .../data-source.tf | 3 - .../import.sh | 1 - .../resource.tf | 6 - .../fabric_l3_handoff_ip_transit.yaml | 8 +- gen/definitions/transit_peer_network.yaml | 56 ---- ...enter_fabric_l3_handoff_ip_transit_test.go | 8 +- ...rce_catalystcenter_transit_network_test.go | 1 + ...rce_catalystcenter_transit_peer_network.go | 139 --------- ...atalystcenter_transit_peer_network_test.go | 71 ----- ...del_catalystcenter_transit_peer_network.go | 172 ----------- internal/provider/provider.go | 2 - ...enter_fabric_l3_handoff_ip_transit_test.go | 10 +- ...rce_catalystcenter_transit_peer_network.go | 288 ------------------ ...atalystcenter_transit_peer_network_test.go | 77 ----- templates/guides/changelog.md.tmpl | 4 + 19 files changed, 26 insertions(+), 928 deletions(-) delete mode 100644 docs/data-sources/transit_peer_network.md delete mode 100644 docs/resources/transit_peer_network.md delete mode 100644 examples/data-sources/catalystcenter_transit_peer_network/data-source.tf delete mode 100644 examples/resources/catalystcenter_transit_peer_network/import.sh delete mode 100644 examples/resources/catalystcenter_transit_peer_network/resource.tf delete mode 100644 gen/definitions/transit_peer_network.yaml delete mode 100644 internal/provider/data_source_catalystcenter_transit_peer_network.go delete mode 100644 internal/provider/data_source_catalystcenter_transit_peer_network_test.go delete mode 100644 internal/provider/model_catalystcenter_transit_peer_network.go delete mode 100644 internal/provider/resource_catalystcenter_transit_peer_network.go delete mode 100644 internal/provider/resource_catalystcenter_transit_peer_network_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 39447ca9..65b2e2a9 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 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 82fd4862..c7b27ead 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 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_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_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_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_network_test.go b/internal/provider/data_source_catalystcenter_transit_network_test.go index 5a0d2d2d..7927cd8f 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 60fa9a44..00000000 --- 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 ba346637..00000000 --- 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 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 e5e97aa2..a2f82da1 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 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_peer_network.go deleted file mode 100644 index 1ee101a7..00000000 --- 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 62fa7c4e..00000000 --- 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 82fd4862..c7b27ead 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