Skip to content

Commit

Permalink
Clean up: fix linter/style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alidaw committed Mar 18, 2024
1 parent ded6185 commit 0c8c4f4
Show file tree
Hide file tree
Showing 47 changed files with 128 additions and 135 deletions.
1 change: 0 additions & 1 deletion gridscale/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var marketplaceAppCategories = []string{"CMS", "project management", "Adminpanel
var postgreSQLPerformanceClasses = []string{"standard", "high", "insane", "ultra"}
var filesystemPerformanceClasses = []string{"standard", "high", "insane", "ultra"}
var msSQLServerPerformanceClasses = []string{"standard", "high", "insane", "ultra"}
var mariaDBPerformanceClasses = []string{"standard", "high", "insane", "ultra"}
var machineTypes = []string{"i440fx", "q35_bios", "q35_uefi"}
var storageDevices = []string{"ide", "sata", "virtio_scsi", "virtio_block"}
var usbControllers = []string{"nec_xhci", "piix3_uhci"}
Expand Down
5 changes: 2 additions & 3 deletions gridscale/datasource_gridscale_backup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gridscale

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -24,12 +23,12 @@ func TestAccdataSourceGridscaleBackup_basic(t *testing.T) {
}

func testAccCheckDataSourceBackupConfig_basic() string {
return fmt.Sprintf(`
return `
resource "gridscale_storage" "foo" {
name = "storage"
capacity = 1
}
data "gridscale_backup_list" "foo" {
storage_uuid = gridscale_storage.foo.id
}`)
}`
}
5 changes: 2 additions & 3 deletions gridscale/datasource_gridscale_objectstorage_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gridscale

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -29,12 +28,12 @@ func TestAccdataSourceGridscaleObjectStorage_basic(t *testing.T) {
}

func testAccCheckDataSourceObjectStorageConfig_basic() string {
return fmt.Sprint(`
return `
resource "gridscale_object_storage_accesskey" "foo" {
}
data "gridscale_object_storage_accesskey" "foo" {
resource_id = "${gridscale_object_storage_accesskey.foo.id}"
}
`)
`
}
6 changes: 5 additions & 1 deletion gridscale/datasource_gridscale_paas.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func dataSourceGridscalePaaSRead(d *schema.ResourceData, meta interface{}) error
if err = d.Set("name", props.Name); err != nil {
return fmt.Errorf("%s error setting name: %v", errorPrefix, err)
}
if creds != nil && len(creds) > 0 {
if len(creds) > 0 {
if err = d.Set("username", creds[0].Username); err != nil {
return fmt.Errorf("%s error setting username: %v", errorPrefix, err)
}
Expand Down Expand Up @@ -222,6 +222,10 @@ func dataSourceGridscalePaaSRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
valueInString, err := convInterfaceToString(paramValType, value)

if err != nil {
return err
}
param := map[string]interface{}{
"param": k,
"value": valueInString,
Expand Down
5 changes: 2 additions & 3 deletions gridscale/datasource_gridscale_publicnetwork_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gridscale

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -26,7 +25,7 @@ func TestAccdataSourceGridscalePublicNetwork_basic(t *testing.T) {
}

func testAccCheckDataSourcePublicNetworkConfig_basic() string {
return fmt.Sprint(`
return `
data "gridscale_public_network" "foo" {
}`)
}`
}
4 changes: 2 additions & 2 deletions gridscale/datasource_gridscale_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func dataSourceGridscaleServerRead(d *schema.ResourceData, meta interface{}) err
}

//Get storages
storages := make([]interface{}, 0)
/*storages := make([]interface{}, 0)
for _, value := range server.Properties.Relations.Storages {
storage := map[string]interface{}{
"object_uuid": value.ObjectUUID,
Expand All @@ -389,7 +389,7 @@ func dataSourceGridscaleServerRead(d *schema.ResourceData, meta interface{}) err
"capacity": value.Capacity,
}
storages = append(storages, storage)
}
}*/

// Get hardware_profile_config
hardwareProfileConfigList := make([]interface{}, 0)
Expand Down
8 changes: 4 additions & 4 deletions gridscale/resource_gridscale_backup_schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ resource "gridscale_backupschedule" "foo" {
}

func testAccCheckDataSourceGridscaleBackupScheduleConfig_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_storage" "foo" {
name = "storage"
capacity = 1
Expand All @@ -127,11 +127,11 @@ resource "gridscale_backupschedule" "foo" {
next_runtime = "2030-12-30 15:04:05"
active = true
}
`)
`
}

func testAccCheckDataSourceGridscaleBackupScheduleConfig_forcenew_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_storage" "new" {
name = "storage"
capacity = 1
Expand All @@ -144,5 +144,5 @@ resource "gridscale_backupschedule" "foo" {
next_runtime = "2030-12-30 15:04:05"
active = true
}
`)
`
}
5 changes: 2 additions & 3 deletions gridscale/resource_gridscale_bucket_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gridscale

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -32,7 +31,7 @@ func TestAccResourceGridscaleBucket_Basic(t *testing.T) {
}

func testAccCheckResourceGridscaleBucketConfig_basic() string {
return fmt.Sprint(`
return `
resource "gridscale_object_storage_accesskey" "test" {
timeouts {
create="10m"
Expand All @@ -44,5 +43,5 @@ resource "gridscale_object_storage_bucket" "foo" {
secret_key = gridscale_object_storage_accesskey.test.secret_key
bucket_name = "myterraformbucket"
}
`)
`
}
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func resourceGridscaleFilesystem() *schema.Resource {
}
}
if !isReleaseValid {
return fmt.Errorf("%v is not a valid Filesystem service release. Valid releases are: %v\n", newReleaseVal, strings.Join(releaseList, ", "))
return fmt.Errorf("%v is not a valid Filesystem service release. Valid releases are: %v", newReleaseVal, strings.Join(releaseList, ", "))
}
return nil
}),
Expand Down Expand Up @@ -427,7 +427,7 @@ func getFilesystemTemplateUUID(client *gsclient.Client, release, performanceClas
}
}
if !isReleaseValid {
return "", fmt.Errorf("%v is not a valid Filesystem service release. Valid releases are: %v\n", release, strings.Join(releases, ", "))
return "", fmt.Errorf("%v is not a valid Filesystem service release. Valid releases are: %v", release, strings.Join(releases, ", "))
}

return uTemplate.Properties.ObjectUUID, nil
Expand Down
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resource "gridscale_filesystem" "test" {
}

func testAccCheckResourceGridscaleFilesystemConfig_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_filesystem" "test" {
name = "newname"
root_squash = false
Expand All @@ -68,5 +68,5 @@ resource "gridscale_filesystem" "test" {
allowed_ip_ranges = ["192.14.15.15"]
labels = ["test"]
}
`)
`
}
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ resource "gridscale_firewall" "foo" {
}

func testAccCheckResourceGridscaleFirewallConfig_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_firewall" "foo" {
name = "newname"
rules_v4_out {
Expand All @@ -139,5 +139,5 @@ resource "gridscale_firewall" "foo" {
comment = "testv6"
}
}
`)
`
}
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_ipv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ resource "gridscale_ipv4" "foo" {
}

func testAccCheckResourceGridscaleIpv4Config_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_ipv4" "foo" {
name = "newname"
failover = true
reverse_dns = "test.test"
}
`)
`
}
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ resource "gridscale_ipv6" "foo" {
}

