Skip to content

Commit

Permalink
Update wireless profile api endpoint (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-mazurkiewicz authored Aug 8, 2024
1 parent ec8fd51 commit bcb13be
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 82 deletions.
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)

- 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
- Add `assign_templates_to_tag` resource and data source
Expand Down
44 changes: 44 additions & 0 deletions docs/data-sources/wireless_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "catalystcenter_wireless_profile Data Source - terraform-provider-catalystcenter"
subcategory: "Wireless"
description: |-
This data source can read the Wireless Profile.
---

# catalystcenter_wireless_profile (Data Source)

This data source can read the Wireless Profile.

## Example Usage

```terraform
data "catalystcenter_wireless_profile" "example" {
id = "76d24097-41c4-4558-a4d0-a8c07ac08470"
}
```

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

### Required

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

### Read-Only

- `ssid_details` (Attributes List) SSID Details (see [below for nested schema](#nestedatt--ssid_details))
- `wireless_profile_name` (String) Wireless Network Profile Name

<a id="nestedatt--ssid_details"></a>
### Nested Schema for `ssid_details`

Read-Only:

- `dot11be_profile_id` (String) 802.11be Profile Id. Applicable to IOS controllers with version 17.15 and higher. 802.11be Profiles if passed, should be same across all SSIDs in network profile being configured
- `enable_fabric` (Boolean) True if fabric is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time
- `enable_flex_connect` (Boolean) True if flex connect is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time
- `interface_name` (String) Interface Name
- `local_to_vlan` (Number) Local To Vlan Id
- `ssid_name` (String) SSID Name
- `wlan_profile_name` (String) WLAN Profile Name
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)

- 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
- Add `assign_templates_to_tag` resource and data source
Expand Down
17 changes: 9 additions & 8 deletions docs/resources/wireless_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ This resource creates a wireless network profile. To associate a wireless networ

```terraform
resource "catalystcenter_wireless_profile" "example" {
name = "Wireless_Profile_1"
wireless_profile_name = "Wireless_Profile_1"
ssid_details = [
{
name = "mySSID1"
ssid_name = "mySSID1"
enable_fabric = true
enable_flex_connect = false
}
Expand All @@ -30,7 +30,7 @@ resource "catalystcenter_wireless_profile" "example" {

### Required

- `name` (String) Profile Name
- `wireless_profile_name` (String) Wireless Network Profile Name

### Optional

Expand All @@ -45,21 +45,22 @@ resource "catalystcenter_wireless_profile" "example" {

Required:

- `name` (String) Ssid Name
- `ssid_name` (String) SSID Name

Optional:

- `enable_fabric` (Boolean) `true` if ssid is fabric else `false`
- `enable_flex_connect` (Boolean) `true` if flex connect is enabled else `false`
- `dot11be_profile_id` (String) 802.11be Profile Id. Applicable to IOS controllers with version 17.15 and higher. 802.11be Profiles if passed, should be same across all SSIDs in network profile being configured
- `enable_fabric` (Boolean) True if fabric is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time
- `enable_flex_connect` (Boolean) True if flex connect is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time
- `interface_name` (String) Interface Name
- Default value: `management`
- `local_to_vlan` (Number) Local To Vlan Id
- `policy_profile_name` (String) Policy Profile Name
- `wlan_profile_name` (String) WLAN Profile Name

## Import

Import is supported using the following syntax:

```shell
terraform import catalystcenter_wireless_profile.example "<id>"
terraform import catalystcenter_wireless_profile.example "4b0b7a80-44c0-4bf2-bab5-fc24b4e0a17e"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "catalystcenter_wireless_profile" "example" {
id = "76d24097-41c4-4558-a4d0-a8c07ac08470"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import catalystcenter_wireless_profile.example "<id>"
terraform import catalystcenter_wireless_profile.example "4b0b7a80-44c0-4bf2-bab5-fc24b4e0a17e"
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resource "catalystcenter_wireless_profile" "example" {
name = "Wireless_Profile_1"
wireless_profile_name = "Wireless_Profile_1"
ssid_details = [
{
name = "mySSID1"
ssid_name = "mySSID1"
enable_fabric = true
enable_flex_connect = false
}
Expand Down
27 changes: 10 additions & 17 deletions gen/definitions/wireless_profile.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
---
name: Wireless Profile
rest_endpoint: /dna/intent/api/v2/wireless/profile
rest_endpoint: /intent/api/v1/wirelessProfiles
id_from_query_path: response
id_from_query_path_attribute: id
import_no_id: true
get_from_all: true
no_data_source: true
put_no_id: true
id_from_query_path_attribute: instanceUuid
res_description:
'This resource creates a wireless network profile. To associate a wireless network profile with a site, use
the `catalystcenter_associate_site_to_network_profile` resource.'
doc_category: Wireless
attributes:
- model_name: wirelessProfileName
tf_name: name
delete_query_param_name: name
delete_query_param: true
type: String
match_id: true
description: Profile Name
description: Wireless Network Profile Name
example: Wireless_Profile_1
- model_name: ssidDetails
type: List
description: SSID Details
attributes:
- model_name: ssidName
tf_name: name
type: String
id: true
description: Ssid Name
description: SSID Name
example: mySSID1
test_value: catalystcenter_wireless_enterprise_ssid.test.name
- model_name: enableFabric
type: Bool
description: "`true` if ssid is fabric else `false`"
description: "True if fabric is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time"
example: true
- model_name: enableFlexConnect
data_path: flexConnect
type: Bool
description: "`true` if flex connect is enabled else `false`"
description: "True if flex connect is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time"
example: false
- model_name: localToVlan
data_path: flexConnect
Expand All @@ -49,19 +44,17 @@ attributes:
type: String
description: Interface Name
exclude_test: true
default_value: management
example: management
- model_name: wlanProfileName
write_only: true
type: String
description: WLAN Profile Name
exclude_test: true
example: mySSID1_profile
- model_name: policyProfileName
write_only: true
- model_name: dot11beProfileId
type: String
description: Policy Profile Name
description: 802.11be Profile Id. Applicable to IOS controllers with version 17.15 and higher. 802.11be Profiles if passed, should be same across all SSIDs in network profile being configured
exclude_test: true
example: mySSID1_profile
test_prerequisites: |
resource "catalystcenter_wireless_enterprise_ssid" "test" {
name = "mySSID1"
Expand Down
146 changes: 146 additions & 0 deletions internal/provider/data_source_catalystcenter_wireless_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// 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"

"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 = &WirelessProfileDataSource{}
_ datasource.DataSourceWithConfigure = &WirelessProfileDataSource{}
)

func NewWirelessProfileDataSource() datasource.DataSource {
return &WirelessProfileDataSource{}
}

type WirelessProfileDataSource struct {
client *cc.Client
}

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

func (d *WirelessProfileDataSource) 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 Wireless Profile.",

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The id of the object",
Required: true,
},
"wireless_profile_name": schema.StringAttribute{
MarkdownDescription: "Wireless Network Profile Name",
Computed: true,
},
"ssid_details": schema.ListNestedAttribute{
MarkdownDescription: "SSID Details",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"ssid_name": schema.StringAttribute{
MarkdownDescription: "SSID Name",
Computed: true,
},
"enable_fabric": schema.BoolAttribute{
MarkdownDescription: "True if fabric is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time",
Computed: true,
},
"enable_flex_connect": schema.BoolAttribute{
MarkdownDescription: "True if flex connect is enabled, else False. Flex and fabric cannot be enabled simultaneously and a profile can only contain either flex SSIDs or fabric SSIDs and not both at the same time",
Computed: true,
},
"local_to_vlan": schema.Int64Attribute{
MarkdownDescription: "Local To Vlan Id",
Computed: true,
},
"interface_name": schema.StringAttribute{
MarkdownDescription: "Interface Name",
Computed: true,
},
"wlan_profile_name": schema.StringAttribute{
MarkdownDescription: "WLAN Profile Name",
Computed: true,
},
"dot11be_profile_id": schema.StringAttribute{
MarkdownDescription: "802.11be Profile Id. Applicable to IOS controllers with version 17.15 and higher. 802.11be Profiles if passed, should be same across all SSIDs in network profile being configured",
Computed: true,
},
},
},
},
},
}
}

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

// 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 := ""
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

0 comments on commit bcb13be

Please sign in to comment.