Skip to content

Commit

Permalink
Modified Transit to use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Aug 12, 2024
1 parent 52d4917 commit 6887ffe
Show file tree
Hide file tree
Showing 12 changed files with 906 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/data-sources/transit_network.md
Original file line number Diff line number Diff line change
@@ -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 generated by tfplugindocs -->
## 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
51 changes: 51 additions & 0 deletions docs/resources/transit_network.md
Original file line number Diff line number Diff line change
@@ -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 generated by tfplugindocs -->
## 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 "<name>"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "catalystcenter_transit_network" "example" {
name = "TRANSIT_1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import catalystcenter_transit_network.example "<name>"
6 changes: 6 additions & 0 deletions examples/resources/catalystcenter_transit_network/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "catalystcenter_transit_network" "example" {
name = "TRANSIT_1"
type = "IP_BASED_TRANSIT"
routing_protocol_name = "BGP"
autonomous_system_number = "65010"
}
58 changes: 58 additions & 0 deletions gen/definitions/transit_network.yaml
Original file line number Diff line number Diff line change
@@ -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
133 changes: 133 additions & 0 deletions internal/provider/data_source_catalystcenter_transit_network.go
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 6887ffe

Please sign in to comment.