func testAccCheckResourceGridscaleIpv6Config_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_ipv6" "foo" {
name = "newname"
failover = true
reverse_dns = "test.test"
}
`)
`
}
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_isoimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ resource "gridscale_server" "foo" {
}

func testAccCheckResourceGridscaleISOImageConfig_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_isoimage" "foo" {
name = "newname"
source_url = "http://tinycorelinux.net/10.x/x86/release/TinyCore-current.iso"
}
`)
`
}
14 changes: 7 additions & 7 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func resourceGridscaleK8s() *schema.Resource {
newVersionValInf, isVersionSet := d.GetOk("gsk_version")
newVersionVal := newVersionValInf.(string)
if !isReleaseSet && !isVersionSet {
return errors.New("either \"release\" or \"gsk_version\" has to be defined.")
return errors.New("either \"release\" or \"gsk_version\" has to be defined")
}
if isReleaseSet && isVersionSet {
return errors.New("\"release\" and \"gsk_version\" cannot be set at the same time. Only one of them is set at a time.")
return errors.New("\"release\" and \"gsk_version\" cannot be set at the same time. Only one of them is set at a time")
}

paasTemplates, err := client.GetPaaSTemplateList(ctx)
Expand Down Expand Up @@ -78,10 +78,10 @@ func resourceGridscaleK8s() *schema.Resource {
}
}
if !isReleaseValid && isReleaseSet {
return fmt.Errorf("%v is an INVALID Kubernetes minor release. Valid releases are: %v\n", newReleaseVal, strings.Join(releaseList, ", "))
return fmt.Errorf("%v is an INVALID Kubernetes minor release. Valid releases are: %v", newReleaseVal, strings.Join(releaseList, ", "))
}
if !isVersionValid && isVersionSet {
return fmt.Errorf("%v is an INVALID gridscale Kubernetes (GSK) version. Valid GSK versions are: %v\n", newVersionVal, strings.Join(versionList, ", "))
return fmt.Errorf("%v is an INVALID gridscale Kubernetes (GSK) version. Valid GSK versions are: %v", newVersionVal, strings.Join(versionList, ", "))
}
return validateK8sParameters(d, chosenTemplate)
},
Expand Down Expand Up @@ -551,7 +551,7 @@ func getK8sTemplateUUIDFromRelease(client *gsclient.Client, release string) (str
}
}
if !isReleaseValid {
return "", fmt.Errorf("%v is an INVALID Kubernetes minor release. Valid releases are: %v\n", release, strings.Join(releases, ", "))
return "", fmt.Errorf("%v is an INVALID Kubernetes minor release. Valid releases are: %v", release, strings.Join(releases, ", "))
}

