-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add organization devices data source
- Loading branch information
Showing
10 changed files
with
600 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "meraki_organization_devices Data Source - terraform-provider-meraki" | ||
subcategory: "" | ||
description: |- | ||
This data source can read the Organization Devices configuration. | ||
--- | ||
|
||
# meraki_organization_devices (Data Source) | ||
|
||
This data source can read the `Organization Devices` configuration. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "meraki_organization_devices" "example" { | ||
organization_id = "123456" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `organization_id` (String) Organization 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: | ||
|
||
- `address` (String) Physical address of the device | ||
- `details` (Attributes List) Additional device information (see [below for nested schema](#nestedatt--items--details)) | ||
- `firmware` (String) Firmware version of the device | ||
- `id` (String) The id of the object | ||
- `imei` (String) IMEI of the device, if applicable | ||
- `lan_ip` (String) LAN IP address of the device | ||
- `lat` (Number) Latitude of the device | ||
- `lng` (Number) Longitude of the device | ||
- `mac` (String) MAC address of the device | ||
- `model` (String) Model of the device | ||
- `name` (String) Name of the device | ||
- `network_id` (String) ID of the network the device belongs to | ||
- `notes` (String) Notes for the device, limited to 255 characters | ||
- `product_type` (String) Product type of the device | ||
- `serial` (String) Serial number of the device | ||
- `tags` (List of String) List of tags assigned to the device | ||
|
||
<a id="nestedatt--items--details"></a> | ||
### Nested Schema for `items.details` | ||
|
||
Read-Only: | ||
|
||
- `name` (String) Additional property name | ||
- `value` (String) Additional property value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
examples/data-sources/meraki_organization_devices/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "meraki_organization_devices" "example" { | ||
organization_id = "123456" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: Organization Devices | ||
bulk_name: Organization Devices | ||
spec_endpoint: /organizations/{organizationId}/devices | ||
rest_endpoint: /organizations/%v/devices | ||
no_data_source: true | ||
no_resource: true | ||
bulk_data_source: true | ||
no_update: true | ||
no_delete: true | ||
data_source_name_query: true | ||
doc_category: Organizations | ||
test_variables: [test_org] | ||
attributes: | ||
- tf_name: organization_id | ||
type: String | ||
id: true | ||
reference: true | ||
description: Organization ID | ||
example: "123456" | ||
test_value: data.meraki_organization.test.id | ||
- model_name: address | ||
type: String | ||
description: Physical address of the device | ||
example: 1600 Pennsylvania Ave | ||
- model_name: firmware | ||
type: String | ||
description: Firmware version of the device | ||
example: wireless-25-14 | ||
- model_name: imei | ||
type: String | ||
description: IMEI of the device, if applicable | ||
example: "123456789000000" | ||
- model_name: lanIp | ||
type: String | ||
description: LAN IP address of the device | ||
example: 1.2.3.4 | ||
- model_name: lat | ||
type: Float64 | ||
description: Latitude of the device | ||
example: "37.4180951010362" | ||
- model_name: lng | ||
type: Float64 | ||
description: Longitude of the device | ||
example: "-122.098531723022" | ||
- model_name: mac | ||
type: String | ||
description: MAC address of the device | ||
example: "00:11:22:33:44:55" | ||
- model_name: model | ||
type: String | ||
description: Model of the device | ||
example: MR34 | ||
- model_name: name | ||
type: String | ||
description: Name of the device | ||
example: My AP | ||
- model_name: networkId | ||
type: String | ||
description: ID of the network the device belongs to | ||
example: N_24329156 | ||
- model_name: notes | ||
type: String | ||
description: Notes for the device, limited to 255 characters | ||
example: My AP's note | ||
- model_name: productType | ||
type: String | ||
description: Product type of the device | ||
example: wireless | ||
- model_name: serial | ||
type: String | ||
description: Serial number of the device | ||
example: Q234-ABCD-5678 | ||
- model_name: details | ||
type: List | ||
description: Additional device information | ||
attributes: | ||
- model_name: name | ||
type: String | ||
description: Additional property name | ||
example: Catalyst serial | ||
- model_name: value | ||
type: String | ||
description: Additional property value | ||
example: 123ABC | ||
- model_name: tags | ||
type: List | ||
element_type: String | ||
description: List of tags assigned to the device | ||
example: recently-added | ||
test_prerequisites: |2 | ||
data "meraki_organization" "test" { | ||
name = var.test_org | ||
} |
192 changes: 192 additions & 0 deletions
192
internal/provider/data_source_meraki_organization_devices.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// 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-framework/types" | ||
"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 = &OrganizationDevicesDataSource{} | ||
_ datasource.DataSourceWithConfigure = &OrganizationDevicesDataSource{} | ||
) | ||
|
||
func NewOrganizationDevicesDataSource() datasource.DataSource { | ||
return &OrganizationDevicesDataSource{} | ||
} | ||
|
||
type OrganizationDevicesDataSource struct { | ||
client *meraki.Client | ||
} | ||
|
||
func (d *OrganizationDevicesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_organization_devices" | ||
} | ||
|
||
func (d *OrganizationDevicesDataSource) 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 `Organization Devices` configuration.").String, | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"organization_id": schema.StringAttribute{ | ||
MarkdownDescription: "Organization 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, | ||
}, | ||
"address": schema.StringAttribute{ | ||
MarkdownDescription: "Physical address of the device", | ||
Computed: true, | ||
}, | ||
"firmware": schema.StringAttribute{ | ||
MarkdownDescription: "Firmware version of the device", | ||
Computed: true, | ||
}, | ||
"imei": schema.StringAttribute{ | ||
MarkdownDescription: "IMEI of the device, if applicable", | ||
Computed: true, | ||
}, | ||
"lan_ip": schema.StringAttribute{ | ||
MarkdownDescription: "LAN IP address of the device", | ||
Computed: true, | ||
}, | ||
"lat": schema.Float64Attribute{ | ||
MarkdownDescription: "Latitude of the device", | ||
Computed: true, | ||
}, | ||
"lng": schema.Float64Attribute{ | ||
MarkdownDescription: "Longitude of the device", | ||
Computed: true, | ||
}, | ||
"mac": schema.StringAttribute{ | ||
MarkdownDescription: "MAC address of the device", | ||
Computed: true, | ||
}, | ||
"model": schema.StringAttribute{ | ||
MarkdownDescription: "Model of the device", | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "Name of the device", | ||
Computed: true, | ||
}, | ||
"network_id": schema.StringAttribute{ | ||
MarkdownDescription: "ID of the network the device belongs to", | ||
Computed: true, | ||
}, | ||
"notes": schema.StringAttribute{ | ||
MarkdownDescription: "Notes for the device, limited to 255 characters", | ||
Computed: true, | ||
}, | ||
"product_type": schema.StringAttribute{ | ||
MarkdownDescription: "Product type of the device", | ||
Computed: true, | ||
}, | ||
"serial": schema.StringAttribute{ | ||
MarkdownDescription: "Serial number of the device", | ||
Computed: true, | ||
}, | ||
"details": schema.ListNestedAttribute{ | ||
MarkdownDescription: "Additional device information", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "Additional property name", | ||
Computed: true, | ||
}, | ||
"value": schema.StringAttribute{ | ||
MarkdownDescription: "Additional property value", | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"tags": schema.ListAttribute{ | ||
MarkdownDescription: "List of tags assigned to the device", | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *OrganizationDevicesDataSource) 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 *OrganizationDevicesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config OrganizationDevices | ||
|
||
// 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", "OrganizationDevicesDataSource")) | ||
|
||
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", "OrganizationDevicesDataSource")) | ||
|
||
diags = resp.State.Set(ctx, &config) | ||
resp.Diagnostics.Append(diags...) | ||
} | ||
|
||
// End of section. //template:end read |
Oops, something went wrong.