0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-02 03:22:59 +00:00
terraform-provider-proxmox/proxmoxtf/data_source_virtual_environment_pools.go
Pavel Boldyrev bf9e31ecfc
chore: lint and reformat the code (#204)
* chore: reformat code

* chore: add commitlint config

* reformat README.md

* add linter config

* lint & reformat docs

* go linter: only new issues

* fix some linting errors

* more reformatting

* disable linter warning for some duplicated code
2023-01-16 18:07:30 -05:00

60 lines
1.3 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 proxmoxtf
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
mkDataSourceVirtualEnvironmentPoolsPoolIDs = "pool_ids"
)
func dataSourceVirtualEnvironmentPools() *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: dataSourceVirtualEnvironmentPoolsRead,
}
}
func dataSourceVirtualEnvironmentPoolsRead(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
config := m.(providerConfiguration)
veClient, err := config.GetVEClient()
if err != nil {
return diag.FromErr(err)
}
list, err := veClient.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)
}