Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add support for staticcheck #2717

Merged
merged 14 commits into from
Aug 26, 2024
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- canonicalheader # canonicalheader checks whether net/http.Header uses canonical header [fast: false, auto-fix: false]
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
- contextcheck # check the function whether use a non-inherited context [fast: false, auto-fix: false]
- copyloopvar # copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
Expand Down Expand Up @@ -54,10 +55,12 @@ linters:
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
- protogetter # Reports direct reads from proto message fields when getters should be used [fast: false, auto-fix: true]
- reassign # Checks that package variables are not reassigned [fast: false, auto-fix: false]
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false]
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
Expand Down Expand Up @@ -94,7 +97,6 @@ linters:
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]

Expand Down
6 changes: 5 additions & 1 deletion docs/resources/instance_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ attached to the server. Updates to this field will trigger a stop/start of the s
~> **Important:** If this field contains local volumes, you have to first detach them, in one apply, and then delete the volume in another apply.

- `enable_ipv6` - (Defaults to `false`) Determines if IPv6 is enabled for the server. Useful only with `routed_ip_enabled` as false, otherwise ipv6 is always supported.
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.

- `ip_id` - (Optional) The ID of the reserved IP that is attached to the server.

Expand Down Expand Up @@ -273,13 +274,16 @@ In addition to all arguments above, the following attributes are exported:
- `root_volume`
- `volume_id` - The volume ID of the root volume of the server.
- `private_ip` - The Scaleway internal IP address of the server.
- `public_ip` - The public IP address of the server.
- `public_ip` - The public IP address of the server (Deprecated use `public_ips` instead).
- `public_ips` - The list of public IPs of the server.
- `id` - The ID of the IP
- `address` - The address of the IP
- `ipv6_address` - The default ipv6 address routed to the server. ( Only set when enable_ipv6 is set to true )
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
- `ipv6_gateway` - The ipv6 gateway address. ( Only set when enable_ipv6 is set to true )
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
- `ipv6_prefix_length` - The prefix length of the ipv6 subnet routed to the server. ( Only set when enable_ipv6 is set to true )
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
- `boot_type` - The boot Type of the server. Possible values are: `local`, `bootscript` or `rescue`.
- `organization_id` - The organization ID the server is associated with.

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/k8s_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ In addition to all arguments above, the following attributes are exported:
- `status` - The status of the pool.
- `nodes` - (List of) The nodes in the default pool.
- `name` - The name of the node.
- `public_ip` - The public IPv4.
- `public_ip_v6` - The public IPv6.
- `public_ip` - The public IPv4. (Deprecated, Please use the official Kubernetes provider and the kubernetes_nodes data source)
- `public_ip_v6` - The public IPv6. (Deprecated, Please use the official Kubernetes provider and the kubernetes_nodes data source)
- `status` - The status of the node.
- `created_at` - The creation date of the pool.
- `updated_at` - The last update date of the pool.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ resource "scaleway_lb" "main" {

- `ipam_ids` - (Optional) IPAM ID of a pre-reserved IP address to assign to the Load Balancer on this Private Network.

- `dhcp_config` - (Optional) Set to `true` if you want to let DHCP assign IP addresses. See below.
- `dhcp_config` - (Deprecated) Please use `ipam_ids`. Set to `true` if you want to let DHCP assign IP addresses. See below.

- `static_config` - (Deprecated) Please use `ipam_ids`. Define a local ip address of your choice for the load balancer instance.

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/lb_frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ In addition to all arguments above, the following attributes are exported:

~> **Important:** Load Balancer frontend IDs are [zoned](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111`

- `certificate_id` - (Deprecated) First certificate ID used by the frontend.
- `certificate_id` - (Deprecated, use `certificate_ids` instead) First certificate ID used by the frontend.


## Import
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/rdb_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ In addition to all arguments above, the following attributes are exported:
~> **Important** Database Instances' IDs are [regional](../guides/regions_and_zones.md#resource-ids), which means they
are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-111111111111`

- `endpoint_ip` - (Deprecated) The IP of the Database Instance.
- `endpoint_port` - (Deprecated) The port of the Database Instance.
- `endpoint_ip` - (Deprecated) The IP of the Database Instance. Please use the private_network or the load_balancer attribute.
- `endpoint_port` - (Deprecated) The port of the Database Instance. Please use the private_network or the load_balancer attribute.
- `read_replicas` - List of read replicas of the Database Instance.
- `ip` - IP of the replica.
- `port` - Port of the replica.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/tem_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ In addition to all arguments above, the following attributes are exported:

- `revoked_at` - The date and time of the revocation of the domain (RFC 3339 format).

- `last_error` - The error message if the last check failed.
- `last_error` - (Deprecated) The error message if the last check failed.

- `spf_config` - The snippet of the SPF record that should be registered in the DNS zone.

Expand Down
24 changes: 12 additions & 12 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,27 @@ func Provider(config *Config) plugin.ProviderFunc {
Description: "The Scaleway access key.",
},
"secret_key": {
Type: schema.TypeString,
Optional: true, // To allow user to use deprecated `token`.
Description: "The Scaleway secret Key.",
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Optional: true, // To allow user to use deprecated `token`.
Description: "The Scaleway secret Key.",
ValidateDiagFunc: verify.IsUUID(),
},
"profile": {
Type: schema.TypeString,
Optional: true, // To allow user to use `access_key`, `secret_key`, `project_id`...
Description: "The Scaleway profile to use.",
},
"project_id": {
Type: schema.TypeString,
Optional: true, // To allow user to use organization instead of project
Description: "The Scaleway project ID.",
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Optional: true, // To allow user to use organization instead of project
Description: "The Scaleway project ID.",
ValidateDiagFunc: verify.IsUUID(),
},
"organization_id": {
Type: schema.TypeString,
Optional: true,
Description: "The Scaleway organization ID.",
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Optional: true,
Description: "The Scaleway organization ID.",
ValidateDiagFunc: verify.IsUUID(),
},
"region": regional.Schema(),
"zone": zonal.Schema(),
Expand Down
12 changes: 6 additions & 6 deletions internal/services/account/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func ResourceProject() *schema.Resource {
Description: "The date and time of the last update of the Project (Format ISO 8601)",
},
"organization_id": {
Type: schema.TypeString,
Description: "The organization_id you want to attach the resource to",
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Description: "The organization_id you want to attach the resource to",
Optional: true,
ForceNew: true,
Computed: true,
ValidateDiagFunc: verify.IsUUID(),
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions internal/services/account/project_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func DataSourceProject() *schema.Resource {

dsSchema["name"].ConflictsWith = []string{"project_id"}
dsSchema["project_id"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The ID of the SSH key",
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The ID of the SSH key",
ValidateDiagFunc: verify.IsUUID(),
}

return &schema.Resource{
Expand Down
12 changes: 6 additions & 6 deletions internal/services/account/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func OrganizationIDOptionalSchema() *schema.Schema {
// ProjectIDSchema returns a standard schema for a project_id
func ProjectIDSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Description: "The project_id you want to attach the resource to",
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Description: "The project_id you want to attach the resource to",
Optional: true,
ForceNew: true,
Computed: true,
ValidateDiagFunc: verify.IsUUID(),
}
}
10 changes: 5 additions & 5 deletions internal/services/baremetal/option_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func DataSourceOption() *schema.Resource {
ConflictsWith: []string{"option_id"},
},
"option_id": {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the option",
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
Type: schema.TypeString,
Optional: true,
Description: "The ID of the option",
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
},
"manageable": {
Type: schema.TypeBool,
Expand Down
10 changes: 5 additions & 5 deletions internal/services/baremetal/os_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func DataSourceOS() *schema.Resource {
ConflictsWith: []string{"os_id"},
},
"os_id": {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the os",
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
Type: schema.TypeString,
Optional: true,
Description: "The ID of the os",
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
},
"zone": zonal.Schema(),
},
Expand Down
14 changes: 7 additions & 7 deletions internal/services/baremetal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ResourceServer() *schema.Resource {
Optional: true,
Description: "The base image of the server",
DiffSuppressFunc: dsf.Locality,
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
},
"os_name": {
Type: schema.TypeString,
Expand All @@ -91,8 +91,8 @@ func ResourceServer() *schema.Resource {
"ssh_key_ids": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
ValidateDiagFunc: verify.IsUUID(),
},
Optional: true,
Description: `Array of SSH key IDs allowed to SSH to the server
Expand Down Expand Up @@ -212,10 +212,10 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "The private network ID",
Required: true,
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
Type: schema.TypeString,
Description: "The private network ID",
Required: true,
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
StateFunc: func(i interface{}) string {
return locality.ExpandID(i.(string))
},
Expand Down
10 changes: 5 additions & 5 deletions internal/services/baremetal/server_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func DataSourceServer() *schema.Resource {

dsSchema["name"].ConflictsWith = []string{"server_id"}
dsSchema["server_id"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The ID of the server",
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
Type: schema.TypeString,
Optional: true,
Description: "The ID of the server",
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
}

return &schema.Resource{
Expand Down
2 changes: 1 addition & 1 deletion internal/services/block/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ResourceSnapshot() *schema.Resource {
"volume_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
Description: "ID of the volume from which creates a snapshot",
DiffSuppressFunc: dsf.Locality,
},
Expand Down
10 changes: 5 additions & 5 deletions internal/services/block/snapshot_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func DataSourceSnapshot() *schema.Resource {
datasource.AddOptionalFieldsToSchema(dsSchema, "name", "zone", "volume_id", "project_id")

dsSchema["snapshot_id"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The ID of the snapshot",
ConflictsWith: []string{"name"},
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
Type: schema.TypeString,
Optional: true,
Description: "The ID of the snapshot",
ConflictsWith: []string{"name"},
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
}

return &schema.Resource{
Expand Down
10 changes: 5 additions & 5 deletions internal/services/block/volume_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func DataSourceVolume() *schema.Resource {
datasource.AddOptionalFieldsToSchema(dsSchema, "name", "zone", "project_id")

dsSchema["volume_id"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The ID of the volume",
ConflictsWith: []string{"name"},
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
Type: schema.TypeString,
Optional: true,
Description: "The ID of the volume",
ConflictsWith: []string{"name"},
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
}

return &schema.Resource{
Expand Down
8 changes: 4 additions & 4 deletions internal/services/cockpit/alert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func ResourceCockpitAlertManager() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.IsEmail(),
Description: "Email addresses for the alert receivers",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: verify.IsEmail(),
Description: "Email addresses for the alert receivers",
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/services/cockpit/cockpit_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func DataSourceCockpit() *schema.Resource {
dsSchema := datasource.SchemaFromResourceSchema(ResourceCockpit().Schema)

dsSchema["project_id"] = &schema.Schema{
Type: schema.TypeString,
Description: "The project_id you want to attach the resource to",
Optional: true,
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Description: "The project_id you want to attach the resource to",
Optional: true,
ValidateDiagFunc: verify.IsUUID(),
}
dsSchema["plan"] = &schema.Schema{
Type: schema.TypeString,
Expand Down
26 changes: 13 additions & 13 deletions internal/services/container/container_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ func DataSourceContainer() *schema.Resource {

dsSchema["name"].ConflictsWith = []string{"container_id"}
dsSchema["container_id"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The ID of the Container",
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
Type: schema.TypeString,
Optional: true,
Description: "The ID of the Container",
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
}
dsSchema["namespace_id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The ID of the Container namespace",
ValidateFunc: verify.IsUUIDorUUIDWithLocality(),
Type: schema.TypeString,
Required: true,
Description: "The ID of the Container namespace",
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
}
dsSchema["project_id"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The ID of the project to filter the Container",
ValidateFunc: verify.IsUUID(),
Type: schema.TypeString,
Optional: true,
Description: "The ID of the project to filter the Container",
ValidateDiagFunc: verify.IsUUID(),
}

return &schema.Resource{
Expand Down
Loading
Loading