Skip to content

Commit

Permalink
Add network vlan profile assignments by device data source
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Nov 5, 2024
1 parent df9ea77 commit d21fe6e
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Add `meraki_organization_firmware_upgrades` data source
- Add `meraki_organization_inventory_devices` data source
- Add `meraki_network_policies_by_client` data source
- Add `meraki_network_vlan_profile_assignments_by_device` data source

## 0.1.2

Expand Down
45 changes: 45 additions & 0 deletions docs/data-sources/network_vlan_profile_assignments_by_device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_network_vlan_profile_assignments_by_device Data Source - terraform-provider-meraki"
subcategory: ""
description: |-
This data source can read the Network VLAN Profile Assignments By Device configuration.
---

# meraki_network_vlan_profile_assignments_by_device (Data Source)

This data source can read the `Network VLAN Profile Assignments By Device` configuration.

## Example Usage

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

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

### Required

- `network_id` (String) Network ID

### Read-Only

- `items` (Attributes List) The list of items (see [below for nested schema](#nestedatt--items))

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

Read-Only:

- `id` (String) The id of the object
- `mac` (String) MAC address of the device
- `name` (String) Name of the Device
- `product_type` (String) The product type
- `serial` (String) Serial of the Device
- `stack_id` (String) ID of the Switch Stack
- `vlan_profile_iname` (String) IName of the VLAN Profile
- `vlan_profile_is_default` (Boolean) Is this VLAN profile the default for the network?
- `vlan_profile_name` (String) Name of the VLAN Profile
3 changes: 2 additions & 1 deletion docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ description: |-
- Add `meraki_organization_devices` data source
- Add `meraki_organization_firmware_upgrades` data source
- Add `meraki_organization_inventory_devices` data source
- Add `meraki_network_pii_keys` data source
- Add `meraki_network_policies_by_client` data source
- Add `meraki_network_vlan_profile_assignments_by_device` data source

## 0.1.2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "meraki_network_vlan_profile_assignments_by_device" "example" {
network_id = "L_123456"
}
65 changes: 65 additions & 0 deletions gen/definitions/network_vlan_profile_assignments_by_device.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Network VLAN Profile Assignments By Device
bulk_name: Network VLAN Profile Assignments By Device
spec_endpoint: /networks/{networkId}/vlanProfiles/assignments/byDevice
rest_endpoint: /networks/%v/vlanProfiles/assignments/byDevice
no_data_source: true
no_resource: true
bulk_data_source: true
no_update: true
no_delete: true
data_source_name_query: true
doc_category: Networks
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: mac
type: String
description: MAC address of the device
example: "00:11:22:33:44:55"
- model_name: name
type: String
description: Name of the Device
example: My switch
- model_name: productType
type: String
description: The product type
example: switch
- model_name: serial
type: String
description: Serial of the Device
example: Q234-ABCD-5678
- model_name: id
type: String
data_path: [stack]
description: ID of the Switch Stack
example: "1234"
- model_name: iname
type: String
data_path: [vlanProfile]
description: IName of the VLAN Profile
example: Profile1
- model_name: isDefault
type: Bool
data_path: [vlanProfile]
description: Is this VLAN profile the default for the network?
example: "true"
- model_name: name
type: String
data_path: [vlanProfile]
description: Name of the VLAN Profile
example: My VLAN Profile
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", "appliance"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// 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/CiscoDevNet/terraform-provider-meraki/internal/provider/helpers"
"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"
)

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

func NewNetworkVLANProfileAssignmentsByDeviceDataSource() datasource.DataSource {
return &NetworkVLANProfileAssignmentsByDeviceDataSource{}
}

type NetworkVLANProfileAssignmentsByDeviceDataSource struct {
client *meraki.Client
}

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

func (d *NetworkVLANProfileAssignmentsByDeviceDataSource) 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: helpers.NewAttributeDescription("This data source can read the `Network VLAN Profile Assignments By Device` configuration.").String,

Attributes: map[string]schema.Attribute{
"network_id": schema.StringAttribute{
MarkdownDescription: "Network ID",
Required: true,
},
"items": schema.ListNestedAttribute{
MarkdownDescription: "The list of items",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The id of the object",
Computed: true,
},
"mac": schema.StringAttribute{
MarkdownDescription: "MAC address of the device",
Computed: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "Name of the Device",
Computed: true,
},
"product_type": schema.StringAttribute{
MarkdownDescription: "The product type",
Computed: true,
},
"serial": schema.StringAttribute{
MarkdownDescription: "Serial of the Device",
Computed: true,
},
"stack_id": schema.StringAttribute{
MarkdownDescription: "ID of the Switch Stack",
Computed: true,
},
"vlan_profile_iname": schema.StringAttribute{
MarkdownDescription: "IName of the VLAN Profile",
Computed: true,
},
"vlan_profile_is_default": schema.BoolAttribute{
MarkdownDescription: "Is this VLAN profile the default for the network?",
Computed: true,
},
"vlan_profile_name": schema.StringAttribute{
MarkdownDescription: "Name of the VLAN Profile",
Computed: true,
},
},
},
},
},
}
}

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

// 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", "NetworkVLANProfileAssignmentsByDeviceDataSource"))

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)

tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", "NetworkVLANProfileAssignmentsByDeviceDataSource"))

diags = resp.State.Set(ctx, &config)
resp.Diagnostics.Append(diags...)
}

// End of section. //template:end read
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

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

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

func TestAccDataSourceMerakiNetworkVLANProfileAssignmentsByDevice(t *testing.T) {
if os.Getenv("TF_VAR_test_org") == "" || os.Getenv("TF_VAR_test_network") == "" {
t.Skip("skipping test, set environment variable TF_VAR_test_org and TF_VAR_test_network")
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDevicePrerequisitesConfig + testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDeviceConfig(),
},
},
})
}

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

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

const testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDevicePrerequisitesConfig = `
variable "test_org" {}
variable "test_network" {}
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", "appliance"]
}
`

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

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

func testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDeviceConfig() string {
config := `data "meraki_network_vlan_profile_assignments_by_device" "test" {
network_id = meraki_network.test.id
}
`
return config
}

// End of section. //template:end testAccDataSourceConfig
Loading

0 comments on commit d21fe6e

Please sign in to comment.