Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabric l2 handoff #112

Merged
merged 39 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c95fc8e
added GenerateQueryParamString templating helper function
kuba-mazurkiewicz Jul 19, 2024
b853a94
use create_query_path instead of query_param in Create and Update fun…
kuba-mazurkiewicz Jul 19, 2024
d0e2c6f
add query_param_no_body and data_source_no_id attributes
kuba-mazurkiewicz Jul 20, 2024
c1381fd
add import_no_id attribute, if import does not require and ID
kuba-mazurkiewicz Jul 20, 2024
a98ad26
add anycast_gateway
kuba-mazurkiewicz Jul 20, 2024
5545db0
update changelog
kuba-mazurkiewicz Jul 20, 2024
9c69bd5
add transitPeerNetworkId as id to transit_peer_network resource
kuba-mazurkiewicz Jul 20, 2024
c70bd2a
updated changelog
kuba-mazurkiewicz Jul 20, 2024
38d93bf
add fabric_l3_handoff_ip_transit resource and data source
kuba-mazurkiewicz Jul 21, 2024
59173f3
add fabric_device resource and data source
kuba-mazurkiewicz Jul 21, 2024
522d49c
pnp bulk import
kuba-mazurkiewicz Jul 22, 2024
30854ad
update changelog
kuba-mazurkiewicz Jul 22, 2024
9a6533c
rename pnp_device_import to pnp_import_devices
kuba-mazurkiewicz Jul 24, 2024
35565f0
add tag and assign_templates_to_tag
kuba-mazurkiewicz Jul 26, 2024
241fe0a
changed template_ids from List to Set
kuba-mazurkiewicz Jul 26, 2024
2db5bce
update changelog
kuba-mazurkiewicz Jul 26, 2024
b10aeaa
add fabric_provision_device resource and data source
kuba-mazurkiewicz Jul 30, 2024
f478bfb
modified max_async_wait_time in fabric_device resource
kuba-mazurkiewicz Jul 31, 2024
25435ac
modified max_async_wait_time in fabric_provision_device resource
kuba-mazurkiewicz Jul 31, 2024
01fefd8
add wireless_device_provision, add additional params in enterprise_ss…
kuba-mazurkiewicz Aug 1, 2024
4906ccb
update changelog
kuba-mazurkiewicz Aug 1, 2024
9f31f09
Merge branch 'main' into tags_to_template
kuba-mazurkiewicz Aug 5, 2024
df90953
update changelog
kuba-mazurkiewicz Aug 5, 2024
c8291fd
modified res_description
kuba-mazurkiewicz Aug 5, 2024
7252a29
Merge branch 'tags_to_template' into provision_sda
kuba-mazurkiewicz Aug 5, 2024
efa562b
Merge branch 'provision_sda' into fix_provision_borders
kuba-mazurkiewicz Aug 5, 2024
9a02a97
fix data source test for resources with data_source_no_id: true
kuba-mazurkiewicz Aug 5, 2024
7b1404d
fix confilcts
kuba-mazurkiewicz Aug 5, 2024
efb6157
update changelog
kuba-mazurkiewicz Aug 5, 2024
a7d936f
fix typo in virtualNetworkName description in fabric_l3_handoff_ip_tr…
kuba-mazurkiewicz Aug 5, 2024
d3c42c2
modified wireless_profile to use new endpoint /intent/api/v1/wireless…
kuba-mazurkiewicz Aug 6, 2024
ce879d8
add test tag CC2376 to wireles_profile resource
kuba-mazurkiewicz Aug 6, 2024
f74ce30
update changelog
kuba-mazurkiewicz Aug 6, 2024
686672a
added fabric_l2_handoff
kuba-mazurkiewicz Aug 7, 2024
7d3ba2f
removed test tag from wireless_profile
kuba-mazurkiewicz Aug 7, 2024
4496a67
removed ghz24_policy from test prerequisites
kuba-mazurkiewicz Aug 7, 2024
bab2f21
Merge branch 'wireless_profile2' into fabric_l2_handoff
kuba-mazurkiewicz Aug 7, 2024
78b89fb
update changelog
kuba-mazurkiewicz Aug 7, 2024
d733a22
modified changelog
kuba-mazurkiewicz Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.1.10 (unreleased)

- Add `fabric_l2_handoff` resource and data source
- BREAKING CHANGE: Modified `wireless_profile` resource to use `/intent/api/v1/wirelessProfiles` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+
- Add `wireless_device_provision` resource
- Add `fabric_provision_device` resource and data source
Expand Down
36 changes: 36 additions & 0 deletions docs/data-sources/fabric_l2_handoff.md
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)
1 change: 1 addition & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description: |-

## 0.1.10 (unreleased)

- Add `fabric_l2_handoff` resource and data source
- BREAKING CHANGE: Modified `wireless_profile` resource to use `/intent/api/v1/wirelessProfiles` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+
- Add `wireless_device_provision` resource
- Add `fabric_provision_device` resource and data source
Expand Down
46 changes: 46 additions & 0 deletions docs/resources/fabric_l2_handoff.md
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>"
```
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"
}
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>"
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
}
67 changes: 67 additions & 0 deletions gen/definitions/fabric_l2_handoff.yaml
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]
}
2 changes: 1 addition & 1 deletion gen/templates/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C
{{- if and .IdFromQueryPathAttribute .IdFromQueryPath (not .GetExtraQueryParams) (not .GetFromAll) }}
plan.Id = types.StringValue(res.Get("{{if eq .IdFromQueryPath "." }}{{else}}{{.IdFromQueryPath}}.{{end}}{{.IdFromQueryPathAttribute}}").String())
{{- else}}
plan.Id = types.StringValue(res.Get("{{.IdFromQueryPath}}.#({{if $id.ResponseModelName}}{{$id.ResponseModelName}}{{else}}{{$id.ModelName}}{{end}}==\""+ plan.{{toGoName $id.TfName}}.Value{{$id.Type}}() +"\").{{if .IdFromQueryPathAttribute}}{{.IdFromQueryPathAttribute}}{{else}}id{{end}}").String())
plan.Id = types.StringValue(res.Get("{{.IdFromQueryPath}}.#({{if $id.ResponseModelName}}{{$id.ResponseModelName}}{{else}}{{$id.ModelName}}{{end}}==\""+ {{if eq $id.Type "Int64"}}strconv.FormatInt(plan.{{toGoName $id.TfName}}.ValueInt64(), 10){{else}}plan.{{toGoName $id.TfName}}.Value{{$id.Type}}(){{end}} +"\").{{if .IdFromQueryPathAttribute}}{{.IdFromQueryPathAttribute}}{{else}}id{{end}}").String())
{{- end}}
{{- /* If we have an id attribute we will use that as id */}}
{{- else if hasId .Attributes}}
Expand Down
128 changes: 128 additions & 0 deletions internal/provider/data_source_catalystcenter_fabric_l2_handoff.go
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
Loading