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:
parent
39e7b4822c
commit
d23f7ab1c0
@ -293,7 +293,7 @@ func (r *acmeAccountResource) read(ctx context.Context, data *acmeAccountModel)
|
|||||||
|
|
||||||
acc, err := r.client.Get(ctx, name)
|
acc, err := r.client.Get(ctx, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
if !strings.Contains(err.Error(), "does not exist") {
|
if !strings.Contains(err.Error(), "does not exist") {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
|
@ -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
|
// 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.
|
// be converted into a map value. Errors will be returned as Terraform diagnostics.
|
||||||
func (m *GroupModel) parseHAGroupNodes(nodes string) diag.Diagnostics {
|
func (m *GroupModel) parseHAGroupNodes(nodes string) diag.Diagnostics {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
nodesIn := strings.Split(nodes, ",")
|
nodesIn := strings.Split(nodes, ",")
|
||||||
nodesOut := make(map[string]attr.Value)
|
nodesOut := make(map[string]attr.Value)
|
||||||
|
@ -309,7 +309,7 @@ func (r *hagroupResource) read(ctx context.Context, data *GroupModel) (bool, dia
|
|||||||
|
|
||||||
group, err := r.client.Get(ctx, name)
|
group, err := r.client.Get(ctx, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
if !strings.Contains(err.Error(), "no such ha group") {
|
if !strings.Contains(err.Error(), "no such ha group") {
|
||||||
diags.AddError("Could not read HA group", err.Error())
|
diags.AddError("Could not read HA group", err.Error())
|
||||||
|
@ -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
|
// 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.
|
// in the model before this function is called.
|
||||||
func (r *haResourceResource) read(ctx context.Context, data *ResourceModel) (bool, diag.Diagnostics) {
|
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())
|
resID, err := proxmoxtypes.ParseHAResourceID(data.ID.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,7 +43,7 @@ type dirResource struct {
|
|||||||
|
|
||||||
// read reads information about a directory mapping from the Proxmox VE API.
|
// read reads information about a directory mapping from the Proxmox VE API.
|
||||||
func (r *dirResource) read(ctx context.Context, hm *modelDir) (bool, diag.Diagnostics) {
|
func (r *dirResource) read(ctx context.Context, hm *modelDir) (bool, diag.Diagnostics) {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
hmName := hm.Name.ValueString()
|
hmName := hm.Name.ValueString()
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ type pciResource struct {
|
|||||||
|
|
||||||
// read reads information about a PCI hardware mapping from the Proxmox VE API.
|
// 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) {
|
func (r *pciResource) read(ctx context.Context, hm *modelPCI) (bool, diag.Diagnostics) {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
hmName := hm.Name.ValueString()
|
hmName := hm.Name.ValueString()
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ type usbResource struct {
|
|||||||
|
|
||||||
// read reads information about a USB hardware mapping from the Proxmox VE API.
|
// 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) {
|
func (r *usbResource) read(ctx context.Context, hm *modelUSB) (bool, diag.Diagnostics) {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
hmName := hm.Name.ValueString()
|
hmName := hm.Name.ValueString()
|
||||||
|
|
||||||
|
@ -10,11 +10,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"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/attribute"
|
||||||
"github.com/bpg/terraform-provider-proxmox/fwprovider/config"
|
"github.com/bpg/terraform-provider-proxmox/fwprovider/config"
|
||||||
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
|
"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.
|
// Ensure the implementation satisfies the expected interfaces.
|
||||||
|
@ -7,8 +7,9 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
|
||||||
|
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metricsServerModel struct {
|
type metricsServerModel struct {
|
||||||
|
@ -11,10 +11,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"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/int64validator"
|
||||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"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/planmodifier"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
"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 (
|
var (
|
||||||
|
@ -11,8 +11,9 @@ package metrics_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/bpg/terraform-provider-proxmox/fwprovider/test"
|
|
||||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||||
|
|
||||||
|
"github.com/bpg/terraform-provider-proxmox/fwprovider/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccResourceMetricsServer(t *testing.T) {
|
func TestAccResourceMetricsServer(t *testing.T) {
|
||||||
|
@ -142,7 +142,7 @@ type modelStandardRepo struct {
|
|||||||
|
|
||||||
// importFromAPI imports the contents of an APT repository model from the Proxmox VE API's response data.
|
// 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 {
|
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
|
// 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.
|
// source list files can be loaded by Proxmox VE from every path on a node.
|
||||||
|
@ -58,7 +58,7 @@ type repositoryResource struct {
|
|||||||
// read reads information about an APT repository from the Proxmox VE API.
|
// 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!
|
// 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) {
|
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)
|
data, err := r.client.Node(rp.Node.ValueString()).APT().Repositories().Get(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ type standardRepositoryResource struct {
|
|||||||
// read reads information about an APT standard repository from the Proxmox VE API.
|
// 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!
|
// 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) {
|
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)
|
data, err := r.client.Node(srp.Node.ValueString()).APT().Repositories().Get(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,7 +84,7 @@ func (t IPAddrType) Validate(_ context.Context, value tftypes.Value, valuePath p
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
var valueString string
|
var valueString string
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func (t IPCIDRType) Validate(_ context.Context, value tftypes.Value, valuePath p
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
var valueString string
|
var valueString string
|
||||||
|
|
||||||
|
@ -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.
|
// 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 {
|
func SecurityGroupRead(ctx context.Context, api clusterfirewall.API, d *schema.ResourceData) diag.Diagnostics {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
name := d.Id()
|
name := d.Id()
|
||||||
|
|
||||||
|
@ -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 {
|
func ipSetDelete(ctx context.Context, api firewall.API, d *schema.ResourceData) diag.Diagnostics {
|
||||||
var diags diag.Diagnostics
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
name := d.Id()
|
name := d.Id()
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ func Rules() *schema.Resource {
|
|||||||
|
|
||||||
// RulesCreate creates new firewall rules.
|
// RulesCreate creates new firewall rules.
|
||||||
func RulesCreate(ctx context.Context, api firewall.Rule, d *schema.ResourceData) diag.Diagnostics {
|
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{})
|
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.
|
// RulesRead reads rules from the API and updates the state.
|
||||||
func RulesRead(ctx context.Context, api firewall.Rule, d *schema.ResourceData) diag.Diagnostics {
|
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 {
|
readRule := func(pos int, ruleMap map[string]interface{}) error {
|
||||||
rule, err := api.GetRule(ctx, pos)
|
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.
|
// RulesUpdate updates rules.
|
||||||
func RulesUpdate(ctx context.Context, api firewall.Rule, d *schema.ResourceData) diag.Diagnostics {
|
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{})
|
rules := d.Get(MkRule).([]interface{})
|
||||||
for i := len(rules) - 1; i >= 0; i-- {
|
for i := len(rules) - 1; i >= 0; i-- {
|
||||||
|
@ -47,7 +47,7 @@ func GetSchemaBlock(
|
|||||||
if ki == 0 {
|
if ki == 0 {
|
||||||
resourceData = d.Get(kv)
|
resourceData = d.Get(kv)
|
||||||
resourceSchema = r.Schema[kv]
|
resourceSchema = r.Schema[kv]
|
||||||
} else {
|
} else if resourceSchema != nil {
|
||||||
mapValues := resourceData.([]interface{})
|
mapValues := resourceData.([]interface{})
|
||||||
|
|
||||||
if len(mapValues) <= i {
|
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{})
|
list := resourceData.([]interface{})
|
||||||
|
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user