diff --git a/.golangci.yml b/.golangci.yml index dcd832b6..026b3360 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,18 +1,106 @@ linters: - # TODO: remove the `disable` section - disable: - - errcheck - - ineffassign - - staticcheck - - unused enable: + - gci - godot - gofmt - misspell - whitespace - - gci + - revive +issues: + exclude-use-default: false linters-settings: gci: sections: - standard - default + errcheck: + exclude-functions: + - (*os.File).Close + revive: + rules: + ## https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#exported + #- name: exported + # arguments: + # - "checkPrivateReceivers" + # - "disableStutteringCheck" + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#unchecked-type-assertion + - name: unchecked-type-assertion + arguments: + - { "acceptIgnoredAssertionResult": true } + + ## https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#var-naming + #- name: var-naming + # arguments: # The arguments here are quite odd looking. See the rule description. + # - [ ] + # - [ ] + # - [ { "upperCaseConst": true } ] + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#early-return + - name: early-return + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#redundant-import-alias + - name: redundant-import-alias + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#redefines-builtin-id + - name: redefines-builtin-id + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#struct-tag + - name: struct-tag + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#receiver-naming + - name: receiver-naming + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#deep-exit + - name: deep-exit + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#bool-literal-in-expr + - name: bool-literal-in-expr + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#comment-spacings + - name: comment-spacings + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#confusing-results + - name: confusing-results + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#use-any + - name: use-any + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#bare-return + - name: bare-return + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#empty-block + - name: empty-block + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#range-val-address + - name: range-val-address + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#range-val-in-closure + - name: range-val-in-closure + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#var-declaration + - name: var-declaration + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#useless-break + - name: useless-break + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#error-naming + - name: error-naming + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#indent-error-flow + - name: indent-error-flow + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#datarace + - name: datarace + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#modifies-value-receiver + - name: modifies-value-receiver + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#empty-lines + - name: empty-lines + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#duplicated-imports + - name: duplicated-imports + + # https://github.com/mgechev/revive/blob/2a1701aadbedfcc175cb92836a51407bec382652/RULES_DESCRIPTIONS.md#error-return + - name: error-return diff --git a/Makefile b/Makefile index b2da4bd6..a979ec65 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ static-analysis: .PHONY: update-gomod update-gomod: $(GO) get -t -v -u ./... - $(GO) mod tidy --go=1.23.3 + $(GO) mod tidy $(GO) get toolchain@none @echo "Dependencies updated" diff --git a/internal/acctest/checks.go b/internal/acctest/checks.go index 4d8370de..32edc245 100644 --- a/internal/acctest/checks.go +++ b/internal/acctest/checks.go @@ -121,7 +121,7 @@ func PreCheckLocalServerHTTPS(t *testing.T) { t.Skip(`Skipping remote provider test. LXD is not available on "https://127.0.0.1:8443"`) } - conn.Close() + _ = conn.Close() } // ConfigureTrustPassword sets and returns the trust password. If the server diff --git a/internal/common/lxd_exec.go b/internal/common/lxd_exec.go index b4429b7f..4810caaa 100644 --- a/internal/common/lxd_exec.go +++ b/internal/common/lxd_exec.go @@ -13,6 +13,7 @@ import ( "github.com/terraform-lxd/terraform-provider-lxd/internal/utils" ) +// ExecTriggerType represents an exec trigger. type ExecTriggerType string const ( @@ -25,6 +26,7 @@ func (t ExecTriggerType) String() string { return string(t) } +// ExecModel represents exec command to be executed on LXD instance. type ExecModel struct { Command types.List `tfsdk:"command"` Environment types.Map `tfsdk:"environment"` diff --git a/internal/common/lxd_import.go b/internal/common/lxd_import.go index 3a6ba98f..3140757c 100644 --- a/internal/common/lxd_import.go +++ b/internal/common/lxd_import.go @@ -37,25 +37,25 @@ type ImportMetadata struct { // "image": "jammy" // option // "optKey2": "value" // option // } -func (m ImportMetadata) ParseImportID(importId string) (map[string]string, diag.Diagnostic) { - if strings.TrimSpace(importId) == "" { - return nil, newImportIDError(m, importId, fmt.Errorf("Import ID cannot be empty")) +func (m ImportMetadata) ParseImportID(importID string) (map[string]string, diag.Diagnostic) { + if strings.TrimSpace(importID) == "" { + return nil, newImportIDError(m, importID, fmt.Errorf("Import ID cannot be empty")) } // First split by comma to determine mandatory and optional parts. - parts := strings.Split(importId, ",") + parts := strings.Split(importID, ",") // Extract fields (including project and remote) from first part. result, err := processFields(parts[0], m.RequiredFields) if err != nil { - return nil, newImportIDError(m, importId, err) + return nil, newImportIDError(m, importID, err) } // Extract options. if len(parts) > 1 { options, err := processOptions(parts[1:], m.AllowedOptions) if err != nil { - return nil, newImportIDError(m, importId, err) + return nil, newImportIDError(m, importID, err) } for k, v := range options { @@ -142,7 +142,7 @@ func processOptions(options []string, allowedOptions []string) (map[string]strin } // newImportIDError converts an error into terraform diagnostic. -func newImportIDError(m ImportMetadata, importId string, err error) diag.Diagnostic { +func newImportIDError(m ImportMetadata, importID string, err error) diag.Diagnostic { remote := "[:]" project := "[/]" if len(m.RequiredFields) > 1 { @@ -157,7 +157,7 @@ func newImportIDError(m ImportMetadata, importId string, err error) diag.Diagnos fields := fmt.Sprintf("<%s>", strings.Join(m.RequiredFields, ">/<")) return diag.NewErrorDiagnostic( - fmt.Sprintf("Invalid import ID: %q", importId), + fmt.Sprintf("Invalid import ID: %q", importID), fmt.Sprintf( "%v.\n\nValid import format:\nimport lxd_%s. %s%s%s%s", err, m.ResourceName, remote, project, fields, options, diff --git a/internal/common/lxd_interface.go b/internal/common/lxd_interface.go index b6094261..ef376229 100644 --- a/internal/common/lxd_interface.go +++ b/internal/common/lxd_interface.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -// Interface represents LXD instance network interface. +// InterfaceModel represents LXD instance network interface. type InterfaceModel struct { // Real name of the interface within the instance. If config interface is // defined as "eth0", the real interface within a container will have the @@ -27,7 +27,7 @@ type InterfaceModel struct { Addresses types.List `tfsdk:"ips"` } -// Interface IP is a wrapper of the interface IP address. +// IPModel is a wrapper of the interface IP address. type IPModel struct { // IP address. Address types.String `tfsdk:"address"` diff --git a/internal/image/resource_publish_image.go b/internal/image/resource_publish_image.go index 20465681..6282f117 100644 --- a/internal/image/resource_publish_image.go +++ b/internal/image/resource_publish_image.go @@ -267,7 +267,12 @@ func (r PublishImageResource) Create(ctx context.Context, req resource.CreateReq // Extract fingerprint from operation response. opResp := op.Get() - imageFingerprint := opResp.Metadata["fingerprint"].(string) + imageFingerprint, ok := opResp.Metadata["fingerprint"].(string) + if !ok { + resp.Diagnostics.AddError("Failed to extract fingerprint from operation response", "") + return + } + plan.Fingerprint = types.StringValue(imageFingerprint) // Update Terraform state. @@ -418,7 +423,7 @@ func (r PublishImageResource) Delete(ctx context.Context, req resource.DeleteReq // SyncState fetches the server's current state for a published image and // updates the provided model. It then applies this updated model as the // new state in Terraform. -func (_ PublishImageResource) SyncState(ctx context.Context, tfState *tfsdk.State, server lxd.InstanceServer, m PublishImageModel) diag.Diagnostics { +func (r PublishImageResource) SyncState(ctx context.Context, tfState *tfsdk.State, server lxd.InstanceServer, m PublishImageModel) diag.Diagnostics { var respDiags diag.Diagnostics imageFingerprint := m.Fingerprint.ValueString() diff --git a/internal/instance/resource_instance.go b/internal/instance/resource_instance.go index 25a51255..6069b8d2 100644 --- a/internal/instance/resource_instance.go +++ b/internal/instance/resource_instance.go @@ -959,16 +959,16 @@ func (r InstanceResource) Update(ctx context.Context, req resource.UpdateRequest // Execute commands. for _, k := range utils.SortMapKeys(newExecs) { - new := newExecs[k] - old := oldExecs[k] + newExec := newExecs[k] + oldExec := oldExecs[k] // Copy run count from state (if exists). - if old != nil { - new.RunCount = old.RunCount + if oldExec != nil { + newExec.RunCount = oldExec.RunCount } - if instanceRunning && new.IsTriggered(instanceStarted) { - diags := new.Execute(ctx, server, instance.Name) + if instanceRunning && newExec.IsTriggered(instanceStarted) { + diags := newExec.Execute(ctx, server, instance.Name) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -1195,7 +1195,7 @@ func (r InstanceResource) SyncState(ctx context.Context, tfState *tfsdk.State, s } // ComputedKeys returns list of computed config keys. -func (_ InstanceModel) ComputedKeys() []string { +func (m InstanceModel) ComputedKeys() []string { return []string{ "image.", "volatile.", diff --git a/internal/instance/resource_instance_file.go b/internal/instance/resource_instance_file.go index 9a8e7866..51f2f45b 100644 --- a/internal/instance/resource_instance_file.go +++ b/internal/instance/resource_instance_file.go @@ -335,12 +335,16 @@ func (r InstanceFileResource) Delete(ctx context.Context, req resource.DeleteReq // createFileResourceID creates new file ID by concatenating remote, // instnaceName, and targetPath using colon. func createFileResourceID(remote string, instanceName string, targetPath string) string { - return fmt.Sprintf("%s:%s:%s", remote, instanceName, targetPath) + return remote + ":" + instanceName + ":" + targetPath } // splitFileResourceID splits file ID into remote, intanceName, and // targetPath strings. -func splitFileResourceID(id string) (string, string, string) { +func splitFileResourceID(id string) (remote string, instanceName string, targetPath string) { pieces := strings.SplitN(id, ":", 3) + if len(pieces) != 3 { + return "", "", "" + } + return pieces[0], pieces[1], pieces[2] } diff --git a/internal/instance/resource_instance_snapshot.go b/internal/instance/resource_instance_snapshot.go index 7f7af56f..689d787e 100644 --- a/internal/instance/resource_instance_snapshot.go +++ b/internal/instance/resource_instance_snapshot.go @@ -152,16 +152,16 @@ func (r InstanceSnapshotResource) Create(ctx context.Context, req resource.Creat // Wait for snapshot operation to complete. serr = op.Wait() - if serr != nil { - if snapshotReq.Stateful && strings.Contains(serr.Error(), "Dumping FAILED") { - log.Printf("[DEBUG] Error creating stateful snapshot [retry %d]: %v", i, serr) - time.Sleep(3 * time.Second) - } else if strings.Contains(serr.Error(), "file has vanished") { - // Ignore, try again. - time.Sleep(3 * time.Second) - } else { - break - } + if serr == nil { + break + } + + if snapshotReq.Stateful && strings.Contains(serr.Error(), "Dumping FAILED") { + log.Printf("[DEBUG] Error creating stateful snapshot [retry %d]: %v", i, serr) + time.Sleep(3 * time.Second) + } else if strings.Contains(serr.Error(), "file has vanished") { + // Ignore, try again. + time.Sleep(3 * time.Second) } else { break } diff --git a/internal/network/resource_network.go b/internal/network/resource_network.go index b1ce55ff..65a3cd0b 100644 --- a/internal/network/resource_network.go +++ b/internal/network/resource_network.go @@ -343,7 +343,7 @@ func (r NetworkResource) SyncState(ctx context.Context, tfState *tfsdk.State, se } // ComputedKeys returns list of computed LXD config keys. -func (_ NetworkModel) ComputedKeys() []string { +func (m NetworkModel) ComputedKeys() []string { return []string{ "bridge.mtu", "ipv4.address", diff --git a/internal/network/resource_network_forward.go b/internal/network/resource_network_forward.go index e784846b..a4f34754 100644 --- a/internal/network/resource_network_forward.go +++ b/internal/network/resource_network_forward.go @@ -35,7 +35,7 @@ type NetworkForwardModel struct { Config types.Map `tfsdk:"config"` } -// NetworkForwardModel resource data model that matches the schema. +// NetworkForwardPortModel resource data model that matches the schema. type NetworkForwardPortModel struct { Description types.String `tfsdk:"description"` Protocol types.String `tfsdk:"protocol"` diff --git a/internal/profile/resource_profile.go b/internal/profile/resource_profile.go index cff46231..b4e667af 100644 --- a/internal/profile/resource_profile.go +++ b/internal/profile/resource_profile.go @@ -26,6 +26,7 @@ import ( provider_config "github.com/terraform-lxd/terraform-provider-lxd/internal/provider-config" ) +// ProfileModel represents a LXD profile. type ProfileModel struct { Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` diff --git a/internal/project/resource_project.go b/internal/project/resource_project.go index db3c4183..5004ded7 100644 --- a/internal/project/resource_project.go +++ b/internal/project/resource_project.go @@ -295,7 +295,7 @@ func (r ProjectResource) SyncState(ctx context.Context, tfState *tfsdk.State, se } // ComputedKeys returns list of computed config keys. -func (_ ProjectModel) ComputedKeys() []string { +func (m ProjectModel) ComputedKeys() []string { return []string{ "features.images", "features.profiles", diff --git a/internal/provider-config/config.go b/internal/provider-config/config.go index b0a3a7c9..2d7d37db 100644 --- a/internal/provider-config/config.go +++ b/internal/provider-config/config.go @@ -224,7 +224,11 @@ func (p *LxdProviderConfig) InstanceServer(remoteName string, project string, ta return nil, fmt.Errorf("Remote %q (%s) is not an InstanceServer", remoteName, connInfo.Protocol) } - instServer := server.(lxd.InstanceServer) + instServer, ok := server.(lxd.InstanceServer) + if !ok { + return nil, fmt.Errorf("Remote %q is not an InstanceServer", remoteName) + } + instServer = instServer.UseProject(project) instServer = instServer.UseTarget(target) @@ -248,7 +252,12 @@ func (p *LxdProviderConfig) ImageServer(remoteName string) (lxd.ImageServer, err return nil, fmt.Errorf("Remote %q (%s / %s) is not an ImageServer", remoteName, connInfo.Protocol, connInfo.Addresses[0]) } - return server.(lxd.ImageServer), nil + imageServer, ok := server.(lxd.ImageServer) + if !ok { + return nil, fmt.Errorf("Remote %q is not an ImageServer", remoteName) + } + + return imageServer, nil } // server returns a server for the named remote. The returned server diff --git a/internal/provider/provider.go b/internal/provider/provider.go index fea16a95..3a2ec052 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -20,7 +20,6 @@ import ( "github.com/terraform-lxd/terraform-provider-lxd/internal/network" "github.com/terraform-lxd/terraform-provider-lxd/internal/profile" "github.com/terraform-lxd/terraform-provider-lxd/internal/project" - config "github.com/terraform-lxd/terraform-provider-lxd/internal/provider-config" provider_config "github.com/terraform-lxd/terraform-provider-lxd/internal/provider-config" "github.com/terraform-lxd/terraform-provider-lxd/internal/storage" "github.com/terraform-lxd/terraform-provider-lxd/internal/truststore" @@ -182,7 +181,7 @@ func (p *LxdProvider) Configure(ctx context.Context, req provider.ConfigureReque } } - remotes := make(map[string]config.LxdRemote) + remotes := make(map[string]provider_config.LxdRemote) // Read remotes from Terraform schema. for _, remote := range data.Remotes { @@ -193,7 +192,7 @@ func (p *LxdProvider) Configure(ctx context.Context, req provider.ConfigureReque protocol = "lxd" } - address, err := config.DetermineLXDAddress(protocol, remote.Address.ValueString()) + address, err := provider_config.DetermineLXDAddress(protocol, remote.Address.ValueString()) if err != nil { resp.Diagnostics.AddError(fmt.Sprintf("Invalid remote %q", name), err.Error()) return diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 7825f9a4..54e2851d 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -74,9 +74,9 @@ MDEtMDEtMDFUMDA6MDA6MDBaIgp9Cg==` // as environment variable. PreConfig: func() { configDir = t.TempDir() - os.Setenv("LXD_REMOTE", "tf-remote-token-fqdn") - os.Setenv("LXD_ADDR", "https://127.0.0.1:8443") - os.Setenv("LXD_TOKEN", acctest.ConfigureTrustToken(t)) + _ = os.Setenv("LXD_REMOTE", "tf-remote-token-fqdn") + _ = os.Setenv("LXD_ADDR", "https://127.0.0.1:8443") + _ = os.Setenv("LXD_TOKEN", acctest.ConfigureTrustToken(t)) }, Config: testAccProvider_remoteServerEnv(configDir), Check: resource.ComposeTestCheckFunc( @@ -121,9 +121,9 @@ func TestAccProvider_trustPassword(t *testing.T) { // as environment variable. PreConfig: func() { configDir = t.TempDir() - os.Setenv("LXD_REMOTE", "tf-remote-pass-fqdn") - os.Setenv("LXD_ADDR", "https://127.0.0.1:8443") - os.Setenv("LXD_PASSWORD", acctest.ConfigureTrustPassword(t)) + _ = os.Setenv("LXD_REMOTE", "tf-remote-pass-fqdn") + _ = os.Setenv("LXD_ADDR", "https://127.0.0.1:8443") + _ = os.Setenv("LXD_PASSWORD", acctest.ConfigureTrustPassword(t)) }, Config: testAccProvider_remoteServerEnv(configDir), Check: resource.ComposeTestCheckFunc( @@ -329,8 +329,8 @@ func testCheckClientCert(configDir string, shouldExist bool) resource.TestCheckF // resetLXDRemoteEnvVars unsets all environment variables that are supported by // the provider. func resetLXDRemoteEnvVars() { - os.Unsetenv("LXD_REMOTE") - os.Unsetenv("LXD_ADDR") - os.Unsetenv("LXD_PASSWORD") - os.Unsetenv("LXD_TOKEN") + _ = os.Unsetenv("LXD_REMOTE") + _ = os.Unsetenv("LXD_ADDR") + _ = os.Unsetenv("LXD_PASSWORD") + _ = os.Unsetenv("LXD_TOKEN") } diff --git a/internal/storage/resource_storage_bucket.go b/internal/storage/resource_storage_bucket.go index 40360834..5b4eb2f2 100644 --- a/internal/storage/resource_storage_bucket.go +++ b/internal/storage/resource_storage_bucket.go @@ -335,7 +335,7 @@ func (r StorageBucketResource) SyncState(ctx context.Context, tfState *tfsdk.Sta } // ComputedKeys returns list of computed config keys. -func (_ StorageBucketModel) ComputedKeys() []string { +func (m StorageBucketModel) ComputedKeys() []string { return []string{ "block.filesystem", "block.mount_options", diff --git a/internal/storage/resource_storage_bucket_key.go b/internal/storage/resource_storage_bucket_key.go index 8511e5f4..df3a251c 100644 --- a/internal/storage/resource_storage_bucket_key.go +++ b/internal/storage/resource_storage_bucket_key.go @@ -22,6 +22,7 @@ import ( provider_config "github.com/terraform-lxd/terraform-provider-lxd/internal/provider-config" ) +// StorageBucketKeyModel represents a LXD storage bucket key. type StorageBucketKeyModel struct { Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` diff --git a/internal/storage/resource_storage_pool.go b/internal/storage/resource_storage_pool.go index f26918da..53435784 100644 --- a/internal/storage/resource_storage_pool.go +++ b/internal/storage/resource_storage_pool.go @@ -25,6 +25,7 @@ import ( provider_config "github.com/terraform-lxd/terraform-provider-lxd/internal/provider-config" ) +// StoragePoolModel represents a LXD storage pool. type StoragePoolModel struct { Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` @@ -347,7 +348,7 @@ func (r StoragePoolResource) SyncState(ctx context.Context, tfState *tfsdk.State } // ComputedKeys returns list of computed config keys. -func (_ StoragePoolModel) ComputedKeys(driver string) []string { +func (m StoragePoolModel) ComputedKeys(driver string) []string { var keys []string switch driver { diff --git a/internal/storage/resource_storage_volume.go b/internal/storage/resource_storage_volume.go index 19bc1979..16f954da 100644 --- a/internal/storage/resource_storage_volume.go +++ b/internal/storage/resource_storage_volume.go @@ -382,7 +382,7 @@ func (r StorageVolumeResource) SyncState(ctx context.Context, tfState *tfsdk.Sta } // ComputedKeys returns list of computed config keys. -func (_ StorageVolumeModel) ComputedKeys() []string { +func (m StorageVolumeModel) ComputedKeys() []string { return []string{ "block.filesystem", "block.mount_options", @@ -390,7 +390,7 @@ func (_ StorageVolumeModel) ComputedKeys() []string { } } -func (_ StorageVolumeModel) InheritedStoragePoolVolumeKeys(server lxd.InstanceServer, poolName string) ([]string, error) { +func (m StorageVolumeModel) InheritedStoragePoolVolumeKeys(server lxd.InstanceServer, poolName string) ([]string, error) { pool, _, err := server.GetStoragePool(poolName) if err != nil { return nil, err diff --git a/internal/storage/resource_storage_volume_copy.go b/internal/storage/resource_storage_volume_copy.go index 8f23a843..dc7eceb7 100644 --- a/internal/storage/resource_storage_volume_copy.go +++ b/internal/storage/resource_storage_volume_copy.go @@ -17,6 +17,7 @@ import ( provider_config "github.com/terraform-lxd/terraform-provider-lxd/internal/provider-config" ) +// StorageVolumeCopyModel represents a LXD storage volume copy. type StorageVolumeCopyModel struct { Name types.String `tfsdk:"name"` Pool types.String `tfsdk:"pool"` diff --git a/internal/utils/buffer.go b/internal/utils/buffer.go index 373e4d3d..422c8554 100644 --- a/internal/utils/buffer.go +++ b/internal/utils/buffer.go @@ -20,7 +20,7 @@ type bufferCloser struct { mux *sync.RWMutex } -// BufferCloser returns a buffer that wraps bytes.Buffer and satisfies +// NewBufferCloser returns a buffer that wraps bytes.Buffer and satisfies // io.Closer. func NewBufferCloser() Buffer { return bufferCloser{ @@ -58,18 +58,22 @@ func NewDiscardCloser() Buffer { return discardCloser{} } +// Write provides a nop implementation for io.discardCloser. func (b discardCloser) Write(p []byte) (int, error) { return len(p), nil } +// Read provides a nop implementation for io.discardCloser. func (b discardCloser) Read(p []byte) (int, error) { return len(p), nil } +// Close provides a nop implementation for io.discardCloser. func (b discardCloser) Close() error { return nil } +// String implements fmt.Stringer for io.discardCloser. func (b discardCloser) String() string { return "" } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index fa6ff214..4f055bcc 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -71,7 +71,7 @@ func SortMapKeys[T any](m map[string]T) []string { return keys } -// DiffSlice compares two slices and returns removed and added elements. +// DiffSlices compares two slices and returns removed and added elements. // Note: Does not find differences for duplicate elemnts. func DiffSlices[T comparable](sliceA []T, sliceB []T) (removed []T, added []T) { mapA := make(map[T]bool, len(sliceA))