-
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 port assignment resource and data source (#117)
- Loading branch information
1 parent
87da53f
commit 23b609c
Showing
14 changed files
with
1,104 additions
and
0 deletions.
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,48 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "catalystcenter_fabric_port_assignment Data Source - terraform-provider-catalystcenter" | ||
subcategory: "SDA" | ||
description: |- | ||
This data source can read the Fabric Port Assignment. | ||
--- | ||
|
||
# catalystcenter_fabric_port_assignment (Data Source) | ||
|
||
This data source can read the Fabric Port Assignment. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "catalystcenter_fabric_port_assignment" "example" { | ||
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `fabric_id` (String) ID of the fabric the device is assigned to | ||
- `network_device_id` (String) Network device ID of the port assignment | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The id of the object | ||
- `port_assignments` (Attributes List) List of port assignments in SD-Access fabric (see [below for nested schema](#nestedatt--port_assignments)) | ||
|
||
<a id="nestedatt--port_assignments"></a> | ||
### Nested Schema for `port_assignments` | ||
|
||
Read-Only: | ||
|
||
- `authenticate_template_name` (String) Authenticate template name of the port assignment | ||
- `connected_device_type` (String) Connected device type of the port assignment | ||
- `data_vlan_name` (String) Data VLAN name of the port assignment | ||
- `fabric_id` (String) ID of the fabric the device is assigned to | ||
- `interface_description` (String) Interface description of the port assignment | ||
- `interface_name` (String) Interface name of the port assignment | ||
- `network_device_id` (String) Network device ID of the port assignment | ||
- `security_group_name` (String) Security group name of the port assignment | ||
- `voice_vlan_name` (String) Voice VLAN name of the port assignment |
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,67 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "catalystcenter_fabric_port_assignment Resource - terraform-provider-catalystcenter" | ||
subcategory: "SDA" | ||
description: |- | ||
Manages Port Assignments in SD-Access Fabric | ||
--- | ||
|
||
# catalystcenter_fabric_port_assignment (Resource) | ||
|
||
Manages Port Assignments in SD-Access Fabric | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "catalystcenter_fabric_port_assignment" "example" { | ||
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b" | ||
port_assignments = [ | ||
{ | ||
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1" | ||
interface_name = "GigabitEthernet1/0/2" | ||
connected_device_type = "USER_DEVICE" | ||
data_vlan_name = "DATA_VLAN" | ||
voice_vlan_name = "VOICE_VLAN" | ||
authenticate_template_name = "No Authentication" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `network_device_id` (String) Network device ID of the port assignment | ||
- `port_assignments` (Attributes List) List of port assignments in SD-Access fabric (see [below for nested schema](#nestedatt--port_assignments)) | ||
|
||
### Optional | ||
|
||
- `fabric_id` (String) ID of the fabric the device is assigned to | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The id of the object | ||
|
||
<a id="nestedatt--port_assignments"></a> | ||
### Nested Schema for `port_assignments` | ||
|
||
Required: | ||
|
||
- `connected_device_type` (String) Connected device type of the port assignment | ||
- Choices: `USER_DEVICE`, `ACCESS_POINT`, `TRUNKING_DEVICE`, `AUTHENTICATOR_SWITCH`, `SUPPLICANT_BASED_EXTENDED_NODE` | ||
- `fabric_id` (String) ID of the fabric the device is assigned to | ||
- `interface_name` (String) Interface name of the port assignment | ||
- `network_device_id` (String) Network device ID of the port assignment | ||
|
||
Optional: | ||
|
||
- `authenticate_template_name` (String) Authenticate template name of the port assignment | ||
- Choices: `No Authentication`, `Open Authentication`, `Closed Authentication`, `Low Impact` | ||
- `data_vlan_name` (String) Data VLAN name of the port assignment | ||
- `interface_description` (String) Interface description of the port assignment | ||
- `security_group_name` (String) Security group name of the port assignment | ||
- `voice_vlan_name` (String) Voice VLAN name of the port assignment |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/catalystcenter_fabric_port_assignment/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,4 @@ | ||
data "catalystcenter_fabric_port_assignment" "example" { | ||
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b" | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/resources/catalystcenter_fabric_port_assignment/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,15 @@ | ||
resource "catalystcenter_fabric_port_assignment" "example" { | ||
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b" | ||
port_assignments = [ | ||
{ | ||
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f" | ||
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1" | ||
interface_name = "GigabitEthernet1/0/2" | ||
connected_device_type = "USER_DEVICE" | ||
data_vlan_name = "DATA_VLAN" | ||
voice_vlan_name = "VOICE_VLAN" | ||
authenticate_template_name = "No Authentication" | ||
} | ||
] | ||
} |
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,85 @@ | ||
--- | ||
name: Fabric Port Assignment | ||
rest_endpoint: /dna/intent/api/v1/sda/portAssignments | ||
res_description: Manages Port Assignments in SD-Access Fabric | ||
no_update: true | ||
no_import: true | ||
data_source_no_id: true | ||
id_from_attribute: true | ||
root_list: true | ||
skip_minimum_test: true | ||
doc_category: SDA | ||
test_tags: [SDA] | ||
attributes: | ||
- tf_name: fabric_id | ||
write_only: true | ||
query_param: true | ||
delete_query_param: true | ||
query_param_name: fabricId | ||
delete_query_param_name: fabricId | ||
type: String | ||
description: ID of the fabric the device is assigned to | ||
example: e02d9911-b0a7-435b-bb46-079d877d7b3e | ||
- tf_name: network_device_id | ||
write_only: true | ||
id: true | ||
query_param: true | ||
delete_query_param: true | ||
query_param_name: networkDeviceId | ||
delete_query_param_name: networkDeviceId | ||
type: String | ||
description: Network device ID of the port assignment | ||
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b | ||
- tf_name: port_assignments | ||
type: List | ||
response_data_path: response | ||
mandatory: true | ||
description: List of port assignments in SD-Access fabric | ||
attributes: | ||
- model_name: fabricId | ||
query_param: true | ||
type: String | ||
mandatory: true | ||
description: ID of the fabric the device is assigned to | ||
example: c4b85bb2-ce3f-4db9-a32b-e439a388ac2f | ||
test_value: catalystcenter_fabric_site.test.id | ||
- model_name: networkDeviceId | ||
match_id: true | ||
query_param: true | ||
mandatory: true | ||
description: Network device ID of the port assignment | ||
type: String | ||
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1 | ||
- model_name: interfaceName | ||
query_param: true | ||
mandatory: true | ||
type: String | ||
description: Interface name of the port assignment | ||
example: GigabitEthernet1/0/2 | ||
- model_name: connectedDeviceType | ||
mandatory: true | ||
type: String | ||
description: Connected device type of the port assignment | ||
enum_values: [USER_DEVICE, ACCESS_POINT, TRUNKING_DEVICE, AUTHENTICATOR_SWITCH, SUPPLICANT_BASED_EXTENDED_NODE] | ||
example: USER_DEVICE | ||
- model_name: dataVlanName | ||
type: String | ||
description: Data VLAN name of the port assignment | ||
example: DATA_VLAN | ||
- model_name: voiceVlanName | ||
type: String | ||
description: Voice VLAN name of the port assignment | ||
example: VOICE_VLAN | ||
- model_name: authenticateTemplateName | ||
type: String | ||
description: Authenticate template name of the port assignment | ||
enum_values: [No Authentication, Open Authentication, Closed Authentication, Low Impact] | ||
example: No Authentication | ||
- model_name: securityGroupName | ||
type: String | ||
description: Security group name of the port assignment | ||
exclude_test: true | ||
- model_name: interfaceDescription | ||
type: String | ||
description: Interface description of the port assignment | ||
exclude_test: true |
159 changes: 159 additions & 0 deletions
159
internal/provider/data_source_catalystcenter_fabric_port_assignment.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,159 @@ | ||
// 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 = &FabricPortAssignmentDataSource{} | ||
_ datasource.DataSourceWithConfigure = &FabricPortAssignmentDataSource{} | ||
) | ||
|
||
func NewFabricPortAssignmentDataSource() datasource.DataSource { | ||
return &FabricPortAssignmentDataSource{} | ||
} | ||
|
||
type FabricPortAssignmentDataSource struct { | ||
client *cc.Client | ||
} | ||
|
||
func (d *FabricPortAssignmentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_fabric_port_assignment" | ||
} | ||
|
||
func (d *FabricPortAssignmentDataSource) 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 Port Assignment.", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The id of the object", | ||
Computed: true, | ||
}, | ||
"fabric_id": schema.StringAttribute{ | ||
MarkdownDescription: "ID of the fabric the device is assigned to", | ||
Required: true, | ||
}, | ||
"network_device_id": schema.StringAttribute{ | ||
MarkdownDescription: "Network device ID of the port assignment", | ||
Required: true, | ||
}, | ||
"port_assignments": schema.ListNestedAttribute{ | ||
MarkdownDescription: "List of port assignments in SD-Access fabric", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"fabric_id": schema.StringAttribute{ | ||
MarkdownDescription: "ID of the fabric the device is assigned to", | ||
Computed: true, | ||
}, | ||
"network_device_id": schema.StringAttribute{ | ||
MarkdownDescription: "Network device ID of the port assignment", | ||
Computed: true, | ||
}, | ||
"interface_name": schema.StringAttribute{ | ||
MarkdownDescription: "Interface name of the port assignment", | ||
Computed: true, | ||
}, | ||
"connected_device_type": schema.StringAttribute{ | ||
MarkdownDescription: "Connected device type of the port assignment", | ||
Computed: true, | ||
}, | ||
"data_vlan_name": schema.StringAttribute{ | ||
MarkdownDescription: "Data VLAN name of the port assignment", | ||
Computed: true, | ||
}, | ||
"voice_vlan_name": schema.StringAttribute{ | ||
MarkdownDescription: "Voice VLAN name of the port assignment", | ||
Computed: true, | ||
}, | ||
"authenticate_template_name": schema.StringAttribute{ | ||
MarkdownDescription: "Authenticate template name of the port assignment", | ||
Computed: true, | ||
}, | ||
"security_group_name": schema.StringAttribute{ | ||
MarkdownDescription: "Security group name of the port assignment", | ||
Computed: true, | ||
}, | ||
"interface_description": schema.StringAttribute{ | ||
MarkdownDescription: "Interface description of the port assignment", | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *FabricPortAssignmentDataSource) 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 *FabricPortAssignmentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config FabricPortAssignment | ||
|
||
// 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 += "?fabricId=" + url.QueryEscape(config.FabricId.ValueString()) + "&networkDeviceId=" + url.QueryEscape(config.NetworkDeviceId.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 |
Oops, something went wrong.