Skip to content

Commit

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

## 0.1.2

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

# meraki_organization_firmware_upgrades (Data Source)

This data source can read the `Organization Firmware Upgrades` configuration.

## Example Usage

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

- `completed_at` (String) Timestamp when upgrade completed. Null if status pending.
- `from_version_firmware` (String) Firmware name
- `from_version_id` (String) Firmware version ID
- `from_version_release_date` (String) Release date of the firmware version
- `from_version_release_type` (String) Release type of the firmware version
- `from_version_short_name` (String) Firmware version short name
- `id` (String) The id of the object
- `network_id` (String) ID of network
- `network_name` (String) The network
- `product_types` (String) product upgraded [wireless, appliance, switch, systemsManager, camera, cellularGateway, sensor]
- `status` (String) Status of upgrade event: [Cancelled, Completed]
- `time` (String) Scheduled start time
- `to_version_firmware` (String) Firmware name
- `to_version_id` (String) Firmware version ID
- `to_version_release_date` (String) Release date of the firmware version
- `to_version_release_type` (String) Release type of the firmware version
- `to_version_short_name` (String) Firmware version short name
- `upgrade_batch_id` (String) The upgrade batch
- `upgrade_id` (String) The upgrade
1 change: 1 addition & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ description: |-
- Add `meraki_network_client_splash_authorization_status` resource and data source
- Add `meraki_network_devices` data source
- Add `meraki_organization_devices` data source
- Add `meraki_organization_firmware_upgrades` data source

## 0.1.2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "meraki_organization_firmware_upgrades" "example" {
organization_id = "123456"
}
107 changes: 107 additions & 0 deletions gen/definitions/organization_firmware_upgrades.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Organization Firmware Upgrades
bulk_name: Organization Firmware Upgrades
spec_endpoint: /organizations/{organizationId}/firmware/upgrades
rest_endpoint: /organizations/%v/firmware/upgrades
no_data_source: true
no_resource: true
bulk_data_source: true
no_update: true
no_delete: 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: completedAt
type: String
description: Timestamp when upgrade completed. Null if status pending.
example: 2020-11-05 15:50:05 UTC
- model_name: productTypes
type: String
description: product upgraded [wireless, appliance, switch, systemsManager, camera, cellularGateway, sensor]
example: wireless
- model_name: status
type: String
description: 'Status of upgrade event: [Cancelled, Completed]'
example: Completed
- model_name: time
type: String
description: Scheduled start time
example: "2022-11-01T00:00:00Z"
- model_name: upgradeBatchId
type: String
description: The upgrade batch
example: "5678"
- model_name: upgradeId
type: String
description: The upgrade
example: "1234"
- model_name: firmware
type: String
data_path: [fromVersion]
description: Firmware name
example: wireless-11-2-1
- model_name: id
type: String
data_path: [fromVersion]
description: Firmware version ID
example: "2887"
- model_name: releaseDate
type: String
data_path: [fromVersion]
description: Release date of the firmware version
example: "2022-03-17T17:22:52Z"
- model_name: releaseType
type: String
data_path: [fromVersion]
description: Release type of the firmware version
example: stable
- model_name: shortName
type: String
data_path: [fromVersion]
description: Firmware version short name
example: MR 11.2.1
- model_name: id
type: String
data_path: [network]
description: ID of network
example: L_1738
- model_name: name
type: String
data_path: [network]
description: The network
example: Minions
- model_name: firmware
type: String
data_path: [toVersion]
description: Firmware name
example: wireless-11-2-1
- model_name: id
type: String
data_path: [toVersion]
description: Firmware version ID
example: "2888"
- model_name: releaseDate
type: String
data_path: [toVersion]
description: Release date of the firmware version
example: "2022-03-17T17:22:52Z"
- model_name: releaseType
type: String
data_path: [toVersion]
description: Release type of the firmware version
example: stable
- model_name: shortName
type: String
data_path: [toVersion]
description: Firmware version short name
example: MR 11.2.1
test_prerequisites: |2
data "meraki_organization" "test" {
name = var.test_org
}
190 changes: 190 additions & 0 deletions internal/provider/data_source_meraki_organization_firmware_upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// 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 = &OrganizationFirmwareUpgradesDataSource{}
_ datasource.DataSourceWithConfigure = &OrganizationFirmwareUpgradesDataSource{}
)

func NewOrganizationFirmwareUpgradesDataSource() datasource.DataSource {
return &OrganizationFirmwareUpgradesDataSource{}
}

type OrganizationFirmwareUpgradesDataSource struct {
client *meraki.Client
}

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

func (d *OrganizationFirmwareUpgradesDataSource) 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 Firmware Upgrades` 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,
},
"completed_at": schema.StringAttribute{
MarkdownDescription: "Timestamp when upgrade completed. Null if status pending.",
Computed: true,
},
"product_types": schema.StringAttribute{
MarkdownDescription: "product upgraded [wireless, appliance, switch, systemsManager, camera, cellularGateway, sensor]",
Computed: true,
},
"status": schema.StringAttribute{
MarkdownDescription: "Status of upgrade event: [Cancelled, Completed]",
Computed: true,
},
"time": schema.StringAttribute{
MarkdownDescription: "Scheduled start time",
Computed: true,
},
"upgrade_batch_id": schema.StringAttribute{
MarkdownDescription: "The upgrade batch",
Computed: true,
},
"upgrade_id": schema.StringAttribute{
MarkdownDescription: "The upgrade",
Computed: true,
},
"from_version_firmware": schema.StringAttribute{
MarkdownDescription: "Firmware name",
Computed: true,
},
"from_version_id": schema.StringAttribute{
MarkdownDescription: "Firmware version ID",
Computed: true,
},
"from_version_release_date": schema.StringAttribute{
MarkdownDescription: "Release date of the firmware version",
Computed: true,
},
"from_version_release_type": schema.StringAttribute{
MarkdownDescription: "Release type of the firmware version",
Computed: true,
},
"from_version_short_name": schema.StringAttribute{
MarkdownDescription: "Firmware version short name",
Computed: true,
},
"network_id": schema.StringAttribute{
MarkdownDescription: "ID of network",
Computed: true,
},
"network_name": schema.StringAttribute{
MarkdownDescription: "The network",
Computed: true,
},
"to_version_firmware": schema.StringAttribute{
MarkdownDescription: "Firmware name",
Computed: true,
},
"to_version_id": schema.StringAttribute{
MarkdownDescription: "Firmware version ID",
Computed: true,
},
"to_version_release_date": schema.StringAttribute{
MarkdownDescription: "Release date of the firmware version",
Computed: true,
},
"to_version_release_type": schema.StringAttribute{
MarkdownDescription: "Release type of the firmware version",
Computed: true,
},
"to_version_short_name": schema.StringAttribute{
MarkdownDescription: "Firmware version short name",
Computed: true,
},
},
},
},
},
}
}

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

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

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

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

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

0 comments on commit 0f2866e

Please sign in to comment.