-
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 inventory devices data source
- Loading branch information
Showing
10 changed files
with
555 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,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 |
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_inventory_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_inventory_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,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
180
internal/provider/data_source_meraki_organization_inventory_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,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 |
Oops, something went wrong.