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

Wireless settings: data source + resource #11

Merged
merged 9 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions docs/data-sources/wireless_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_wireless_settings Data Source - terraform-provider-meraki"
subcategory: "Wireless"
description: |-
This data source can read the Wireless settings configuration.
---

# meraki_wireless_settings (Data Source)

This data source can read the `Wireless settings` configuration.

## Example Usage

```terraform
data "meraki_wireless_settings" "example" {
network_id = "L_123456"
}
```

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

### Required

- `network_id` (String) Network ID

### Read-Only

- `id` (String) The id of the object
- `ipv6_bridge_enabled` (Boolean) Toggle for enabling or disabling IPv6 bridging in a network (Note: if enabled, SSIDs must also be configured to use bridge mode)
- `led_lights_on` (Boolean) Toggle for enabling or disabling LED lights on all APs in the network (making them run dark)
- `location_analytics_enabled` (Boolean) Toggle for enabling or disabling location analytics for your network
- `meshing_enabled` (Boolean) Toggle for enabling or disabling meshing in a network
- `named_vlans_pool_dhcp_monitoring_duration` (Number) The duration in minutes that devices will refrain from using dirty VLANs before adding them back to the pool.
- `named_vlans_pool_dhcp_monitoring_enabled` (Boolean) Whether or not devices using named VLAN pools should remove dirty VLANs from the pool, thereby preventing clients from being assigned to VLANs where they would be unable to obtain an IP address via DHCP.
- `upgrade_strategy` (String) The default strategy that network devices will use to perform an upgrade. Requires firmware version MR 26.8 or higher.
56 changes: 56 additions & 0 deletions docs/resources/wireless_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_wireless_settings Resource - terraform-provider-meraki"
subcategory: "Wireless"
description: |-
This resource can manage the Wireless settings configuration.
---

# meraki_wireless_settings (Resource)

This resource can manage the `Wireless settings` configuration.

## Example Usage

```terraform
resource "meraki_wireless_settings" "example" {
network_id = "L_123456"
ipv6_bridge_enabled = true
led_lights_on = true
location_analytics_enabled = false
meshing_enabled = true
upgrade_strategy = "minimizeUpgradeTime"
named_vlans_pool_dhcp_monitoring_duration = 5
named_vlans_pool_dhcp_monitoring_enabled = false
}
```

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

### Required

- `network_id` (String) Network ID

### Optional

- `ipv6_bridge_enabled` (Boolean) Toggle for enabling or disabling IPv6 bridging in a network (Note: if enabled, SSIDs must also be configured to use bridge mode)
- `led_lights_on` (Boolean) Toggle for enabling or disabling LED lights on all APs in the network (making them run dark)
- `location_analytics_enabled` (Boolean) Toggle for enabling or disabling location analytics for your network
- `meshing_enabled` (Boolean) Toggle for enabling or disabling meshing in a network
- `named_vlans_pool_dhcp_monitoring_duration` (Number) The duration in minutes that devices will refrain from using dirty VLANs before adding them back to the pool.
- `named_vlans_pool_dhcp_monitoring_enabled` (Boolean) Whether or not devices using named VLAN pools should remove dirty VLANs from the pool, thereby preventing clients from being assigned to VLANs where they would be unable to obtain an IP address via DHCP.
- `upgrade_strategy` (String) The default strategy that network devices will use to perform an upgrade. Requires firmware version MR 26.8 or higher.
- Choices: `minimizeClientDowntime`, `minimizeUpgradeTime`

### Read-Only

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

## Import

Import is supported using the following syntax:

