mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 18:42:58 +00:00
* 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
79 lines
1.9 KiB
Go
79 lines
1.9 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 (
|
|
mkDataSourceVirtualEnvironmentGroupsComments = "comments"
|
|
mkDataSourceVirtualEnvironmentGroupsGroupIDs = "group_ids"
|
|
)
|
|
|
|
func dataSourceVirtualEnvironmentGroups() *schema.Resource {
|
|
return &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
mkDataSourceVirtualEnvironmentGroupsComments: {
|
|
Type: schema.TypeList,
|
|
Description: "The group comments",
|
|
Computed: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
},
|
|
mkDataSourceVirtualEnvironmentGroupsGroupIDs: {
|
|
Type: schema.TypeList,
|
|
Description: "The group ids",
|
|
Computed: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
},
|
|
},
|
|
ReadContext: dataSourceVirtualEnvironmentGroupsRead,
|
|
}
|
|
}
|
|
|
|
func dataSourceVirtualEnvironmentGroupsRead(
|
|
ctx context.Context,
|
|
d *schema.ResourceData,
|
|
m interface{},
|
|
) diag.Diagnostics {
|
|
var diags diag.Diagnostics
|
|
|
|
config := m.(providerConfiguration)
|
|
veClient, err := config.GetVEClient()
|
|
if err != nil {
|
|
return diag.FromErr(err)
|
|
}
|
|
|
|
list, err := veClient.ListGroups(ctx)
|
|
if err != nil {
|
|
return diag.FromErr(err)
|
|
}
|
|
|
|
comments := make([]interface{}, len(list))
|
|
groupIDs := make([]interface{}, len(list))
|
|
|
|
for i, v := range list {
|
|
if v.Comment != nil {
|
|
comments[i] = v.Comment
|
|
} else {
|
|
comments[i] = ""
|
|
}
|
|
|
|
groupIDs[i] = v.ID
|
|
}
|
|
|
|
d.SetId("groups")
|
|
|
|
err = d.Set(mkDataSourceVirtualEnvironmentGroupsComments, comments)
|
|
diags = append(diags, diag.FromErr(err)...)
|
|
err = d.Set(mkDataSourceVirtualEnvironmentGroupsGroupIDs, groupIDs)
|
|
diags = append(diags, diag.FromErr(err)...)
|
|
|
|
return diags
|
|
}
|