Skip to content

Commit

Permalink
add fabric_l2_virtual_network and add device unreachability warning i…
Browse files Browse the repository at this point in the history
…n fabric_l3_handoff_ip_transit
  • Loading branch information
kuba-mazurkiewicz committed Nov 28, 2024
1 parent b6775e3 commit e8aa354
Show file tree
Hide file tree
Showing 19 changed files with 958 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.1.16 (unreleased)

- Add Device Unreachability Warning to `catalystcenter_fabric_l3_handoff_ip_transit` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/150)
- Add `catalystcenter_fabric_l2_virtual_network` resource and data source
- Remove `max_async_wait_time` attribute and use timeout from `CC_MAX_TIMEOUT`
- Modify `catalystcenter_deploy_template` resource to support deploying composite templates
- Modify `catalystcenter_template_version` resource to use versioned template id as `id` and remove data_source
Expand Down
36 changes: 36 additions & 0 deletions docs/data-sources/fabric_l2_virtual_network.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_virtual_network Data Source - terraform-provider-catalystcenter"
subcategory: "SDA"
description: |-
This data source can read the Fabric L2 Virtual Network.
---

# catalystcenter_fabric_l2_virtual_network (Data Source)

This data source can read the Fabric L2 Virtual Network.

## Example Usage

```terraform
data "catalystcenter_fabric_l2_virtual_network" "example" {
fabric_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
vlan_name = "VLAN401"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `fabric_id` (String) ID of the fabric this layer 2 virtual network is to be assigned to
- `vlan_name` (String) Name of the VLAN of the layer 2 virtual network. Must contain only alphanumeric characters, underscores, and hyphens

### Read-Only

- `associated_l3_virtual_network_name` (String) Name of the layer 3 virtual network associated with the layer 2 virtual network. This field is provided to support requests related to virtual network anchoring. The layer 3 virtual network must have already been added to the fabric before association. This field must either be present in all payload elements or none
- `fabric_enabled_wireless` (Boolean) Set to true to enable wireless. Default is false
- `id` (String) The id of the object
- `traffic_type` (String) The type of traffic that is served
- `vlan_id` (Number) ID of the VLAN of the layer 2 virtual network. Allowed VLAN range is 2-4093 except for reserved VLANs 1002-1005, and 2046. If deploying on a fabric zone, this vlanId must match the vlanId of the corresponding layer 2 virtual network on the fabric site
2 changes: 2 additions & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ description: |-

## 0.1.16 (unreleased)

- Add Device Unreachability Warning to `catalystcenter_fabric_l3_handoff_ip_transit` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/150)
- Add `catalystcenter_fabric_l2_virtual_network` resource and data source
- Remove `max_async_wait_time` attribute and use timeout from `CC_MAX_TIMEOUT`
- Modify `catalystcenter_deploy_template` resource to support deploying composite templates
- Modify `catalystcenter_template_version` resource to use versioned template id as `id` and remove data_source
Expand Down
51 changes: 51 additions & 0 deletions docs/resources/fabric_l2_virtual_network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "catalystcenter_fabric_l2_virtual_network Resource - terraform-provider-catalystcenter"
subcategory: "SDA"
description: |-
This resource can manage a Fabric L2 Virtual Network.
---

# catalystcenter_fabric_l2_virtual_network (Resource)

This resource can manage a Fabric L2 Virtual Network.

## Example Usage

```terraform
resource "catalystcenter_fabric_l2_virtual_network" "example" {
fabric_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
vlan_name = "VLAN401"
vlan_id = 401
traffic_type = "DATA"
fabric_enabled_wireless = false
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `fabric_id` (String) ID of the fabric this layer 2 virtual network is to be assigned to
- `traffic_type` (String) The type of traffic that is served
- Choices: `DATA`, `VOICE`
- `vlan_name` (String) Name of the VLAN of the layer 2 virtual network. Must contain only alphanumeric characters, underscores, and hyphens

### Optional

- `associated_l3_virtual_network_name` (String) Name of the layer 3 virtual network associated with the layer 2 virtual network. This field is provided to support requests related to virtual network anchoring. The layer 3 virtual network must have already been added to the fabric before association. This field must either be present in all payload elements or none
- `fabric_enabled_wireless` (Boolean) Set to true to enable wireless. Default is false
- `vlan_id` (Number) ID of the VLAN of the layer 2 virtual network. Allowed VLAN range is 2-4093 except for reserved VLANs 1002-1005, and 2046. If deploying on a fabric zone, this vlanId must match the vlanId of the corresponding layer 2 virtual network on the fabric site

### Read-Only

- `id` (String) The id of the object

## Import

Import is supported using the following syntax:

```shell
terraform import catalystcenter_fabric_l2_virtual_network.example "<fabric_id>,<vlan_name>"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "catalystcenter_fabric_l2_virtual_network" "example" {
fabric_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
vlan_name = "VLAN401"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import catalystcenter_fabric_l2_virtual_network.example "<fabric_id>,<vlan_name>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "catalystcenter_fabric_l2_virtual_network" "example" {
fabric_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
vlan_name = "VLAN401"
vlan_id = 401
traffic_type = "DATA"
fabric_enabled_wireless = false
}
2 changes: 0 additions & 2 deletions gen/definitions/anycast_gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ test_prerequisites: |
resource "catalystcenter_area" "test" {
name = "Area1"
parent_name = "Global"
depends_on = [catalystcenter_ip_pool.test]
}
resource "catalystcenter_ip_pool" "test" {
name = "MyPool1"
Expand All @@ -166,7 +165,6 @@ test_prerequisites: |
site_id = catalystcenter_area.test.id
pub_sub_enabled = false
authentication_profile_name = "No Authentication"
depends_on = [catalystcenter_area.test]
}
resource "catalystcenter_fabric_virtual_network" "test" {
virtual_network_name = "SDA_VN1"
Expand Down
72 changes: 72 additions & 0 deletions gen/definitions/fabric_l2_virtual_network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
name: Fabric L2 Virtual Network
rest_endpoint: /dna/intent/api/v1/sda/layer2VirtualNetworks
id_from_query_path: response.0
id_from_query_path_attribute: id
import_no_id: true
data_source_no_id: true
skip_minimum_test: true
put_id_include_path: "0.id"
put_no_id: true
doc_category: SDA
attributes:
- model_name: fabricId
requires_replace: true
data_path: '0'
query_param: true
response_data_path: response.0.fabricId
mandatory: true
description: ID of the fabric this layer 2 virtual network is to be assigned to
type: String
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1
test_value: catalystcenter_fabric_site.test.id
- model_name: vlanName
requires_replace: true
data_path: '0'
query_param: true
response_data_path: response.0.vlanName
type: String
mandatory: true
description: Name of the VLAN of the layer 2 virtual network. Must contain only alphanumeric characters, underscores, and hyphens
example: VLAN401
- model_name: vlanId
requires_replace: true
data_path: '0'
response_data_path: response.0.vlanId
type: Int64
description: ID of the VLAN of the layer 2 virtual network. Allowed VLAN range is 2-4093 except for reserved VLANs 1002-1005, and 2046. If deploying on a fabric zone, this vlanId must match the vlanId of the corresponding layer 2 virtual network on the fabric site
example: 401
- model_name: trafficType
data_path: '0'
response_data_path: response.0.trafficType
type: String
enum_values: [DATA, VOICE]
mandatory: true
description: The type of traffic that is served
example: DATA
- model_name: isFabricEnabledWireless
data_path: '0'
response_data_path: response.0.isFabricEnabledWireless
tf_name: fabric_enabled_wireless
type: Bool
description: Set to true to enable wireless. Default is false
example: false
- model_name: associatedLayer3VirtualNetworkName
requires_replace: true
data_path: '0'
response_data_path: response.0.associatedLayer3VirtualNetworkName
tf_name: associated_l3_virtual_network_name
type: String
description: Name of the layer 3 virtual network associated with the layer 2 virtual network. This field is provided to support requests related to virtual network anchoring. The layer 3 virtual network must have already been added to the fabric before association. This field must either be present in all payload elements or none
example: SDA_VN1
exclude_test: true
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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const testAccDataSourceCcAnycastGatewayPrerequisitesConfig = `
resource "catalystcenter_area" "test" {
name = "Area1"
parent_name = "Global"
depends_on = [catalystcenter_ip_pool.test]
}
resource "catalystcenter_ip_pool" "test" {
name = "MyPool1"
Expand All @@ -78,7 +77,6 @@ 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]
}
resource "catalystcenter_fabric_virtual_network" "test" {
virtual_network_name = "SDA_VN1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// 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 = &FabricL2VirtualNetworkDataSource{}
_ datasource.DataSourceWithConfigure = &FabricL2VirtualNetworkDataSource{}
)