```shell
terraform import meraki_wireless_settings.example "<network_id>"
```
3 changes: 3 additions & 0 deletions examples/data-sources/meraki_wireless_settings/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "meraki_wireless_settings" "example" {
network_id = "L_123456"
}
1 change: 1 addition & 0 deletions examples/resources/meraki_wireless_settings/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import meraki_wireless_settings.example "<network_id>"
10 changes: 10 additions & 0 deletions examples/resources/meraki_wireless_settings/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "meraki_wireless_settings" "example" {
network_id = "L_123456"
ipv6_bridge_enabled = true
led_lights_on = true
location_analytics_enabled = false
meshing_enabled = true
upgrade_strategy = "minimizeUpgradeTime"
named_vlans_pool_dhcp_monitoring_duration = 5
named_vlans_pool_dhcp_monitoring_enabled = false
}
56 changes: 56 additions & 0 deletions gen/definitions/wireless_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# @endpoint: /networks/{networkId}/wireless/settings
name: Wireless settings
rest_endpoint: /networks/%v/wireless/settings
put_create: true
no_delete: true
doc_category: Wireless
test_variables: [test_org, test_network]
attributes:
- tf_name: network_id
type: String
id: true
reference: true
description: Network ID
example: L_123456
test_value: meraki_network.test.id
- model_name: ipv6BridgeEnabled
type: Bool
description: 'Toggle for enabling or disabling IPv6 bridging in a network (Note: if enabled, SSIDs must also be configured to use bridge mode)'
example: "true"
minimum_test_value: "true"
- model_name: ledLightsOn
type: Bool
description: Toggle for enabling or disabling LED lights on all APs in the network (making them run dark)
example: "true"
- model_name: locationAnalyticsEnabled
type: Bool
description: Toggle for enabling or disabling location analytics for your network
example: "false"
- model_name: meshingEnabled
type: Bool
description: Toggle for enabling or disabling meshing in a network
example: "true"
- model_name: upgradeStrategy
type: String
description: The default strategy that network devices will use to perform an upgrade. Requires firmware version MR 26.8 or higher.
example: minimizeUpgradeTime
enum_values: [minimizeClientDowntime, minimizeUpgradeTime]
- model_name: duration
type: Int64
data_path: [namedVlans, poolDhcpMonitoring]
description: The duration in minutes that devices will refrain from using dirty VLANs before adding them back to the pool.
example: "5"
- model_name: enabled
type: Bool
data_path: [namedVlans, poolDhcpMonitoring]
description: Whether or not devices using named VLAN pools should remove dirty VLANs from the pool, thereby preventing clients from being assigned to VLANs where they would be unable to obtain an IP address via DHCP.
example: "false"
test_prerequisites: |
data "meraki_organization" "test" {
name = var.test_org
}
resource "meraki_network" "test" {
organization_id = data.meraki_organization.test.id
name = var.test_network
product_types = ["switch", "wireless"]
}
144 changes: 144 additions & 0 deletions internal/provider/data_source_meraki_wireless_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright © 2024 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"
"github.com/netascode/go-meraki"
"github.com/tidwall/gjson"
)

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

func NewWirelessSettingsDataSource() datasource.DataSource {
return &WirelessSettingsDataSource{}
}

type WirelessSettingsDataSource struct {
client *meraki.Client
}

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

func (d *WirelessSettingsDataSource) 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 settings` configuration.",

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The id of the object",
Computed: true,
},
"network_id": schema.StringAttribute{
MarkdownDescription: "Network ID",
Required: true,
},
"ipv6_bridge_enabled": schema.BoolAttribute{
MarkdownDescription: "Toggle for enabling or disabling IPv6 bridging in a network (Note: if enabled, SSIDs must also be configured to use bridge mode)",
Computed: true,
},
"led_lights_on": schema.BoolAttribute{
MarkdownDescription: "Toggle for enabling or disabling LED lights on all APs in the network (making them run dark)",
Computed: true,
},
"location_analytics_enabled": schema.BoolAttribute{
MarkdownDescription: "Toggle for enabling or disabling location analytics for your network",
Computed: true,
},
"meshing_enabled": schema.BoolAttribute{
MarkdownDescription: "Toggle for enabling or disabling meshing in a network",
Computed: true,
},
"upgrade_strategy": schema.StringAttribute{
MarkdownDescription: "The default strategy that network devices will use to perform an upgrade. Requires firmware version MR 26.8 or higher.",
Computed: true,
},
"named_vlans_pool_dhcp_monitoring_duration": schema.Int64Attribute{
MarkdownDescription: "The duration in minutes that devices will refrain from using dirty VLANs before adding them back to the pool.",
Computed: true,
},
"named_vlans_pool_dhcp_monitoring_enabled": schema.BoolAttribute{
MarkdownDescription: "Whether or not devices using named VLAN pools should remove dirty VLANs from the pool, thereby preventing clients from being assigned to VLANs where they would be unable to obtain an IP address via DHCP.",
Computed: true,
},
},
}
}

func (d *WirelessSettingsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

d.client = req.ProviderData.(*MerakiProviderData).Client
}

// End of section. //template:end model

// Section below is generated&owned by "gen/generator.go". //template:begin read

func (d *WirelessSettingsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config WirelessSettings

// 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()))

var res gjson.Result
var err error

if !res.Exists() {
res, err = d.client.Get(config.getPath())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
return
}
}

config.fromBody(ctx, res)
config.Id = config.NetworkId

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