Skip to content

Commit 23b609c

Browse files
Add fabric port assignment resource and data source (#117)
1 parent 87da53f commit 23b609c

File tree

14 files changed

+1104
-0
lines changed

14 files changed

+1104
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add `catalystcenter_fabric_vlan_to_ssid` resource and data source
44
- Add `catalystcenter_wireless_ssid` resource and data source
55
- Add `catalystcenter_site` data source
6+
- Add `catalystcenter_fabric_port_assignment` resource and data source
67

78
## 0.1.10
89

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "catalystcenter_fabric_port_assignment Data Source - terraform-provider-catalystcenter"
4+
subcategory: "SDA"
5+
description: |-
6+
This data source can read the Fabric Port Assignment.
7+
---
8+
9+
# catalystcenter_fabric_port_assignment (Data Source)
10+
11+
This data source can read the Fabric Port Assignment.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "catalystcenter_fabric_port_assignment" "example" {
17+
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e"
18+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `fabric_id` (String) ID of the fabric the device is assigned to
28+
- `network_device_id` (String) Network device ID of the port assignment
29+
30+
### Read-Only
31+
32+
- `id` (String) The id of the object
33+
- `port_assignments` (Attributes List) List of port assignments in SD-Access fabric (see [below for nested schema](#nestedatt--port_assignments))
34+
35+
<a id="nestedatt--port_assignments"></a>
36+
### Nested Schema for `port_assignments`
37+
38+
Read-Only:
39+
40+
- `authenticate_template_name` (String) Authenticate template name of the port assignment
41+
- `connected_device_type` (String) Connected device type of the port assignment
42+
- `data_vlan_name` (String) Data VLAN name of the port assignment
43+
- `fabric_id` (String) ID of the fabric the device is assigned to
44+
- `interface_description` (String) Interface description of the port assignment
45+
- `interface_name` (String) Interface name of the port assignment
46+
- `network_device_id` (String) Network device ID of the port assignment
47+
- `security_group_name` (String) Security group name of the port assignment
48+
- `voice_vlan_name` (String) Voice VLAN name of the port assignment

docs/guides/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description: |-
1212
- Add `catalystcenter_fabric_vlan_to_ssid` resource and data source
1313
- Add `catalystcenter_wireless_ssid` resource and data source
1414
- Add `catalystcenter_site` data source
15+
- Add `catalystcenter_fabric_port_assignment` resource and data source
1516

1617
## 0.1.10
1718

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "catalystcenter_fabric_port_assignment Resource - terraform-provider-catalystcenter"
4+
subcategory: "SDA"
5+
description: |-
6+
Manages Port Assignments in SD-Access Fabric
7+
---
8+
9+
# catalystcenter_fabric_port_assignment (Resource)
10+
11+
Manages Port Assignments in SD-Access Fabric
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "catalystcenter_fabric_port_assignment" "example" {
17+
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e"
18+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b"
19+
port_assignments = [
20+
{
21+
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f"
22+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
23+
interface_name = "GigabitEthernet1/0/2"
24+
connected_device_type = "USER_DEVICE"
25+
data_vlan_name = "DATA_VLAN"
26+
voice_vlan_name = "VOICE_VLAN"
27+
authenticate_template_name = "No Authentication"
28+
}
29+
]
30+
}
31+
```
32+
33+
<!-- schema generated by tfplugindocs -->
34+
## Schema
35+
36+
### Required
37+
38+
- `network_device_id` (String) Network device ID of the port assignment
39+
- `port_assignments` (Attributes List) List of port assignments in SD-Access fabric (see [below for nested schema](#nestedatt--port_assignments))
40+
41+
### Optional
42+
43+
- `fabric_id` (String) ID of the fabric the device is assigned to
44+
45+
### Read-Only
46+
47+
- `id` (String) The id of the object
48+
49+
<a id="nestedatt--port_assignments"></a>
50+
### Nested Schema for `port_assignments`
51+
52+
Required:
53+
54+
- `connected_device_type` (String) Connected device type of the port assignment
55+
- Choices: `USER_DEVICE`, `ACCESS_POINT`, `TRUNKING_DEVICE`, `AUTHENTICATOR_SWITCH`, `SUPPLICANT_BASED_EXTENDED_NODE`
56+
- `fabric_id` (String) ID of the fabric the device is assigned to
57+
- `interface_name` (String) Interface name of the port assignment
58+
- `network_device_id` (String) Network device ID of the port assignment
59+
60+
Optional:
61+
62+
- `authenticate_template_name` (String) Authenticate template name of the port assignment
63+
- Choices: `No Authentication`, `Open Authentication`, `Closed Authentication`, `Low Impact`
64+
- `data_vlan_name` (String) Data VLAN name of the port assignment
65+
- `interface_description` (String) Interface description of the port assignment
66+
- `security_group_name` (String) Security group name of the port assignment
67+
- `voice_vlan_name` (String) Voice VLAN name of the port assignment
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "catalystcenter_fabric_port_assignment" "example" {
2+
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e"
3+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b"
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "catalystcenter_fabric_port_assignment" "example" {
2+
fabric_id = "e02d9911-b0a7-435b-bb46-079d877d7b3e"
3+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b"
4+
port_assignments = [
5+
{
6+
fabric_id = "c4b85bb2-ce3f-4db9-a32b-e439a388ac2f"
7+
network_device_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
8+
interface_name = "GigabitEthernet1/0/2"
9+
connected_device_type = "USER_DEVICE"
10+
data_vlan_name = "DATA_VLAN"
11+
voice_vlan_name = "VOICE_VLAN"
12+
authenticate_template_name = "No Authentication"
13+
}
14+
]
15+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
name: Fabric Port Assignment
3+
rest_endpoint: /dna/intent/api/v1/sda/portAssignments
4+
res_description: Manages Port Assignments in SD-Access Fabric
5+
no_update: true
6+
no_import: true
7+
data_source_no_id: true
8+
id_from_attribute: true
9+
root_list: true
10+
skip_minimum_test: true
11+
doc_category: SDA
12+
test_tags: [SDA]
13+
attributes:
14+
- tf_name: fabric_id
15+
write_only: true
16+
query_param: true
17+
delete_query_param: true
18+
query_param_name: fabricId
19+
delete_query_param_name: fabricId
20+
type: String
21+
description: ID of the fabric the device is assigned to
22+
example: e02d9911-b0a7-435b-bb46-079d877d7b3e
23+
- tf_name: network_device_id
24+
write_only: true
25+
id: true
26+
query_param: true
27+
delete_query_param: true
28+
query_param_name: networkDeviceId
29+
delete_query_param_name: networkDeviceId
30+
type: String
31+
description: Network device ID of the port assignment
32+
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b
33+
- tf_name: port_assignments
34+
type: List
35+
response_data_path: response
36+
mandatory: true
37+
description: List of port assignments in SD-Access fabric
38+
attributes:
39+
- model_name: fabricId
40+
query_param: true
41+
type: String
42+
mandatory: true
43+
description: ID of the fabric the device is assigned to
44+
example: c4b85bb2-ce3f-4db9-a32b-e439a388ac2f
45+
test_value: catalystcenter_fabric_site.test.id
46+
- model_name: networkDeviceId
47+
match_id: true
48+
query_param: true
49+
mandatory: true
50+
description: Network device ID of the port assignment
51+
type: String
52+
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1
53+
- model_name: interfaceName
54+
query_param: true
55+
mandatory: true
56+
type: String
57+
description: Interface name of the port assignment
58+
example: GigabitEthernet1/0/2
59+
- model_name: connectedDeviceType
60+
mandatory: true
61+
type: String
62+
description: Connected device type of the port assignment
63+
enum_values: [USER_DEVICE, ACCESS_POINT, TRUNKING_DEVICE, AUTHENTICATOR_SWITCH, SUPPLICANT_BASED_EXTENDED_NODE]
64+
example: USER_DEVICE
65+
- model_name: dataVlanName
66+
type: String
67+
description: Data VLAN name of the port assignment
68+
example: DATA_VLAN
69+
- model_name: voiceVlanName
70+
type: String
71+
description: Voice VLAN name of the port assignment
72+
example: VOICE_VLAN
73+
- model_name: authenticateTemplateName
74+
type: String
75+
description: Authenticate template name of the port assignment
76+
enum_values: [No Authentication, Open Authentication, Closed Authentication, Low Impact]
77+
example: No Authentication
78+
- model_name: securityGroupName
79+
type: String
80+
description: Security group name of the port assignment
81+
exclude_test: true
82+
- model_name: interfaceDescription
83+
type: String
84+
description: Interface description of the port assignment
85+
exclude_test: true
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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-log/tflog"
29+
cc "github.com/netascode/go-catalystcenter"
30+
)
31+
32+
// End of section. //template:end imports
33+
34+
// Section below is generated&owned by "gen/generator.go". //template:begin model
35+
36+
// Ensure the implementation satisfies the expected interfaces.
37+
var (
38+
_ datasource.DataSource = &FabricPortAssignmentDataSource{}
39+
_ datasource.DataSourceWithConfigure = &FabricPortAssignmentDataSource{}
40+
)
41+
42+
func NewFabricPortAssignmentDataSource() datasource.DataSource {
43+
return &FabricPortAssignmentDataSource{}
44+
}
45+
46+
type FabricPortAssignmentDataSource struct {
47+
client *cc.Client
48+
}
49+
50+
func (d *FabricPortAssignmentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
51+
resp.TypeName = req.ProviderTypeName + "_fabric_port_assignment"
52+
}
53+
54+
func (d *FabricPortAssignmentDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
55+
resp.Schema = schema.Schema{
56+
// This description is used by the documentation generator and the language server.
57+
MarkdownDescription: "This data source can read the Fabric Port Assignment.",
58+
59+
Attributes: map[string]schema.Attribute{
60+
"id": schema.StringAttribute{
61+
MarkdownDescription: "The id of the object",
62+
Computed: true,
63+
},
64+
"fabric_id": schema.StringAttribute{
65+
MarkdownDescription: "ID of the fabric the device is assigned to",
66+
Required: true,
67+
},
68+
"network_device_id": schema.StringAttribute{
69+
MarkdownDescription: "Network device ID of the port assignment",
70+
Required: true,
71+
},
72+
"port_assignments": schema.ListNestedAttribute{
73+
MarkdownDescription: "List of port assignments in SD-Access fabric",
74+
Computed: true,
75+
NestedObject: schema.NestedAttributeObject{
76+
Attributes: map[string]schema.Attribute{
77+
"fabric_id": schema.StringAttribute{
78+
MarkdownDescription: "ID of the fabric the device is assigned to",
79+
Computed: true,
80+
},
81+
"network_device_id": schema.StringAttribute{
82+
MarkdownDescription: "Network device ID of the port assignment",
83+
Computed: true,
84+
},
85+
"interface_name": schema.StringAttribute{
86+
MarkdownDescription: "Interface name of the port assignment",
87+
Computed: true,
88+
},
89+
"connected_device_type": schema.StringAttribute{
90+
MarkdownDescription: "Connected device type of the port assignment",
91+
Computed: true,
92+
},
93+
"data_vlan_name": schema.StringAttribute{
94+
MarkdownDescription: "Data VLAN name of the port assignment",
95+
Computed: true,
96+
},
97+
"voice_vlan_name": schema.StringAttribute{
98+
MarkdownDescription: "Voice VLAN name of the port assignment",
99+
Computed: true,
100+
},
101+
"authenticate_template_name": schema.StringAttribute{
102+
MarkdownDescription: "Authenticate template name of the port assignment",
103+
Computed: true,
104+
},
105+
"security_group_name": schema.StringAttribute{
106+
MarkdownDescription: "Security group name of the port assignment",
107+
Computed: true,
108+
},
109+
"interface_description": schema.StringAttribute{
110+
MarkdownDescription: "Interface description of the port assignment",
111+
Computed: true,
112+
},
113+
},
114+
},
115+
},
116+
},
117+
}
118+
}
119+
120+
func (d *FabricPortAssignmentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
121+
if req.ProviderData == nil {
122+
return
123+
}
124+
125+
d.client = req.ProviderData.(*CcProviderData).Client
126+
}
127+
128+
// End of section. //template:end model
129+
130+
// Section below is generated&owned by "gen/generator.go". //template:begin read
131+
func (d *FabricPortAssignmentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
132+
var config FabricPortAssignment
133+
134+
// Read config
135+
diags := req.Config.Get(ctx, &config)
136+
resp.Diagnostics.Append(diags...)
137+
if resp.Diagnostics.HasError() {
138+
return
139+
}
140+
141+
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
142+
143+
params := ""
144+
params += "?fabricId=" + url.QueryEscape(config.FabricId.ValueString()) + "&networkDeviceId=" + url.QueryEscape(config.NetworkDeviceId.ValueString())
145+
res, err := d.client.Get(config.getPath() + params)
146+
if err != nil {
147+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
148+
return
149+
}
150+
151+
config.fromBody(ctx, res)
152+
153+
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString()))
154+
155+
diags = resp.State.Set(ctx, &config)
156+
resp.Diagnostics.Append(diags...)
157+
}
158+
159+
// End of section. //template:end read

0 commit comments

Comments
 (0)