Skip to content

Commit

Permalink
golangci-lint run --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phillc committed Feb 25, 2021
1 parent 3e8cfa6 commit 02a62e7
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 45 deletions.
7 changes: 3 additions & 4 deletions linode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ 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"
)

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
Expand All @@ -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{
Expand Down
1 change: 0 additions & 1 deletion linode/data_source_linode_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
2 changes: 0 additions & 2 deletions linode/data_source_linode_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -100,5 +99,4 @@ func dataSourceLinodeVolumeRead(d *schema.ResourceData, meta interface{}) error
}

return fmt.Errorf("Linode Volume %s was not found", fmt.Sprint(requestedVolumeID))

}
24 changes: 11 additions & 13 deletions linode/linode_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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[:])
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 0 additions & 2 deletions linode/resource_linode_domain_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
}
Expand Down
3 changes: 2 additions & 1 deletion linode/resource_linode_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions linode/resource_linode_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_nodebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_nodebalancer_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 0 additions & 2 deletions linode/resource_linode_object_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_object_storage_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions linode/resource_linode_rdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_stackscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions linode/resource_linode_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion linode/resource_linode_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 2 additions & 4 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 02a62e7

Please sign in to comment.