From 02a62e747b2a6f5e88e21202228a8d662fb456e1 Mon Sep 17 00:00:00 2001 From: phillc <15082+phillc@users.noreply.github.com> Date: Thu, 25 Feb 2021 10:48:40 -0500 Subject: [PATCH] golangci-lint run --fix --- linode/config.go | 7 +++--- linode/data_source_linode_domain.go | 1 - linode/data_source_linode_volume.go | 2 -- linode/linode_instance_helpers.go | 24 +++++++++---------- linode/resource_linode_domain_record.go | 2 -- linode/resource_linode_firewall.go | 3 ++- linode/resource_linode_instance.go | 6 +---- linode/resource_linode_nodebalancer.go | 1 - linode/resource_linode_nodebalancer_node.go | 1 - .../resource_linode_object_storage_bucket.go | 2 -- linode/resource_linode_object_storage_key.go | 1 - linode/resource_linode_rdns.go | 3 +-- linode/resource_linode_sshkey.go | 1 - linode/resource_linode_stackscript.go | 1 - linode/resource_linode_token.go | 1 - linode/resource_linode_user.go | 3 +-- linode/resource_linode_volume.go | 1 - version/version.go | 6 ++--- 18 files changed, 21 insertions(+), 45 deletions(-) diff --git a/linode/config.go b/linode/config.go index 14e30d57b..0551aed65 100644 --- a/linode/config.go +++ b/linode/config.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" "github.com/hashicorp/terraform-plugin-sdk/v2/meta" - "github.com/linode/linodego" "github.com/linode/terraform-provider-linode/version" "golang.org/x/oauth2" @@ -18,10 +17,10 @@ import ( const uaEnvVar = "TF_APPEND_USER_AGENT" -// DefaultLinodeURL is the Linode APIv4 URL to use +// DefaultLinodeURL is the Linode APIv4 URL to use. const DefaultLinodeURL = "https://api.linode.com/v4" -// Config represents the Linode provider configuration +// Config represents the Linode provider configuration. type Config struct { AccessToken string APIURL string @@ -35,7 +34,7 @@ type Config struct { MaxRetryDelayMilliseconds int } -// Client returns a fully initialized Linode client +// Client returns a fully initialized Linode client. func (c *Config) Client() linodego.Client { tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: c.AccessToken}) oauthTransport := &oauth2.Transport{ diff --git a/linode/data_source_linode_domain.go b/linode/data_source_linode_domain.go index 9bfbbfb55..f48fc0f3a 100644 --- a/linode/data_source_linode_domain.go +++ b/linode/data_source_linode_domain.go @@ -130,7 +130,6 @@ func dataSourceLinodeDomainRead(d *schema.ResourceData, meta interface{}) error } if len(domains) != 1 || domains[0].Domain != reqDomain { return fmt.Errorf("Domain %s was not found", reqDomain) - } domain = &domains[0] } diff --git a/linode/data_source_linode_volume.go b/linode/data_source_linode_volume.go index 3fe6b9ae8..380ae1a73 100644 --- a/linode/data_source_linode_volume.go +++ b/linode/data_source_linode_volume.go @@ -80,7 +80,6 @@ func dataSourceLinodeVolumeRead(d *schema.ResourceData, meta interface{}) error var volume *linodego.Volume volume, err := client.GetVolume(context.Background(), requestedVolumeID) - if err != nil { return fmt.Errorf("Error requesting Volume: %s", err) } @@ -100,5 +99,4 @@ func dataSourceLinodeVolumeRead(d *schema.ResourceData, meta interface{}) error } return fmt.Errorf("Linode Volume %s was not found", fmt.Sprint(requestedVolumeID)) - } diff --git a/linode/linode_instance_helpers.go b/linode/linode_instance_helpers.go index 4cbff6164..803305706 100644 --- a/linode/linode_instance_helpers.go +++ b/linode/linode_instance_helpers.go @@ -181,7 +181,6 @@ func createInstanceConfigsFromSet(client linodego.Client, instanceID int, cset [ configIDMap[instanceConfig.ID] = *instanceConfig } return configIDMap, nil - } func updateInstanceConfigs(client linodego.Client, d *schema.ResourceData, instance linodego.Instance, tfConfigsOld, tfConfigsNew interface{}, diskIDLabelMap map[string]int) (bool, map[string]int, []*linodego.InstanceConfig, error) { @@ -321,10 +320,9 @@ func flattenInstanceConfigDevice(dev *linodego.InstanceConfigDevice, diskLabelID return []map[string]interface{}{{ "volume_id": dev.VolumeID, }} - } -// expandInstanceConfigDeviceMap converts a terraform linode_instance config.*.devices map to a InstanceConfigDeviceMap for the Linode API +// expandInstanceConfigDeviceMap converts a terraform linode_instance config.*.devices map to a InstanceConfigDeviceMap for the Linode API. func expandInstanceConfigDeviceMap(m map[string]interface{}, diskIDLabelMap map[string]int) (deviceMap *linodego.InstanceConfigDeviceMap, err error) { if len(m) == 0 { return nil, nil @@ -345,7 +343,7 @@ func expandInstanceConfigDeviceMap(m map[string]interface{}, diskIDLabelMap map[ return deviceMap, nil } -// changeInstanceConfigDevice returns a copy of a config device map with the specified disk slot changed to the provided device +// changeInstanceConfigDevice returns a copy of a config device map with the specified disk slot changed to the provided device. func changeInstanceConfigDevice(deviceMap linodego.InstanceConfigDeviceMap, namedSlot string, device *linodego.InstanceConfigDevice) linodego.InstanceConfigDeviceMap { tDevice := device if tDevice != nil && emptyInstanceConfigDevice(*tDevice) { @@ -373,12 +371,12 @@ func changeInstanceConfigDevice(deviceMap linodego.InstanceConfigDeviceMap, name return deviceMap } -// emptyInstanceConfigDevice returns true only when neither the disk or volume have been assigned to a config device +// emptyInstanceConfigDevice returns true only when neither the disk or volume have been assigned to a config device. func emptyInstanceConfigDevice(dev linodego.InstanceConfigDevice) bool { return (dev.DiskID == 0 && dev.VolumeID == 0) } -// emptyConfigDeviceMap returns true only when none of the disks in a config device map have been assigned +// emptyConfigDeviceMap returns true only when none of the disks in a config device map have been assigned. func emptyConfigDeviceMap(dmap linodego.InstanceConfigDeviceMap) bool { drives := []*linodego.InstanceConfigDevice{ dmap.SDA, dmap.SDB, dmap.SDC, dmap.SDD, dmap.SDE, dmap.SDF, dmap.SDG, dmap.SDH, @@ -645,17 +643,17 @@ func updateInstanceDisks(client linodego.Client, d *schema.ResourceData, instanc return hasChanges, nil } -// sshKeyState hashes a string passed in as an interface +// sshKeyState hashes a string passed in as an interface. func sshKeyState(val interface{}) string { return hashString(strings.Join(val.([]string), "\n")) } -// rootPasswordState hashes a string passed in as an interface +// rootPasswordState hashes a string passed in as an interface. func rootPasswordState(val interface{}) string { return hashString(val.(string)) } -// hashString hashes a string +// hashString hashes a string. func hashString(key string) string { hash := sha3.Sum512([]byte(key)) return base64.StdEncoding.EncodeToString(hash[:]) @@ -689,7 +687,7 @@ func ensureInstanceOffline(client *linodego.Client, instanceID, timeout int) (in return client.WaitForInstanceStatus(context.Background(), instanceID, linodego.InstanceOffline, timeout) } -// changeInstanceType resizes the Linode Instance +// changeInstanceType resizes the Linode Instance. func changeInstanceType(client *linodego.Client, instanceID int, targetType string, d *schema.ResourceData) (*linodego.Instance, error) { instance, err := ensureInstanceOffline(client, instanceID, int(d.Timeout(schema.TimeoutUpdate))) if err != nil { @@ -717,7 +715,7 @@ func changeInstanceType(client *linodego.Client, instanceID int, targetType stri return instance, nil } -// returns the amount of disk space used by the new plan and old plan +// returns the amount of disk space used by the new plan and old plan. func getDiskSizeChange(oldDisk interface{}, newDisk interface{}) (int, int) { tfDisksOldInterface := oldDisk.([]interface{}) tfDisksNewInterface := newDisk.([]interface{}) @@ -831,7 +829,7 @@ func getInstanceTypeChange(d *schema.ResourceData, client *linodego.Client) (old // applyInstanceDiskSpec checks to see if the staged disk changes can be supported by the instance specification's // capacity. If there is sufficient space, it attempts to update the disks. // -// returns bool describing whether change has occurred +// returns bool describing whether change has occurred. func applyInstanceDiskSpec( d *schema.ResourceData, client *linodego.Client, @@ -871,7 +869,7 @@ func applyInstanceTypeChange( return changeInstanceType(client, instance.ID, typ.ID, d) } -// detachConfigVolumes detaches any volumes associated with an InstanceConfig.Devices struct +// detachConfigVolumes detaches any volumes associated with an InstanceConfig.Devices struct. func detachConfigVolumes(dmap linodego.InstanceConfigDeviceMap, detacher volumeDetacher) error { // Preallocate our slice of config devices drives := []*linodego.InstanceConfigDevice{ diff --git a/linode/resource_linode_domain_record.go b/linode/resource_linode_domain_record.go index 4cd12a395..c5b0b8db1 100644 --- a/linode/resource_linode_domain_record.go +++ b/linode/resource_linode_domain_record.go @@ -132,7 +132,6 @@ func resourceLinodeDomainRecordRead(d *schema.ResourceData, meta interface{}) er } domainID := d.Get("domain_id").(int) record, err := client.GetDomainRecord(context.Background(), int(domainID), int(id)) - if err != nil { if lerr, ok := err.(*linodego.Error); ok && lerr.Code == 404 { log.Printf("[WARN] removing Linode Domain Record ID %q from state because it no longer exists", d.Id()) @@ -280,7 +279,6 @@ func resourceLinodeDomainRecordDelete(d *schema.ResourceData, meta interface{}) client := meta.(*ProviderMeta).Client domainID := d.Get("domain_id").(int) id, err := strconv.ParseInt(d.Id(), 10, 64) - if err != nil { return fmt.Errorf("Error parsing Linode DomainRecord id %s as int", d.Id()) } diff --git a/linode/resource_linode_firewall.go b/linode/resource_linode_firewall.go index 60a0d4632..abcf2969c 100644 --- a/linode/resource_linode_firewall.go +++ b/linode/resource_linode_firewall.go @@ -4,10 +4,11 @@ import ( "context" "errors" "fmt" + "strconv" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/linode/linodego" - "strconv" ) func resourceLinodeFirewallRule() *schema.Resource { diff --git a/linode/resource_linode_instance.go b/linode/resource_linode_instance.go index 9ddf57d3e..759d38380 100644 --- a/linode/resource_linode_instance.go +++ b/linode/resource_linode_instance.go @@ -606,7 +606,6 @@ func resourceLinodeInstanceRead(d *schema.ResourceData, meta interface{}) error } instance, err := client.GetInstance(context.Background(), int(id)) - if err != nil { if lerr, ok := err.(*linodego.Error); ok && lerr.Code == 404 { log.Printf("[WARN] removing Linode Instance ID %q from state because it no longer exists", d.Id()) @@ -618,7 +617,6 @@ func resourceLinodeInstanceRead(d *schema.ResourceData, meta interface{}) error } instanceNetwork, err := client.GetInstanceIPAddresses(context.Background(), int(id)) - if err != nil { return fmt.Errorf("Error getting the IPs for Linode instance %s: %s", d.Id(), err) } @@ -676,14 +674,12 @@ func resourceLinodeInstanceRead(d *schema.ResourceData, meta interface{}) error d.Set("swap_size", swapSize) instanceConfigs, err := client.ListInstanceConfigs(context.Background(), int(id), nil) - if err != nil { return fmt.Errorf("Error getting the config for Linode instance %d (%s): %s", instance.ID, instance.Label, err) } diskLabelIDMap := make(map[int]string, len(instanceDisks)) for _, disk := range instanceDisks { diskLabelIDMap[disk.ID] = disk.Label - } configs := flattenInstanceConfigs(instanceConfigs, diskLabelIDMap) @@ -890,7 +886,7 @@ func findDiskByFS(disks []linodego.InstanceDisk, fs linodego.DiskFilesystem) *li // adjustSwapSizeIfNeeded handles changes to the swap_size attribute if needed. If there is a change, this means resizing // the underlying main/swap disks on the instance to match the declared swap size allocation. // -// returns bool describing whether the linode needs to be restarted +// returns bool describing whether the linode needs to be restarted. func adjustSwapSizeIfNeeded(d *schema.ResourceData, client *linodego.Client, instance *linodego.Instance) (bool, error) { if !d.HasChange("swap_size") { return false, nil diff --git a/linode/resource_linode_nodebalancer.go b/linode/resource_linode_nodebalancer.go index d5a96b949..4acb6e328 100644 --- a/linode/resource_linode_nodebalancer.go +++ b/linode/resource_linode_nodebalancer.go @@ -105,7 +105,6 @@ func resourceLinodeNodeBalancerRead(d *schema.ResourceData, meta interface{}) er } nodebalancer, err := client.GetNodeBalancer(context.Background(), int(id)) - if err != nil { if lerr, ok := err.(*linodego.Error); ok && lerr.Code == 404 { log.Printf("[WARN] removing Linode NodeBalancer ID %q from state because it no longer exists", d.Id()) diff --git a/linode/resource_linode_nodebalancer_node.go b/linode/resource_linode_nodebalancer_node.go index a80bb6fdb..c87483a8e 100644 --- a/linode/resource_linode_nodebalancer_node.go +++ b/linode/resource_linode_nodebalancer_node.go @@ -83,7 +83,6 @@ func resourceLinodeNodeBalancerNodeRead(d *schema.ResourceData, meta interface{} } node, err := client.GetNodeBalancerNode(context.Background(), nodebalancerID, configID, int(id)) - if err != nil { if lerr, ok := err.(*linodego.Error); ok && lerr.Code == 404 { log.Printf("[WARN] removing NodeBalancer Node ID %q from state because it no longer exists", d.Id()) diff --git a/linode/resource_linode_object_storage_bucket.go b/linode/resource_linode_object_storage_bucket.go index c5111b0fc..f607ea9f8 100644 --- a/linode/resource_linode_object_storage_bucket.go +++ b/linode/resource_linode_object_storage_bucket.go @@ -59,13 +59,11 @@ func resourceLinodeObjectStorageBucket() *schema.Resource { func resourceLinodeObjectStorageBucketRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*ProviderMeta).Client cluster, label, err := decodeLinodeObjectStorageBucketID(d.Id()) - if err != nil { return fmt.Errorf("Error parsing Linode ObjectStorageBucket id %s", d.Id()) } bucket, err := client.GetObjectStorageBucket(context.Background(), cluster, label) - if err != nil { return fmt.Errorf("Error finding the specified Linode ObjectStorageBucket: %s", err) } diff --git a/linode/resource_linode_object_storage_key.go b/linode/resource_linode_object_storage_key.go index 099942b35..bfeea794e 100644 --- a/linode/resource_linode_object_storage_key.go +++ b/linode/resource_linode_object_storage_key.go @@ -106,7 +106,6 @@ func resourceLinodeObjectStorageKeyRead(d *schema.ResourceData, meta interface{} } objectStorageKey, err := client.GetObjectStorageKey(context.Background(), int(id)) - if err != nil { return fmt.Errorf("Error finding the specified Linode Object Storage Key: %s", err) } diff --git a/linode/resource_linode_rdns.go b/linode/resource_linode_rdns.go index f4c27838c..4fc93f2a9 100644 --- a/linode/resource_linode_rdns.go +++ b/linode/resource_linode_rdns.go @@ -45,7 +45,6 @@ func resourceLinodeRDNSRead(d *schema.ResourceData, meta interface{}) error { } ip, err := client.GetIPAddress(context.Background(), ipStr) - if err != nil { return fmt.Errorf("Error finding the specified Linode RDNS: %s", err) } @@ -59,7 +58,7 @@ func resourceLinodeRDNSRead(d *schema.ResourceData, meta interface{}) error { func resourceLinodeRDNSCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ProviderMeta).Client - var address = d.Get("address").(string) + address := d.Get("address").(string) var rdns *string if rdnsRaw, ok := d.GetOk("rdns"); ok && len(rdnsRaw.(string)) > 0 { rdnsStr := rdnsRaw.(string) diff --git a/linode/resource_linode_sshkey.go b/linode/resource_linode_sshkey.go index 57e4edcab..e682e575b 100644 --- a/linode/resource_linode_sshkey.go +++ b/linode/resource_linode_sshkey.go @@ -48,7 +48,6 @@ func resourceLinodeSSHKeyRead(d *schema.ResourceData, meta interface{}) error { } sshkey, err := client.GetSSHKey(context.Background(), int(id)) - if err != nil { return fmt.Errorf("Error finding the specified Linode SSH Key: %s", err) } diff --git a/linode/resource_linode_stackscript.go b/linode/resource_linode_stackscript.go index bf6ca3a68..dada66335 100644 --- a/linode/resource_linode_stackscript.go +++ b/linode/resource_linode_stackscript.go @@ -131,7 +131,6 @@ func resourceLinodeStackscriptRead(d *schema.ResourceData, meta interface{}) err } stackscript, err := client.GetStackscript(context.Background(), int(id)) - if err != nil { if lerr, ok := err.(*linodego.Error); ok && lerr.Code == 404 { log.Printf("[WARN] removing StackScript ID %q from state because it no longer exists", d.Id()) diff --git a/linode/resource_linode_token.go b/linode/resource_linode_token.go index ec9ba1a42..978736043 100644 --- a/linode/resource_linode_token.go +++ b/linode/resource_linode_token.go @@ -88,7 +88,6 @@ func resourceLinodeTokenRead(d *schema.ResourceData, meta interface{}) error { } token, err := client.GetToken(context.Background(), int(id)) - if err != nil { return fmt.Errorf("Error finding the specified Linode Token: %s", err) } diff --git a/linode/resource_linode_user.go b/linode/resource_linode_user.go index 156dac616..41ec1dc51 100644 --- a/linode/resource_linode_user.go +++ b/linode/resource_linode_user.go @@ -3,10 +3,9 @@ package linode import ( "context" - "github.com/linode/linodego" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/linode/linodego" ) func resourceLinodeUser() *schema.Resource { diff --git a/linode/resource_linode_volume.go b/linode/resource_linode_volume.go index acfe89263..afd455b90 100644 --- a/linode/resource_linode_volume.go +++ b/linode/resource_linode_volume.go @@ -84,7 +84,6 @@ func resourceLinodeVolumeRead(d *schema.ResourceData, meta interface{}) error { } volume, err := client.GetVolume(context.Background(), int(id)) - if err != nil { if lerr, ok := err.(*linodego.Error); ok && lerr.Code == 404 { log.Printf("[WARN] removing Volume ID %q from state because it no longer exists", d.Id()) diff --git a/version/version.go b/version/version.go index 50b6f20ed..8b08f6b4d 100644 --- a/version/version.go +++ b/version/version.go @@ -1,6 +1,4 @@ package version -var ( - // ProviderVersion is set at build-time in the release process - ProviderVersion = "dev" -) +// ProviderVersion is set at build-time in the release process +var ProviderVersion = "dev"