Skip to content

Commit 37789d4

Browse files
Add fabric device resource and data source (#102)
1 parent 5d4fb27 commit 37789d4

File tree

15 files changed

+1104
-0
lines changed

15 files changed

+1104
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.1.10 (unreleased)
22

3+
- Add `fabric_device` resource and data source, this resource now only works with Catalyst Center version 2.3.7.5+ `/sda/fabricDevices`
34
- Add `fabric_l3_handoff_ip_transit` resource and data source
45
- Add `transitPeerNetworkId` as `id` to `transit_peer_network` resource
56
- Add `anycast_gateway` resource and data source, this resource now only works with Catalyst Center version 2.3.7.5+ `/sda/anycastGateways`

docs/data-sources/fabric_device.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "catalystcenter_fabric_device Data Source - terraform-provider-catalystcenter"
4+
subcategory: "SDA"
5+
description: |-
6+
This data source can read the Fabric Device.
7+
---
8+
9+
# catalystcenter_fabric_device (Data Source)
10+
11+
This data source can read the Fabric Device.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "catalystcenter_fabric_device" "example" {
17+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
18+
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `fabric_id` (String) ID of the fabric site/zone of this fabric device
28+
- `network_device_id` (String) Network device ID of the fabric device
29+
30+
### Read-Only
31+
32+
- `border_priority` (Number) Border priority of the fabric border device. A lower value indicates higher priority
33+
- `border_types` (List of String) List of the border types of the fabric device. Allowed values are [LAYER_2, LAYER_3]
34+
- `default_exit` (Boolean) Set this to make the fabric border device the gateway of last resort for this site. Any unknown traffic will be sent to this fabric border device from edge nodes
35+
- `device_roles` (List of String) List of the roles of the fabric device. Allowed values are [CONTROL_PLANE_NODE, EDGE_NODE, BORDER_NODE]
36+
- `id` (String) The id of the object
37+
- `import_external_routes` (Boolean) Set this to import external routes from other routing protocols (such as BGP) to the fabric control plane
38+
- `local_autonomous_system_number` (String) BGP Local autonomous system number of the fabric border device
39+
- `prepend_autonomous_system_count` (Number) Prepend autonomous system count of the fabric border device

docs/guides/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ description: |-
99

1010
## 0.1.10 (unreleased)
1111

12+
- Add `fabric_device` resource and data source, this resource now only works with Catalyst Center version 2.3.7.5+ `/sda/fabricDevices`
1213
- Add `fabric_l3_handoff_ip_transit` resource and data source
1314
- Add `transitPeerNetworkId` as `id` to `transit_peer_network` resource
1415
- Add `anycast_gateway` resource and data source, this resource now only works with Catalyst Center version 2.3.7.5+ `/sda/anycastGateways`

docs/resources/fabric_device.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "catalystcenter_fabric_device Resource - terraform-provider-catalystcenter"
4+
subcategory: "SDA"
5+
description: |-
6+
Manages Fabric Devices
7+
---
8+
9+
# catalystcenter_fabric_device (Resource)
10+
11+
Manages Fabric Devices
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "catalystcenter_fabric_device" "example" {
17+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
18+
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f"
19+
device_roles = ["CONTROL_PLANE_NODE"]
20+
border_types = ["LAYER_3"]
21+
local_autonomous_system_number = "65000"
22+
default_exit = true
23+
import_external_routes = false
24+
border_priority = 5
25+
prepend_autonomous_system_count = 1
26+
}
27+
```
28+
29+
<!-- schema generated by tfplugindocs -->
30+
## Schema
31+
32+
### Required
33+
34+
- `device_roles` (List of String) List of the roles of the fabric device. Allowed values are [CONTROL_PLANE_NODE, EDGE_NODE, BORDER_NODE]
35+
- `fabric_id` (String) ID of the fabric site/zone of this fabric device
36+
- `network_device_id` (String) Network device ID of the fabric device
37+
38+
### Optional
39+
40+
- `border_priority` (Number) Border priority of the fabric border device. A lower value indicates higher priority
41+
- Range: `1`-`9`
42+
- Default value: `10`
43+
- `border_types` (List of String) List of the border types of the fabric device. Allowed values are [LAYER_2, LAYER_3]
44+
- `default_exit` (Boolean) Set this to make the fabric border device the gateway of last resort for this site. Any unknown traffic will be sent to this fabric border device from edge nodes
45+
- `import_external_routes` (Boolean) Set this to import external routes from other routing protocols (such as BGP) to the fabric control plane
46+
- `local_autonomous_system_number` (String) BGP Local autonomous system number of the fabric border device
47+
- `prepend_autonomous_system_count` (Number) Prepend autonomous system count of the fabric border device
48+
- Range: `1`-`10`
49+
50+
### Read-Only
51+
52+
- `id` (String) The id of the object
53+
54+
## Import
55+
56+
Import is supported using the following syntax:
57+
58+
```shell
59+
terraform import catalystcenter_fabric_device.example "<network_device_id>,<fabric_id>"
60+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "catalystcenter_fabric_device" "example" {
2+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
3+
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import catalystcenter_fabric_device.example "<network_device_id>,<fabric_id>"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "catalystcenter_fabric_device" "example" {
2+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
3+
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f"
4+
device_roles = ["CONTROL_PLANE_NODE"]
5+
border_types = ["LAYER_3"]
6+
local_autonomous_system_number = "65000"
7+
default_exit = true
8+
import_external_routes = false
9+
border_priority = 5
10+
prepend_autonomous_system_count = 1
11+
}

gen/definitions/fabric_device.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: Fabric Device
3+
rest_endpoint: /dna/intent/api/v1/sda/fabricDevices
4+
res_description: Manages Fabric Devices
5+
id_from_query_path: response.0
6+
id_from_query_path_attribute: id
7+
put_id_include_path: 0.id
8+
import_no_id: true
9+
data_source_no_id: true
10+
put_no_id: true
11+
max_async_wait_time: 120
12+
doc_category: SDA
13+
test_tags: [SDA]
14+
attributes:
15+
- model_name: networkDeviceId
16+
query_param: true
17+
requires_replace: true
18+
data_path: '0'
19+
response_data_path: response.0.networkDeviceId
20+
mandatory: true
21+
description: Network device ID of the fabric device
22+
type: String
23+
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1
24+
- model_name: fabricId
25+
requires_replace: true
26+
query_param: true
27+
data_path: '0'
28+
response_data_path: response.0.fabricId
29+
type: String
30+
mandatory: true
31+
description: ID of the fabric site/zone of this fabric device
32+
example: c4b85bb2-ce3f-4db9-a32b-e439a388ac2f
33+
test_value: catalystcenter_fabric_site.test.id
34+
- model_name: deviceRoles
35+
requires_replace: true
36+
data_path: '0'
37+
response_data_path: response.0.deviceRoles
38+
type: List
39+
element_type: String
40+
mandatory: true
41+
description: List of the roles of the fabric device. Allowed values are [CONTROL_PLANE_NODE, EDGE_NODE, BORDER_NODE]
42+
example: CONTROL_PLANE_NODE
43+
- model_name: borderTypes
44+
data_path: '0.borderDeviceSettings'
45+
response_data_path: response.0.borderDeviceSettings.borderTypes
46+
type: List
47+
element_type: String
48+
description: List of the border types of the fabric device. Allowed values are [LAYER_2, LAYER_3]
49+
example: LAYER_3
50+
- model_name: localAutonomousSystemNumber
51+
data_path: '0.borderDeviceSettings.layer3Settings'
52+
response_data_path: response.0.borderDeviceSettings.layer3Settings.localAutonomousSystemNumber
53+
type: String
54+
description: BGP Local autonomous system number of the fabric border device
55+
example: "65000"
56+
- model_name: isDefaultExit
57+
tf_name: default_exit
58+
data_path: '0.borderDeviceSettings.layer3Settings'
59+
response_data_path: response.0.borderDeviceSettings.layer3Settings.isDefaultExit
60+
type: Bool
61+
description: Set this to make the fabric border device the gateway of last resort for this site. Any unknown traffic will be sent to this fabric border device from edge nodes
62+
example: true
63+
- model_name: importExternalRoutes
64+
data_path: '0.borderDeviceSettings.layer3Settings'
65+
response_data_path: response.0.borderDeviceSettings.layer3Settings.importExternalRoutes
66+
type: Bool
67+
description: Set this to import external routes from other routing protocols (such as BGP) to the fabric control plane
68+
example: false
69+
- model_name: borderPriority
70+
data_path: '0.borderDeviceSettings.layer3Settings'
71+
response_data_path: response.0.borderDeviceSettings.layer3Settings.borderPriority
72+
type: Int64
73+
min_int: 1
74+
max_int: 9
75+
description: Border priority of the fabric border device. A lower value indicates higher priority
76+
example: 5
77+
default_value: 10
78+
- model_name: prependAutonomousSystemCount
79+
data_path: '0.borderDeviceSettings.layer3Settings'
80+
response_data_path: response.0.borderDeviceSettings.layer3Settings.prependAutonomousSystemCount
81+
type: Int64
82+
description: Prepend autonomous system count of the fabric border device
83+
example: 1
84+
min_int: 1
85+
max_int: 10
86+
test_prerequisites: |
87+
resource "catalystcenter_area" "test" {
88+
name = "Area1"
89+
parent_name = "Global"
90+
}
91+
resource "catalystcenter_fabric_site" "test" {
92+
site_id = catalystcenter_area.test.id
93+
pub_sub_enabled = false
94+
authentication_profile_name = "No Authentication"
95+
depends_on = [catalystcenter_area.test]
96+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
2+
// All rights reserved.
3+
//
4+
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://mozilla.org/MPL/2.0/
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
// SPDX-License-Identifier: MPL-2.0
17+
18+
package provider
19+
20+
// Section below is generated&owned by "gen/generator.go". //template:begin imports
21+
import (
22+
"context"
23+
"fmt"
24+
"net/url"
25+
26+
"github.com/hashicorp/terraform-plugin-framework/datasource"
27+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
28+
"github.com/hashicorp/terraform-plugin-framework/types"
29+
"github.com/hashicorp/terraform-plugin-log/tflog"
30+
cc "github.com/netascode/go-catalystcenter"
31+
)
32+
33+
// End of section. //template:end imports
34+
35+
// Section below is generated&owned by "gen/generator.go". //template:begin model
36+
37+
// Ensure the implementation satisfies the expected interfaces.
38+
var (
39+
_ datasource.DataSource = &FabricDeviceDataSource{}
40+
_ datasource.DataSourceWithConfigure = &FabricDeviceDataSource{}
41+
)
42+
43+
func NewFabricDeviceDataSource() datasource.DataSource {
44+
return &FabricDeviceDataSource{}
45+
}
46+
47+
type FabricDeviceDataSource struct {
48+
client *cc.Client
49+
}
50+
51+
func (d *FabricDeviceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
52+
resp.TypeName = req.ProviderTypeName + "_fabric_device"
53+
}
54+
55+
func (d *FabricDeviceDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
56+
resp.Schema = schema.Schema{
57+
// This description is used by the documentation generator and the language server.
58+
MarkdownDescription: "This data source can read the Fabric Device.",
59+
60+
Attributes: map[string]schema.Attribute{
61+
"id": schema.StringAttribute{
62+
MarkdownDescription: "The id of the object",
63+
Computed: true,
64+
},
65+
"network_device_id": schema.StringAttribute{
66+
MarkdownDescription: "Network device ID of the fabric device",
67+
Required: true,
68+
},
69+
"fabric_id": schema.StringAttribute{
70+
MarkdownDescription: "ID of the fabric site/zone of this fabric device",
71+
Required: true,
72+
},
73+
"device_roles": schema.ListAttribute{
74+
MarkdownDescription: "List of the roles of the fabric device. Allowed values are [CONTROL_PLANE_NODE, EDGE_NODE, BORDER_NODE]",
75+
ElementType: types.StringType,
76+
Computed: true,
77+
},
78+
"border_types": schema.ListAttribute{
79+
MarkdownDescription: "List of the border types of the fabric device. Allowed values are [LAYER_2, LAYER_3]",
80+
ElementType: types.StringType,
81+
Computed: true,
82+
},
83+
"local_autonomous_system_number": schema.StringAttribute{
84+
MarkdownDescription: "BGP Local autonomous system number of the fabric border device",
85+
Computed: true,
86+
},
87+
"default_exit": schema.BoolAttribute{
88+
MarkdownDescription: "Set this to make the fabric border device the gateway of last resort for this site. Any unknown traffic will be sent to this fabric border device from edge nodes",
89+
Computed: true,
90+
},
91+
"import_external_routes": schema.BoolAttribute{
92+
MarkdownDescription: "Set this to import external routes from other routing protocols (such as BGP) to the fabric control plane",
93+
Computed: true,
94+
},
95+
"border_priority": schema.Int64Attribute{
96+
MarkdownDescription: "Border priority of the fabric border device. A lower value indicates higher priority",
97+
Computed: true,
98+
},
99+
"prepend_autonomous_system_count": schema.Int64Attribute{
100+
MarkdownDescription: "Prepend autonomous system count of the fabric border device",
101+
Computed: true,
102+
},
103+
},
104+
}
105+
}
106+
107+
func (d *FabricDeviceDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
108+
if req.ProviderData == nil {
109+
return
110+
}
111+
112+
d.client = req.ProviderData.(*CcProviderData).Client
113+
}
114+
115+
// End of section. //template:end model
116+
117+
// Section below is generated&owned by "gen/generator.go". //template:begin read
118+
func (d *FabricDeviceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
119+
var config FabricDevice
120+
121+
// Read config
122+
diags := req.Config.Get(ctx, &config)
123+
resp.Diagnostics.Append(diags...)
124+
if resp.Diagnostics.HasError() {
125+
return
126+
}
127+
128+
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
129+
130+
params := ""
131+
params += "?networkDeviceId=" + url.QueryEscape(config.NetworkDeviceId.ValueString()) + "&fabricId=" + url.QueryEscape(config.FabricId.ValueString())
132+
res, err := d.client.Get(config.getPath() + params)
133+
if err != nil {
134+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
135+
return
136+
}
137+
138+
config.fromBody(ctx, res)
139+
140+
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString()))
141+
142+
diags = resp.State.Set(ctx, &config)
143+
resp.Diagnostics.Append(diags...)
144+
}
145+
146+
// End of section. //template:end read

0 commit comments

Comments
 (0)