-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fabric l2 handoff resource and data source (#112)
- Loading branch information
1 parent
2cf53db
commit d0f0efa
Showing
16 changed files
with
927 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "catalystcenter_fabric_l2_handoff Data Source - terraform-provider-catalystcenter" | ||
subcategory: "SDA" | ||
description: |- | ||
This data source can read the Fabric L2 Handoff. | ||
--- | ||
|
||
# catalystcenter_fabric_l2_handoff (Data Source) | ||
|
||
This data source can read the Fabric L2 Handoff. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "catalystcenter_fabric_l2_handoff" "example" { | ||
id = "76d24097-41c4-4558-a4d0-a8c07ac08470" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1" | ||
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `fabric_id` (String) ID of the fabric this device belongs to | ||
- `id` (String) The id of the object | ||
- `network_device_id` (String) Network device ID of the fabric device | ||
|
||
### Read-Only | ||
|
||
- `external_vlan_id` (Number) External VLAN number into which the fabric must be extended. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094) | ||
- `interface_name` (String) Interface name of the layer 2 handoff. E.g., GigabitEthernet1/0/4 | ||
- `internal_vlan_id` (Number) VLAN number associated with this fabric. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "catalystcenter_fabric_l2_handoff Resource - terraform-provider-catalystcenter" | ||
subcategory: "SDA" | ||
description: |- | ||
Manages Layer 2 Handoffs in Fabric Devices | ||
--- | ||
|
||
# catalystcenter_fabric_l2_handoff (Resource) | ||
|
||
Manages Layer 2 Handoffs in Fabric Devices | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "catalystcenter_fabric_l2_handoff" "example" { | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1" | ||
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f" | ||
interface_name = "GigabitEthernet1/0/4" | ||
internal_vlan_id = 300 | ||
external_vlan_id = 400 | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `external_vlan_id` (Number) External VLAN number into which the fabric must be extended. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094) | ||
- `fabric_id` (String) ID of the fabric this device belongs to | ||
- `interface_name` (String) Interface name of the layer 2 handoff. E.g., GigabitEthernet1/0/4 | ||
- `internal_vlan_id` (Number) VLAN number associated with this fabric. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094) | ||
- `network_device_id` (String) Network device ID of the fabric device | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The id of the object | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import catalystcenter_fabric_l2_handoff.example "<network_device_id>,<fabric_id>,<id>" | ||
``` |
5 changes: 5 additions & 0 deletions
5
examples/data-sources/catalystcenter_fabric_l2_handoff/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
data "catalystcenter_fabric_l2_handoff" "example" { | ||
id = "76d24097-41c4-4558-a4d0-a8c07ac08470" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1" | ||
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import catalystcenter_fabric_l2_handoff.example "<network_device_id>,<fabric_id>,<id>" |
7 changes: 7 additions & 0 deletions
7
examples/resources/catalystcenter_fabric_l2_handoff/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
resource "catalystcenter_fabric_l2_handoff" "example" { | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1" | ||
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f" | ||
interface_name = "GigabitEthernet1/0/4" | ||
internal_vlan_id = 300 | ||
external_vlan_id = 400 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
name: Fabric L2 Handoff | ||
rest_endpoint: /dna/intent/api/v1/sda/fabricDevices/layer2Handoffs | ||
res_description: Manages Layer 2 Handoffs in Fabric Devices | ||
id_from_query_path: response | ||
id_from_query_path_attribute: id | ||
put_id_include_path: 0.id | ||
get_from_all: true | ||
put_no_id: true | ||
doc_category: SDA | ||
test_tags: [SDA] | ||
attributes: | ||
- model_name: networkDeviceId | ||
query_param: true | ||
requires_replace: true | ||
data_path: '0' | ||
response_data_path: networkDeviceId | ||
mandatory: true | ||
description: Network device ID of the fabric device | ||
type: String | ||
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1 | ||
- model_name: fabricId | ||
requires_replace: true | ||
query_param: true | ||
data_path: '0' | ||
response_data_path: fabricId | ||
type: String | ||
mandatory: true | ||
description: ID of the fabric this device belongs to | ||
example: c4b85bb2-ce3f-4db9-a32b-e439a388ac2f | ||
test_value: catalystcenter_fabric_site.test.id | ||
- model_name: interfaceName | ||
requires_replace: true | ||
data_path: '0' | ||
response_data_path: interfaceName | ||
type: String | ||
mandatory: true | ||
description: Interface name of the layer 2 handoff. E.g., GigabitEthernet1/0/4 | ||
example: GigabitEthernet1/0/4 | ||
- model_name: internalVlanId | ||
data_path: '0' | ||
requires_replace: true | ||
response_data_path: internalVlanId | ||
type: Int64 | ||
match_id: true | ||
mandatory: true | ||
description: VLAN number associated with this fabric. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094) | ||
example: 300 | ||
- model_name: externalVlanId | ||
data_path: '0' | ||
requires_replace: true | ||
response_data_path: externalVlanId | ||
mandatory: true | ||
type: Int64 | ||
description: External VLAN number into which the fabric must be extended. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094) | ||
example: 400 | ||
test_prerequisites: | | ||
resource "catalystcenter_area" "test" { | ||
name = "Area1" | ||
parent_name = "Global" | ||
} | ||
resource "catalystcenter_fabric_site" "test" { | ||
site_id = catalystcenter_area.test.id | ||
pub_sub_enabled = false | ||
authentication_profile_name = "No Authentication" | ||
depends_on = [catalystcenter_area.test] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
internal/provider/data_source_catalystcenter_fabric_l2_handoff.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// 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 = &FabricL2HandoffDataSource{} | ||
_ datasource.DataSourceWithConfigure = &FabricL2HandoffDataSource{} | ||
) | ||
|
||
func NewFabricL2HandoffDataSource() datasource.DataSource { | ||
return &FabricL2HandoffDataSource{} | ||
} | ||
|
||
type FabricL2HandoffDataSource struct { | ||
client *cc.Client | ||
} | ||
|
||
func (d *FabricL2HandoffDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_fabric_l2_handoff" | ||
} | ||
|
||
func (d *FabricL2HandoffDataSource) 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 Fabric L2 Handoff.", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The id of the object", | ||
Required: true, | ||
}, | ||
"network_device_id": schema.StringAttribute{ | ||
MarkdownDescription: "Network device ID of the fabric device", | ||
Required: true, | ||
}, | ||
"fabric_id": schema.StringAttribute{ | ||
MarkdownDescription: "ID of the fabric this device belongs to", | ||
Required: true, | ||
}, | ||
"interface_name": schema.StringAttribute{ | ||
MarkdownDescription: "Interface name of the layer 2 handoff. E.g., GigabitEthernet1/0/4", | ||
Computed: true, | ||
}, | ||
"internal_vlan_id": schema.Int64Attribute{ | ||
MarkdownDescription: "VLAN number associated with this fabric. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094)", | ||
Computed: true, | ||
}, | ||
"external_vlan_id": schema.Int64Attribute{ | ||
MarkdownDescription: "External VLAN number into which the fabric must be extended. Allowed VLAN range is 2-4094 except for reserved vlans (1, 1002-1005, 2046, 4094)", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *FabricL2HandoffDataSource) 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 *FabricL2HandoffDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config FabricL2Handoff | ||
|
||
// 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 += "?networkDeviceId=" + url.QueryEscape(config.NetworkDeviceId.ValueString()) + "&fabricId=" + url.QueryEscape(config.FabricId.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 | ||
} | ||
res = res.Get("response.#(id==\"" + config.Id.ValueString() + "\")") | ||
|
||
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 |
Oops, something went wrong.