0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-08 14:55:02 +00:00
terraform-provider-proxmox/proxmoxtf/datasource/pools.go
renovate[bot] 6a8f367c46
chore(deps): update golangci/golangci-lint (v2.1.6 → v2.2.1) (#2013)
* chore(deps): update golangci/golangci-lint (v2.1.6 → v2.2.1)

| datasource      | package                | from   | to     |
| --------------- | ---------------------- | ------ | ------ |
| github-releases | golangci/golangci-lint | v2.1.6 | v2.2.1 |

* chore: update rules & run linter

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2025-07-04 17:56:38 -04:00

62 lines
1.4 KiB
Go

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package datasource
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
)
const (
mkDataSourceVirtualEnvironmentPoolsPoolIDs = "pool_ids"
)
// Pools returns a resource for the Proxmox pools.
func Pools() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
mkDataSourceVirtualEnvironmentPoolsPoolIDs: {
Type: schema.TypeList,
Description: "The pool ids",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
ReadContext: poolsRead,
}
}
func poolsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
config := m.(proxmoxtf.ProviderConfiguration)
api, err := config.GetClient()
if err != nil {
return diag.FromErr(err)
}
list, err := api.Pool().ListPools(ctx)
if err != nil {
return diag.FromErr(err)
}
poolIDs := make([]interface{}, len(list))
for i, v := range list {
poolIDs[i] = v.ID
}
d.SetId("pools")
err = d.Set(mkDataSourceVirtualEnvironmentPoolsPoolIDs, poolIDs)
return diag.FromErr(err)
}