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

chore(code): fix code quality warnings (#1409)

* chore(code): fix code quality warnings

+ re-enable Qodana on PRs

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-06-25 00:47:50 -04:00 committed by GitHub
parent 27cf34f9b4
commit 4f70459c26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 50 additions and 851 deletions

View File

@ -2,8 +2,10 @@ name: Qodana
on:
workflow_dispatch:
push:
branches: # Specify your branches here
- main # The 'main' branch
branches:
- main
pull_request:
types: [opened, synchronize]
jobs:
qodana:
@ -19,5 +21,7 @@ jobs:
fetch-depth: 0 # a full history is required for pull request analysis
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2024.1.5
with:
post-pr-comment: false
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

View File

@ -87,7 +87,6 @@ jobs:
with:
name: test-log
path: /tmp/gotest.log
if-no-files-found: error
- name: Check for uncommitted changes in generated docs
run: make docs && git diff --exit-code

View File

@ -49,6 +49,9 @@ jobs:
- name: Get dependencies
run: go mod download
- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1
with:
terraform_version: ${{ matrix.terraform }}.*
@ -78,4 +81,3 @@ jobs:
with:
name: test-log
path: /tmp/gotest.log
if-no-files-found: error

View File

@ -36,6 +36,7 @@ The attributes are also marked as optional to allow the practitioner to set (or
- `description` (String) The description of the VM.
- `id` (Number) The unique identifier of the VM in the Proxmox cluster.
- `name` (String) The name of the VM. Doesn't have to be unique.
- `stop_on_destroy` (Boolean) Set to true to stop (rather than shutdown) the VM on destroy (defaults to `false`).
- `tags` (Set of String) The tags assigned to the VM.
- `template` (Boolean) Set to true to create a VM template.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

View File

@ -81,8 +81,8 @@ func (r *hagroupResource) Schema(
Optional: true,
Validators: []validator.String{
stringvalidator.UTF8LengthAtLeast(1),
stringvalidator.RegexMatches(regexp.MustCompile(`^[^\s]|^$`), "must not start with whitespace"),
stringvalidator.RegexMatches(regexp.MustCompile(`[^\s]$|^$`), "must not end with whitespace"),
stringvalidator.RegexMatches(regexp.MustCompile(`^\S|^$`), "must not start with whitespace"),
stringvalidator.RegexMatches(regexp.MustCompile(`\S$|^$`), "must not end with whitespace"),
},
},
"nodes": schema.MapAttribute{

View File

@ -101,8 +101,8 @@ func (r *haResourceResource) Schema(
Optional: true,
Validators: []validator.String{
stringvalidator.UTF8LengthAtLeast(1),
stringvalidator.RegexMatches(regexp.MustCompile(`^[^\s]|^$`), "must not start with whitespace"),
stringvalidator.RegexMatches(regexp.MustCompile(`[^\s]$|^$`), "must not end with whitespace"),
stringvalidator.RegexMatches(regexp.MustCompile(`^\S|^$`), "must not start with whitespace"),
stringvalidator.RegexMatches(regexp.MustCompile(`\S$|^$`), "must not end with whitespace"),
},
},
"group": schema.StringAttribute{

View File

@ -35,13 +35,14 @@ type Model struct {
ID types.Int64 `tfsdk:"id"`
Retries types.Int64 `tfsdk:"retries"`
} `tfsdk:"clone"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
NodeName types.String `tfsdk:"node_name"`
Tags stringset.Value `tfsdk:"tags"`
Template types.Bool `tfsdk:"template"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
VGA vga.Value `tfsdk:"vga"`
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
NodeName types.String `tfsdk:"node_name"`
StopOnDestroy types.Bool `tfsdk:"stop_on_destroy"`
Tags stringset.Value `tfsdk:"tags"`
Template types.Bool `tfsdk:"template"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
VGA vga.Value `tfsdk:"vga"`
}
// read retrieves the current state of the resource from the API and updates the state.

View File

@ -374,11 +374,8 @@ func (r *Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp
return
}
// stop := d.Get(mkStopOnDestroy).(bool)
stop := false
if status.Status != "stopped" {
if stop {
if state.StopOnDestroy.ValueBool() {
if e := vmStop(ctx, vmAPI); e != nil {
resp.Diagnostics.AddWarning("Failed to stop VM", e.Error())
}
@ -445,6 +442,9 @@ func (r *Resource) ImportState(
return
}
// not clear why this is needed, but ImportStateVerify fails without it
state.StopOnDestroy = types.BoolValue(false)
diags := resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}

View File

@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
@ -88,6 +89,13 @@ func (r *Resource) Schema(
Description: "The name of the node where the VM is provisioned.",
Required: true,
},
"stop_on_destroy": schema.BoolAttribute{
Description: "Set to true to stop (rather than shutdown) the VM on destroy.",
MarkdownDescription: "Set to true to stop (rather than shutdown) the VM on destroy (defaults to `false`).",
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"tags": stringset.ResourceAttribute("The tags assigned to the VM.", ""),
"template": schema.BoolAttribute{
Description: "Set to true to create a VM template.",

View File

@ -45,7 +45,8 @@ func (c *Client) GetTaskStatus(ctx context.Context, upid string) (*GetTaskStatus
// Reads first 50 lines by default.
func (c *Client) GetTaskLog(ctx context.Context, upid string) ([]string, error) {
resBody := &GetTaskLogResponseBody{}
lines := []string{}
var lines []string //nolint: prealloc
path, err := c.BuildPath(upid, "log")
if err != nil {

View File

@ -112,7 +112,7 @@ func (d *CustomStorageDevice) IsCloudInitDrive(vmID int) bool {
// EncodeOptions converts a CustomStorageDevice's common options a URL value.
func (d *CustomStorageDevice) EncodeOptions() string {
values := []string{}
var values []string
if d.AIO != nil {
values = append(values, fmt.Sprintf("aio=%s", *d.AIO))

View File

@ -31,7 +31,7 @@ func (r *CustomUSBDevice) EncodeValues(key string, v *url.Values) error {
return fmt.Errorf("either device ID or resource mapping must be set")
}
values := []string{}
var values []string
if r.HostDevice != nil {
values = append(values, fmt.Sprintf("host=%s", *(r.HostDevice)))
}

View File

@ -1,72 +0,0 @@
/*
* 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 firewall
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/proxmox/firewall"
)
const (
dvAliasComment = ""
mkAliasName = "name"
mkAliasCIDR = "cidr"
mkAliasComment = "comment"
)
// AliasSchema defines the schema for the alias.
func AliasSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkAliasName: {
Type: schema.TypeString,
Description: "Alias name",
Required: true,
},
mkAliasCIDR: {
Type: schema.TypeString,
Description: "IP/CIDR block",
Computed: true,
},
mkAliasComment: {
Type: schema.TypeString,
Description: "Alias comment",
Computed: true,
},
}
}
// AliasRead reads the alias.
func AliasRead(ctx context.Context, fw firewall.API, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
aliasName := d.Get(mkAliasName).(string)
alias, err := fw.GetAlias(ctx, aliasName)
if err != nil {
return diag.FromErr(err)
}
d.SetId(aliasName)
err = d.Set(mkAliasCIDR, alias.CIDR)
diags = append(diags, diag.FromErr(err)...)
if alias.Comment != nil {
err = d.Set(mkAliasComment, alias.Comment)
} else {
err = d.Set(mkAliasComment, dvAliasComment)
}
diags = append(diags, diag.FromErr(err)...)
return diags
}

View File

@ -1,44 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestAliasSchemaInstantiation tests whether the AliasSchema instance can be instantiated.
func TestAliasSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNilf(t, AliasSchema(), "Cannot instantiate AliasSchema")
}
// TestAliasSchema tests the AliasSchema.
func TestAliasSchema(t *testing.T) {
t.Parallel()
s := AliasSchema()
test.AssertRequiredArguments(t, s, []string{
mkAliasName,
})
test.AssertComputedAttributes(t, s, []string{
mkAliasCIDR,
mkAliasComment,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkAliasName: schema.TypeString,
mkAliasCIDR: schema.TypeString,
mkAliasComment: schema.TypeString,
})
}

View File

@ -1,53 +0,0 @@
/*
* 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 firewall
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/bpg/terraform-provider-proxmox/proxmox/firewall"
)
const (
mkAliasesAliasNames = "alias_names"
)
// AliasesSchema defines the schema for the Aliases data source.
func AliasesSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkAliasesAliasNames: {
Type: schema.TypeList,
Description: "Alias Names",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
}
}
// AliasesRead reads the aliases.
func AliasesRead(ctx context.Context, fw firewall.API, d *schema.ResourceData) diag.Diagnostics {
list, err := fw.ListAliases(ctx)
if err != nil {
return diag.FromErr(err)
}
aliasNames := make([]interface{}, len(list))
for i, v := range list {
aliasNames[i] = v.Name
}
d.SetId(uuid.New().String())
err = d.Set(mkAliasesAliasNames, aliasNames)
return diag.FromErr(err)
}

View File

@ -1,37 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestAliasesSchemaInstantiation tests whether the AliasesSchema instance can be instantiated.
func TestAliasesSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNil(t, AliasesSchema(), "Cannot instantiate AliasesSchema")
}
// TestAliasesSchema tests the AliasesSchema.
func TestAliasesSchema(t *testing.T) {
t.Parallel()
s := AliasesSchema()
test.AssertComputedAttributes(t, s, []string{
mkAliasesAliasNames,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkAliasesAliasNames: schema.TypeList,
})
}

View File

@ -1,127 +0,0 @@
/*
* 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 firewall
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/proxmox/firewall"
)
const (
dvIPSetCIDRComment = ""
dvIPSetCIDRNoMatch = false
mkIPSetName = "name"
mkIPSetCIDR = "cidr"
mkIPSetCIDRName = "name"
mkIPSetCIDRComment = "comment"
mkIPSetCIDRNoMatch = "nomatch"
)
// IPSetSchema defines the schema for the IPSet.
func IPSetSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkIPSetName: {
Type: schema.TypeString,
Description: "IPSet name",
Required: true,
},
mkIPSetCIDRComment: {
Type: schema.TypeString,
Description: "IPSet comment",
Computed: true,
},
mkIPSetCIDR: {
Type: schema.TypeList,
Description: "List of IP or Networks",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
mkIPSetCIDRName: {
Type: schema.TypeString,
Description: "Network/IP specification in CIDR format",
Computed: true,
},
mkIPSetCIDRNoMatch: {
Type: schema.TypeBool,
Description: "No match this IP/CIDR",
Computed: true,
},
mkIPSetCIDRComment: {
Type: schema.TypeString,
Description: "IP/CIDR comment",
Computed: true,
},
},
},
},
}
}
// IPSetRead reads the IPSet.
func IPSetRead(ctx context.Context, fw firewall.API, d *schema.ResourceData) diag.Diagnostics {
var diags diag.Diagnostics
ipSetName := d.Get(mkIPSetName).(string)
d.SetId(ipSetName)
ipSetList, err := fw.ListIPSets(ctx)
if err != nil {
return diag.FromErr(err)
}
for _, ipSet := range ipSetList {
if ipSet.Name == ipSetName {
if ipSet.Comment != nil {
err = d.Set(mkIPSetCIDRComment, ipSet.Comment)
} else {
err = d.Set(mkIPSetCIDRComment, dvIPSetCIDRComment)
}
diags = append(diags, diag.FromErr(err)...)
break
}
}
content, err := fw.GetIPSetContent(ctx, ipSetName)
if err != nil {
return diag.FromErr(err)
}
//nolint:prealloc
var cidrs []interface{}
for _, v := range content {
cirdEntry := map[string]interface{}{}
cirdEntry[mkIPSetCIDRName] = v.CIDR
if v.NoMatch != nil {
cirdEntry[mkIPSetCIDRNoMatch] = bool(*v.NoMatch)
} else {
cirdEntry[mkIPSetCIDRNoMatch] = dvIPSetCIDRNoMatch
}
if v.Comment != nil {
cirdEntry[mkIPSetCIDRComment] = v.Comment
} else {
cirdEntry[mkIPSetCIDRComment] = dvIPSetCIDRComment
}
cidrs = append(cidrs, cirdEntry)
}
err = d.Set(mkIPSetCIDR, cidrs)
diags = append(diags, diag.FromErr(err)...)
return diags
}

View File

@ -1,58 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestIPSetSchemaInstantiation tests whether the IPSetSchema instance can be instantiated.
func TestIPSetSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNil(t, IPSetSchema(), "Cannot instantiate IPSetSchema")
}
// TestIPSetSchema tests the IPSetSchema.
func TestIPSetSchema(t *testing.T) {
t.Parallel()
s := IPSetSchema()
test.AssertRequiredArguments(t, s, []string{
mkIPSetName,
})
test.AssertComputedAttributes(t, s, []string{
mkIPSetCIDR,
mkIPSetCIDRComment,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkIPSetName: schema.TypeString,
mkIPSetCIDR: schema.TypeList,
mkIPSetCIDRComment: schema.TypeString,
})
cird := test.AssertNestedSchemaExistence(t, s, mkIPSetCIDR)
test.AssertComputedAttributes(t, cird, []string{
mkIPSetCIDRName,
mkIPSetCIDRNoMatch,
mkIPSetCIDRComment,
})
test.AssertValueTypes(t, cird, map[string]schema.ValueType{
mkIPSetCIDRName: schema.TypeString,
mkIPSetCIDRNoMatch: schema.TypeBool,
mkIPSetCIDRComment: schema.TypeString,
})
}

View File

@ -1,53 +0,0 @@
/*
* 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 firewall
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/bpg/terraform-provider-proxmox/proxmox/firewall"
)
const (
mkIPSetsIPSetNames = "ipset_names"
)
// IPSetsSchema defines the schema for the IP sets.
func IPSetsSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkIPSetsIPSetNames: {
Type: schema.TypeList,
Description: "IPSet Names",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
}
}
// IPSetsRead reads the IP sets.
func IPSetsRead(ctx context.Context, fw firewall.API, d *schema.ResourceData) diag.Diagnostics {
list, err := fw.ListIPSets(ctx)
if err != nil {
return diag.FromErr(err)
}
ipSetNames := make([]interface{}, len(list))
for i, v := range list {
ipSetNames[i] = v.Name
}
d.SetId(uuid.New().String())
err = d.Set(mkIPSetsIPSetNames, ipSetNames)
return diag.FromErr(err)
}

View File

@ -1,37 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestIPSetsSchemaInstantiation tests whether the IPSetsSchema instance can be instantiated.
func TestIPSetsSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNil(t, IPSetsSchema(), "Cannot instantiate IPSetsSchema")
}
// TestIPSetsSchema tests the IPSetsSchema.
func TestIPSetsSchema(t *testing.T) {
t.Parallel()
s := IPSetsSchema()
test.AssertComputedAttributes(t, s, []string{
mkIPSetsIPSetNames,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkIPSetsIPSetNames: schema.TypeList,
})
}

View File

@ -1,132 +0,0 @@
/*
* 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 firewall
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
mkRuleAction = "action"
mkRuleComment = "comment"
mkRuleDPort = "dport"
mkRuleDest = "dest"
mkRuleEnable = "enable"
mkRuleIFace = "iface"
mkRuleLog = "log"
mkRuleMacro = "macro"
mkRulePos = "pos"
mkRuleProto = "proto"
mkRuleSource = "source"
mkRuleSPort = "sport"
mkRuleType = "type"
)
// RuleSchema returns the schema for the firewall rule data source.
func RuleSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkRulePos: {
Type: schema.TypeInt,
Description: "Rule position",
Computed: true,
},
mkRuleAction: {
Type: schema.TypeString,
Description: "Rule action ('ACCEPT', 'DROP', 'REJECT')",
Required: true,
},
mkRuleType: {
Type: schema.TypeString,
Description: "Rule type ('in', 'out')",
Required: true,
},
mkRuleComment: {
Type: schema.TypeString,
Description: "Rule comment",
Computed: true,
},
mkRuleDest: {
Type: schema.TypeString,
Description: "Packet destination address",
Computed: true,
},
mkRuleDPort: {
Type: schema.TypeString,
Description: "TCP/UDP destination port.",
Computed: true,
},
mkRuleEnable: {
Type: schema.TypeBool,
Description: "Enable rule",
Computed: true,
},
mkRuleIFace: {
Type: schema.TypeString,
Description: "Network interface name.",
Computed: true,
},
mkRuleLog: {
Type: schema.TypeString,
Description: "Log level for this rule",
Computed: true,
},
mkRuleMacro: {
Type: schema.TypeString,
Description: "Use predefined standard macro",
Computed: true,
},
mkRuleProto: {
Type: schema.TypeString,
Description: "Packet protocol.",
Computed: true,
},
mkRuleSource: {
Type: schema.TypeString,
Description: "Packet source address.",
Computed: true,
},
mkRuleSPort: {
Type: schema.TypeString,
Description: "TCP/UDP source port.",
Computed: true,
},
}
}
//
// func baseRuleToMap(baseRule *firewall.BaseRule, rule map[string]interface{}) {
// if baseRule.Comment != nil {
// rule[mkRuleComment] = *baseRule.Comment
// }
// if baseRule.Dest != nil {
// rule[mkRuleDest] = *baseRule.Dest
// }
// if baseRule.DPort != nil {
// rule[mkRuleDPort] = *baseRule.DPort
// }
// if baseRule.Enable != nil {
// rule[mkRuleEnable] = *baseRule.Enable
// }
// if baseRule.IFace != nil {
// rule[mkRuleIFace] = *baseRule.IFace
// }
// if baseRule.Log != nil {
// rule[mkRuleLog] = *baseRule.Log
// }
// if baseRule.Macro != nil {
// rule[mkRuleMacro] = *baseRule.Macro
// }
// if baseRule.Proto != nil {
// rule[mkRuleProto] = *baseRule.Proto
// }
// if baseRule.Source != nil {
// rule[mkRuleSource] = *baseRule.Source
// }
// if baseRule.SPort != nil {
// rule[mkRuleSPort] = *baseRule.SPort
// }
// }

View File

@ -1,63 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestRuleInstantiation tests whether the RuleSchema instance can be instantiated.
func TestRuleSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNilf(t, RuleSchema(), "Cannot instantiate RuleSchema")
}
// TestRuleSchema tests the RuleSchema.
func TestRuleSchema(t *testing.T) {
t.Parallel()
s := RuleSchema()
test.AssertRequiredArguments(t, s, []string{
mkRuleAction,
mkRuleType,
})
test.AssertComputedAttributes(t, s, []string{
mkRuleComment,
mkRuleDest,
mkRuleDPort,
mkRuleEnable,
mkRuleIFace,
mkRuleLog,
mkRuleMacro,
mkRuleProto,
mkRuleSource,
mkRuleSPort,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkRulePos: schema.TypeInt,
mkRuleAction: schema.TypeString,
mkRuleType: schema.TypeString,
mkRuleComment: schema.TypeString,
mkRuleDest: schema.TypeString,
mkRuleDPort: schema.TypeString,
mkRuleEnable: schema.TypeBool,
mkRuleIFace: schema.TypeString,
mkRuleLog: schema.TypeString,
mkRuleMacro: schema.TypeString,
mkRuleProto: schema.TypeString,
mkRuleSource: schema.TypeString,
mkRuleSPort: schema.TypeString,
})
}

View File

@ -1,39 +0,0 @@
/*
* 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 firewall
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
mkSecurityGroupName = "name"
mkSecurityGroupComment = "comment"
mkRules = "rules"
)
// SecurityGroupSchema defines the schema for the security group data source.
func SecurityGroupSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkSecurityGroupName: {
Type: schema.TypeString,
Description: "Security group name",
Required: true,
},
mkSecurityGroupComment: {
Type: schema.TypeString,
Description: "Security group comment",
Computed: true,
},
mkRules: {
Type: schema.TypeList,
Description: "List of rules",
Computed: true,
Elem: &schema.Resource{Schema: RuleSchema()},
},
}
}

View File

@ -1,44 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestSecurityGroupSchemaInstantiation tests whether the SecurityGroupSchema instance can be instantiated.
func TestSecurityGroupSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNil(t, SecurityGroupSchema(), "Cannot instantiate SecurityGroupSchema")
}
// TestSecurityGroupSchema tests the SecurityGroupSchema.
func TestSecurityGroupSchema(t *testing.T) {
t.Parallel()
s := SecurityGroupSchema()
test.AssertRequiredArguments(t, s, []string{
mkSecurityGroupName,
})
test.AssertComputedAttributes(t, s, []string{
mkSecurityGroupComment,
mkRules,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkSecurityGroupName: schema.TypeString,
mkSecurityGroupComment: schema.TypeString,
mkRules: schema.TypeList,
})
}

View File

@ -1,27 +0,0 @@
/*
* 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 firewall
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
mkSecurityGroupsSecurityGroupNames = "security_group_names"
)
// SecurityGroupsSchema defines the schema for the security groups.
func SecurityGroupsSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
mkSecurityGroupsSecurityGroupNames: {
Type: schema.TypeList,
Description: "Security Group Names",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
}
}

View File

@ -1,37 +0,0 @@
/*
* 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 firewall
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
)
// TestSecurityGroupsSchemaInstantiation tests whether the SecurityGroupsSchema instance can be instantiated.
func TestSecurityGroupsSchemaInstantiation(t *testing.T) {
t.Parallel()
require.NotNil(t, SecurityGroupsSchema(), "Cannot instantiate SecurityGroupsSchema")
}
// TestSecurityGroupsSchema tests the SecurityGroupsSchema.
func TestSecurityGroupsSchema(t *testing.T) {
t.Parallel()
s := SecurityGroupsSchema()
test.AssertComputedAttributes(t, s, []string{
mkSecurityGroupsSecurityGroupNames,
})
test.AssertValueTypes(t, s, map[string]schema.ValueType{
mkSecurityGroupsSecurityGroupNames: schema.TypeList,
})
}

View File

@ -5512,7 +5512,7 @@ func getDiskDatastores(vm *vms.GetResponseData, d *schema.ResourceData) []string
datastoresSet[fileIDParts[0]] = 1
}
datastores := []string{}
var datastores []string //nolint: prealloc
for datastore := range datastoresSet {
datastores = append(datastores, datastore)
}

View File

@ -1,6 +1,5 @@
version: "1.0"
# renovate: datasource=docker depName=jetbrains/qodana-go
linter: jetbrains/qodana-go:2024.1
linter: jetbrains/qodana-go:latest
include:
- name: CheckDependencyLicenses
- name: RegExpRedundantEscape

View File

@ -1,10 +1,17 @@
/*
* 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 utils
// ConvertToStringSlice helps convert interface slice to string slice.
func ConvertToStringSlice(interfaceSlice []interface{}) []string {
resultSlice := []string{}
for _, val := range interfaceSlice {
resultSlice = append(resultSlice, val.(string))
resultSlice := make([]string, len(interfaceSlice))
for i, val := range interfaceSlice {
resultSlice[i] = val.(string)
}
return resultSlice