Skip to content

Commit

Permalink
Add organization inventory devices data source
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Nov 5, 2024
1 parent 0f2866e commit 64f1688
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Add `meraki_network_devices` data source
- Add `meraki_organization_devices` data source
- Add `meraki_organization_firmware_upgrades` data source
- Add `meraki_organization_inventory_devices` data source

## 0.1.2

Expand Down
57 changes: 57 additions & 0 deletions docs/data-sources/organization_inventory_devices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_organization_inventory_devices Data Source - terraform-provider-meraki"
subcategory: ""
description: |-
This data source can read the Organization Inventory Devices configuration.
---

# meraki_organization_inventory_devices (Data Source)

This data source can read the `Organization Inventory Devices` configuration.

## Example Usage

```terraform
data "meraki_organization_inventory_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:

- `claimed_at` (String) Claimed time of the device
- `country_code` (String) Country/region code from device, network, or store order
- `details` (Attributes List) Additional device information (see [below for nested schema](#nestedatt--items--details))
- `id` (String) The id of the object
- `license_expiration_date` (String) License expiration date of the device
- `mac` (String) MAC address of the device
- `model` (String) Model type of the device
- `name` (String) Name of the device
- `network_id` (String) Network Id of the device
- `order_number` (String) Order number of the device
- `product_type` (String) Product type of the device
- `serial` (String) Serial number of the device
- `tags` (List of String) Device tags

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

Read-Only:

- `name` (String) Additional property name
- `value` (String) Additional property value
1 change: 1 addition & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ description: |-
- Add `meraki_network_devices` data source
- Add `meraki_organization_devices` data source
- Add `meraki_organization_firmware_upgrades` data source
- Add `meraki_organization_inventory_devices` data source

## 0.1.2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "meraki_organization_inventory_devices" "example" {
organization_id = "123456"
}
81 changes: 81 additions & 0 deletions gen/definitions/organization_inventory_devices.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Organization Inventory Devices
bulk_name: Organization Inventory Devices
spec_endpoint: /organizations/{organizationId}/inventory/devices
rest_endpoint: /organizations/%v/inventory/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: claimedAt
type: String
description: Claimed time of the device
example: "2018-02-11T00:00:00.090210Z"
- model_name: countryCode
type: String
description: Country/region code from device, network, or store order
example: US
- model_name: licenseExpirationDate
type: String
description: License expiration date of the device
example: "2020-05-02T10:52:44.012345Z"
- 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 type of the device
example: MR34
- model_name: name
type: String
description: Name of the device
example: My AP
- model_name: networkId
type: String
description: Network Id of the device
example: N_24329156
- model_name: orderNumber
type: String
description: Order number of the device
example: 4C1234567
- 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: FOC2234432B
- model_name: tags
type: List
element_type: String
description: Device tags
example: tag1
test_prerequisites: |2
data "meraki_organization" "test" {
name = var.test_org
}
180 changes: 180 additions & 0 deletions internal/provider/data_source_meraki_organization_inventory_devices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// 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 = &OrganizationInventoryDevicesDataSource{}
_ datasource.DataSourceWithConfigure = &OrganizationInventoryDevicesDataSource{}
)

func NewOrganizationInventoryDevicesDataSource() datasource.DataSource {
return &OrganizationInventoryDevicesDataSource{}
}

type OrganizationInventoryDevicesDataSource struct {
client *meraki.Client
}

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

func (d *OrganizationInventoryDevicesDataSource) 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 Inventory 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,
},
"claimed_at": schema.StringAttribute{
MarkdownDescription: "Claimed time of the device",
Computed: true,
},
"country_code": schema.StringAttribute{
MarkdownDescription: "Country/region code from device, network, or store order",
Computed: true,
},
"license_expiration_date": schema.StringAttribute{
MarkdownDescription: "License expiration date of the device",
Computed: true,
},
"mac": schema.StringAttribute{
MarkdownDescription: "MAC address of the device",
Computed: true,
},
"model": schema.StringAttribute{
MarkdownDescription: "Model type of the device",
Computed: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "Name of the device",
Computed: true,
},
"network_id": schema.StringAttribute{
MarkdownDescription: "Network Id of the device",
Computed: true,
},
"order_number": schema.StringAttribute{
MarkdownDescription: "Order number of the device",
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: "Device tags",
ElementType: types.StringType,
Computed: true,
},
},
},
},
},
}
}

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

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

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", "OrganizationInventoryDevicesDataSource"))

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

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

0 comments on commit 64f1688

Please sign in to comment.