diff --git a/fwprovider/cluster/acme/resource_acme_account.go b/fwprovider/cluster/acme/resource_acme_account.go index 4b9d3cf3..15f5dc3a 100644 --- a/fwprovider/cluster/acme/resource_acme_account.go +++ b/fwprovider/cluster/acme/resource_acme_account.go @@ -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( diff --git a/fwprovider/cluster/ha/hagroup_model.go b/fwprovider/cluster/ha/hagroup_model.go index d8ba151f..6382f65f 100644 --- a/fwprovider/cluster/ha/hagroup_model.go +++ b/fwprovider/cluster/ha/hagroup_model.go @@ -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) diff --git a/fwprovider/cluster/ha/resource_hagroup.go b/fwprovider/cluster/ha/resource_hagroup.go index 78b5921a..87c0a23d 100644 --- a/fwprovider/cluster/ha/resource_hagroup.go +++ b/fwprovider/cluster/ha/resource_hagroup.go @@ -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()) diff --git a/fwprovider/cluster/ha/resource_haresource.go b/fwprovider/cluster/ha/resource_haresource.go index 62128810..d06274e6 100644 --- a/fwprovider/cluster/ha/resource_haresource.go +++ b/fwprovider/cluster/ha/resource_haresource.go @@ -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 { diff --git a/fwprovider/cluster/hardwaremapping/resource_dir.go b/fwprovider/cluster/hardwaremapping/resource_dir.go index 3eac6cf6..de915a56 100644 --- a/fwprovider/cluster/hardwaremapping/resource_dir.go +++ b/fwprovider/cluster/hardwaremapping/resource_dir.go @@ -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() diff --git a/fwprovider/cluster/hardwaremapping/resource_pci.go b/fwprovider/cluster/hardwaremapping/resource_pci.go index c122affb..2663c692 100644 --- a/fwprovider/cluster/hardwaremapping/resource_pci.go +++ b/fwprovider/cluster/hardwaremapping/resource_pci.go @@ -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() diff --git a/fwprovider/cluster/hardwaremapping/resource_usb.go b/fwprovider/cluster/hardwaremapping/resource_usb.go index 98a52ed4..ad1e6725 100644 --- a/fwprovider/cluster/hardwaremapping/resource_usb.go +++ b/fwprovider/cluster/hardwaremapping/resource_usb.go @@ -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() diff --git a/fwprovider/cluster/metrics/datasource_metrics_server.go b/fwprovider/cluster/metrics/datasource_metrics_server.go index 7f75a05f..aa10996b 100644 --- a/fwprovider/cluster/metrics/datasource_metrics_server.go +++ b/fwprovider/cluster/metrics/datasource_metrics_server.go @@ -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. diff --git a/fwprovider/cluster/metrics/metrics_server_model.go b/fwprovider/cluster/metrics/metrics_server_model.go index ae6d1650..22792895 100644 --- a/fwprovider/cluster/metrics/metrics_server_model.go +++ b/fwprovider/cluster/metrics/metrics_server_model.go @@ -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 { diff --git a/fwprovider/cluster/metrics/resource_metrics_server.go b/fwprovider/cluster/metrics/resource_metrics_server.go index ad2341ef..73a1f263 100644 --- a/fwprovider/cluster/metrics/resource_metrics_server.go +++ b/fwprovider/cluster/metrics/resource_metrics_server.go @@ -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 ( diff --git a/fwprovider/cluster/metrics/resource_metrics_server_test.go b/fwprovider/cluster/metrics/resource_metrics_server_test.go index e6899f99..d4a452f0 100644 --- a/fwprovider/cluster/metrics/resource_metrics_server_test.go +++ b/fwprovider/cluster/metrics/resource_metrics_server_test.go @@ -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) { diff --git a/fwprovider/nodes/apt/models.go b/fwprovider/nodes/apt/models.go index 15895508..3b81c1e0 100644 --- a/fwprovider/nodes/apt/models.go +++ b/fwprovider/nodes/apt/models.go @@ -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. diff --git a/fwprovider/nodes/apt/resource_repo.go b/fwprovider/nodes/apt/resource_repo.go index 7de4d0fc..16ba0b04 100644 --- a/fwprovider/nodes/apt/resource_repo.go +++ b/fwprovider/nodes/apt/resource_repo.go @@ -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 { diff --git a/fwprovider/nodes/apt/resource_standard_repo.go b/fwprovider/nodes/apt/resource_standard_repo.go index ee5e2b45..a5a8bdec 100644 --- a/fwprovider/nodes/apt/resource_standard_repo.go +++ b/fwprovider/nodes/apt/resource_standard_repo.go @@ -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 { diff --git a/fwprovider/types/ip_addr.go b/fwprovider/types/ip_addr.go index a2fc8bc4..46917435 100644 --- a/fwprovider/types/ip_addr.go +++ b/fwprovider/types/ip_addr.go @@ -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 diff --git a/fwprovider/types/ip_cidr.go b/fwprovider/types/ip_cidr.go index ceb3955f..4ccb8671 100644 --- a/fwprovider/types/ip_cidr.go +++ b/fwprovider/types/ip_cidr.go @@ -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 diff --git a/proxmoxtf/resource/cluster/firewall/security_group.go b/proxmoxtf/resource/cluster/firewall/security_group.go index 710d25d9..d72c7d78 100644 --- a/proxmoxtf/resource/cluster/firewall/security_group.go +++ b/proxmoxtf/resource/cluster/firewall/security_group.go @@ -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() diff --git a/proxmoxtf/resource/firewall/ipset.go b/proxmoxtf/resource/firewall/ipset.go index 4e9594d0..94c5b4bf 100644 --- a/proxmoxtf/resource/firewall/ipset.go +++ b/proxmoxtf/resource/firewall/ipset.go @@ -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() diff --git a/proxmoxtf/resource/firewall/rules.go b/proxmoxtf/resource/firewall/rules.go index 8dd68d8d..98707c43 100644 --- a/proxmoxtf/resource/firewall/rules.go +++ b/proxmoxtf/resource/firewall/rules.go @@ -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-- { diff --git a/proxmoxtf/structure/schema.go b/proxmoxtf/structure/schema.go index 76d6f294..50447734 100644 --- a/proxmoxtf/structure/schema.go +++ b/proxmoxtf/structure/schema.go @@ -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 {