return uTemplate.Properties.ObjectUUID, nil
Expand All @@ -577,7 +577,7 @@ func getK8sTemplateUUIDFromGSKVersion(client *gsclient.Client, version string) (
}
}
if !isVersionValid {
return "", fmt.Errorf("%v is an INVALID gridscale Kubernetes (GSK) version. Valid GSK versions are: %v\n", version, strings.Join(versions, ", "))
return "", fmt.Errorf("%v is an INVALID gridscale Kubernetes (GSK) version. Valid GSK versions are: %v", version, strings.Join(versions, ", "))
}

return uTemplate.Properties.ObjectUUID, nil
Expand Down Expand Up @@ -671,7 +671,7 @@ func validateK8sParameters(d *schema.ResourceDiff, template gsclient.PaaSTemplat
if cluster_cidr.(string) != "" {
_, _, err := net.ParseCIDR(cluster_cidr.(string))
if err != nil {
errorMessages = append(errorMessages, fmt.Sprintf("Invalid value for PaaS template release. Value must be a valid CIDR.\n"))
errorMessages = append(errorMessages, "Invalid value for PaaS template release. Value must be a valid CIDR.\n")
}
}
// if cluster_cidr_template is immutable, return error if it is set during k8s creation
Expand Down
4 changes: 2 additions & 2 deletions gridscale/resource_gridscale_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ resource "gridscale_k8s" "foopaas" {
}

func testAccCheckResourceGridscaleK8sConfig_basic_update() string {
return fmt.Sprintf(`
return `
resource "gridscale_k8s" "foopaas" {
name = "newname"
release = "1.26"
Expand All @@ -72,5 +72,5 @@ resource "gridscale_k8s" "foopaas" {
rocket_storage = 90
}
}
`)
`
}
38 changes: 20 additions & 18 deletions gridscale/resource_gridscale_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,32 +321,34 @@ func expandLoadbalancerForwardingRules(forwardingRules interface{}) []gsclient.F
func flattenLoadbalancerForwardingRules(forwardingRules []gsclient.ForwardingRule) []interface{} {
tempForwardingRules := make([]interface{}, 0)

if forwardingRules != nil {
for _, value := range forwardingRules {
forwardingRule := map[string]interface{}{
"letsencrypt_ssl": value.LetsencryptSSL,
"certificate_uuid": value.CertificateUUID,
"listen_port": value.ListenPort,
"mode": value.Mode,
"target_port": value.TargetPort,
}
tempForwardingRules = append(tempForwardingRules, forwardingRule)
if forwardingRules == nil {
return tempForwardingRules
}
for _, value := range forwardingRules {
forwardingRule := map[string]interface{}{
"letsencrypt_ssl": value.LetsencryptSSL,
"certificate_uuid": value.CertificateUUID,
"listen_port": value.ListenPort,
"mode": value.Mode,
"target_port": value.TargetPort,
}
tempForwardingRules = append(tempForwardingRules, forwardingRule)
}
return tempForwardingRules
}

func flattenLoadbalancerBackendServers(backendServers []gsclient.BackendServer) []interface{} {
tempBackendServers := make([]interface{}, 0)
if backendServers != nil {
for _, value := range backendServers {
backendServer := map[string]interface{}{
"weight": value.Weight,
"host": value.Host,
"proxy_protocol": value.ProxyProtocol,
}
tempBackendServers = append(tempBackendServers, backendServer)
if backendServers == nil {
return tempBackendServers
}
for _, value := range backendServers {
backendServer := map[string]interface{}{
"weight": value.Weight,
"host": value.Host,
"proxy_protocol": value.ProxyProtocol,
}
tempBackendServers = append(tempBackendServers, backendServer)
}
return tempBackendServers
}
2 changes: 1 addition & 1 deletion gridscale/resource_gridscale_mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func getMariaDBTemplateUUID(client *gsclient.Client, release, performanceClass s
}
}
if !isReleaseValid {
return "", fmt.Errorf("%v is not a valid MariaDB release. Valid releases are: %v\n", release, strings.Join(releases, ", "))
return "", fmt.Errorf("%v is not a valid MariaDB release. Valid releases are: %v", release, strings.Join(releases, ", "))
}

return uTemplate.Properties.ObjectUUID, nil
Expand Down
Loading

0 comments on commit 0c8c4f4

Please sign in to comment.