0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-29 18:21:10 +00:00

chore(code): fix new qodana warnings (#1951)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2025-05-05 22:11:19 -04:00 committed by GitHub
parent 39e7b4822c
commit d23f7ab1c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 34 additions and 26 deletions

View File

@ -293,7 +293,7 @@ func (r *acmeAccountResource) read(ctx context.Context, data *acmeAccountModel)
acc, err := r.client.Get(ctx, name)
if err != nil {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
if !strings.Contains(err.Error(), "does not exist") {
diags.AddError(

View File

@ -40,7 +40,7 @@ func (m *GroupModel) ImportFromAPI(group hagroups.HAGroupGetResponseData) diag.D
// Parse the list of member nodes. The list is received from the Proxmox API as a string. It must
// be converted into a map value. Errors will be returned as Terraform diagnostics.
func (m *GroupModel) parseHAGroupNodes(nodes string) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
nodesIn := strings.Split(nodes, ",")
nodesOut := make(map[string]attr.Value)

View File

@ -309,7 +309,7 @@ func (r *hagroupResource) read(ctx context.Context, data *GroupModel) (bool, dia
group, err := r.client.Get(ctx, name)
if err != nil {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
if !strings.Contains(err.Error(), "no such ha group") {
diags.AddError("Could not read HA group", err.Error())

View File

@ -320,7 +320,7 @@ func (r *haResourceResource) ImportState(
// read reads information about a HA resource from the cluster. The Terraform resource identifier must have been set
// in the model before this function is called.
func (r *haResourceResource) read(ctx context.Context, data *ResourceModel) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
resID, err := proxmoxtypes.ParseHAResourceID(data.ID.ValueString())
if err != nil {

View File

@ -43,7 +43,7 @@ type dirResource struct {
// read reads information about a directory mapping from the Proxmox VE API.
func (r *dirResource) read(ctx context.Context, hm *modelDir) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
hmName := hm.Name.ValueString()

View File

@ -45,7 +45,7 @@ type pciResource struct {
// read reads information about a PCI hardware mapping from the Proxmox VE API.
func (r *pciResource) read(ctx context.Context, hm *modelPCI) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
hmName := hm.Name.ValueString()

View File

@ -44,7 +44,7 @@ type usbResource struct {
// read reads information about a USB hardware mapping from the Proxmox VE API.
func (r *usbResource) read(ctx context.Context, hm *modelUSB) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
hmName := hm.Name.ValueString()

View File

@ -10,11 +10,12 @@ import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/fwprovider/config"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
// Ensure the implementation satisfies the expected interfaces.

View File

@ -7,8 +7,9 @@
package metrics
import (
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
)
type metricsServerModel struct {

View File

@ -11,10 +11,6 @@ import (
"errors"
"fmt"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/fwprovider/config"
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
@ -23,6 +19,11 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/bpg/terraform-provider-proxmox/fwprovider/attribute"
"github.com/bpg/terraform-provider-proxmox/fwprovider/config"
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
)
var (

View File

@ -11,8 +11,9 @@ package metrics_test
import (
"testing"
"github.com/bpg/terraform-provider-proxmox/fwprovider/test"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/bpg/terraform-provider-proxmox/fwprovider/test"
)
func TestAccResourceMetricsServer(t *testing.T) {

View File

@ -142,7 +142,7 @@ type modelStandardRepo struct {
// importFromAPI imports the contents of an APT repository model from the Proxmox VE API's response data.
func (rp *modelRepo) importFromAPI(ctx context.Context, data *api.GetResponseData) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
// We can only ensure a unique ID by using the name of the Proxmox VE node and the absolute file path because custom
// source list files can be loaded by Proxmox VE from every path on a node.

View File

@ -58,7 +58,7 @@ type repositoryResource struct {
// read reads information about an APT repository from the Proxmox VE API.
// Note that the name of the node must be set before this method is called!
func (r *repositoryResource) read(ctx context.Context, rp *modelRepo) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
data, err := r.client.Node(rp.Node.ValueString()).APT().Repositories().Get(ctx)
if err != nil {

View File

@ -50,7 +50,7 @@ type standardRepositoryResource struct {
// read reads information about an APT standard repository from the Proxmox VE API.
// Note that the name of the node must be set before this method is called!
func (r *standardRepositoryResource) read(ctx context.Context, srp *modelStandardRepo) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
data, err := r.client.Node(srp.Node.ValueString()).APT().Repositories().Get(ctx)
if err != nil {

View File

@ -84,7 +84,7 @@ func (t IPAddrType) Validate(_ context.Context, value tftypes.Value, valuePath p
return nil
}
var diags diag.Diagnostics
diags := diag.Diagnostics{}
var valueString string

View File

@ -84,7 +84,7 @@ func (t IPCIDRType) Validate(_ context.Context, value tftypes.Value, valuePath p
return nil
}
var diags diag.Diagnostics
diags := diag.Diagnostics{}
var valueString string

View File

@ -83,7 +83,7 @@ func SecurityGroupCreate(ctx context.Context, api clusterfirewall.API, d *schema
// SecurityGroupRead reads the security group from the API and updates the state.
func SecurityGroupRead(ctx context.Context, api clusterfirewall.API, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
name := d.Id()

View File

@ -216,7 +216,7 @@ func ipSetUpdate(ctx context.Context, api firewall.API, d *schema.ResourceData)
}
func ipSetDelete(ctx context.Context, api firewall.API, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
name := d.Id()

View File

@ -180,7 +180,7 @@ func Rules() *schema.Resource {
// RulesCreate creates new firewall rules.
func RulesCreate(ctx context.Context, api firewall.Rule, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
rules := d.Get(MkRule).([]interface{})
@ -235,7 +235,7 @@ func RulesCreate(ctx context.Context, api firewall.Rule, d *schema.ResourceData)
// RulesRead reads rules from the API and updates the state.
func RulesRead(ctx context.Context, api firewall.Rule, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
readRule := func(pos int, ruleMap map[string]interface{}) error {
rule, err := api.GetRule(ctx, pos)
@ -304,7 +304,7 @@ func RulesRead(ctx context.Context, api firewall.Rule, d *schema.ResourceData) d
// RulesUpdate updates rules.
func RulesUpdate(ctx context.Context, api firewall.Rule, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
diags := diag.Diagnostics{}
rules := d.Get(MkRule).([]interface{})
for i := len(rules) - 1; i >= 0; i-- {

View File

@ -47,7 +47,7 @@ func GetSchemaBlock(
if ki == 0 {
resourceData = d.Get(kv)
resourceSchema = r.Schema[kv]
} else {
} else if resourceSchema != nil {
mapValues := resourceData.([]interface{})
if len(mapValues) <= i {
@ -61,6 +61,10 @@ func GetSchemaBlock(
}
}
if resourceSchema == nil {
return nil, fmt.Errorf("schema not found for %s", strings.Join(k, "."))
}
list := resourceData.([]interface{})
if len(list) == 0 {