func NewFabricL2VirtualNetworkDataSource() datasource.DataSource {
return &FabricL2VirtualNetworkDataSource{}
}

type FabricL2VirtualNetworkDataSource struct {
client *cc.Client
}

func (d *FabricL2VirtualNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_fabric_l2_virtual_network"
}

func (d *FabricL2VirtualNetworkDataSource) 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 Virtual Network.",

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 this layer 2 virtual network is to be assigned to",
Required: true,
},
"vlan_name": schema.StringAttribute{
MarkdownDescription: "Name of the VLAN of the layer 2 virtual network. Must contain only alphanumeric characters, underscores, and hyphens",
Required: true,
},
"vlan_id": schema.Int64Attribute{
MarkdownDescription: "ID of the VLAN of the layer 2 virtual network. Allowed VLAN range is 2-4093 except for reserved VLANs 1002-1005, and 2046. If deploying on a fabric zone, this vlanId must match the vlanId of the corresponding layer 2 virtual network on the fabric site",
Computed: true,
},
"traffic_type": schema.StringAttribute{
MarkdownDescription: "The type of traffic that is served",
Computed: true,
},
"fabric_enabled_wireless": schema.BoolAttribute{
MarkdownDescription: "Set to true to enable wireless. Default is false",
Computed: true,
},
"associated_l3_virtual_network_name": schema.StringAttribute{
MarkdownDescription: "Name of the layer 3 virtual network associated with the layer 2 virtual network. This field is provided to support requests related to virtual network anchoring. The layer 3 virtual network must have already been added to the fabric before association. This field must either be present in all payload elements or none",
Computed: true,
},
},
}
}

func (d *FabricL2VirtualNetworkDataSource) 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 *FabricL2VirtualNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config FabricL2VirtualNetwork

// 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()) + "&vlanName=" + url.QueryEscape(config.VlanName.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
Loading

0 comments on commit e8aa354

Please sign in to comment.