Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ formatters:
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
settings:
gofmt:
rewrite-rules:
- pattern: interface{}
replacement: any

linters:
# Run golangci-lint linters to see the list of all linters
Expand Down
2 changes: 1 addition & 1 deletion cmd/vcr-compressor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
continue
}

var m map[string]interface{}
var m map[string]any

err := json.Unmarshal([]byte(responseBody), &m)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/vcr-viewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
log.Printf(" Status: %s\n", interaction.Response.Status)
log.Printf(" Body: %s\n", interaction.Response.Body)

var m map[string]interface{}
var m map[string]any

err := json.Unmarshal([]byte(interaction.Response.Body), &m)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func compareJSONFieldsStrings(expected, actual string) bool {

// compareJSONBodies compare two given maps that represent json bodies
// returns true if both json are equivalent
func compareJSONBodies(expected, actual map[string]interface{}) bool {
func compareJSONBodies(expected, actual map[string]any) bool {
// Check for each key in actual requests
// Compare its value to cassette content if marshal-able to string
for key := range actual {
Expand Down
12 changes: 6 additions & 6 deletions internal/acctest/vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") ==

// SensitiveFields is a map with keys listing fields that should be anonymized
// value will be set in place of its old value
var SensitiveFields = map[string]interface{}{
var SensitiveFields = map[string]any{
"secret_key": "00000000-0000-0000-0000-000000000000",
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func getTestFilePath(t *testing.T, pkgFolder string, suffix string) string {
return filepath.Join(pkgFolder, "testdata", fileName)
}

func compareJSONFields(expected, actualI interface{}) bool {
func compareJSONFields(expected, actualI any) bool {
switch actual := actualI.(type) {
case string:
if _, isString := expected.(string); !isString {
Expand Down Expand Up @@ -138,10 +138,10 @@ func cassetteBodyMatcher(actualRequest *http.Request, cassetteRequest cassette.R
return true
}

actualJSON := make(map[string]interface{})
cassetteJSON := make(map[string]interface{})
actualJSON := make(map[string]any)
cassetteJSON := make(map[string]any)

err = xml.Unmarshal(actualRawBody, new(interface{}))
err = xml.Unmarshal(actualRawBody, new(any))
if err == nil {
// match if content is xml
return true
Expand Down Expand Up @@ -236,7 +236,7 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
}

func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error {
var jsonBody map[string]interface{}
var jsonBody map[string]any

err := json.Unmarshal([]byte(i.Response.Body), &jsonBody)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/cdf/locality.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func expandListKeys(key string, diff *schema.ResourceDiff) []string {
// getLocality find the locality of a resource
// Will try to get the zone if available then use region
// Will also use default zone or region if available
func getLocality(diff *schema.ResourceDiff, m interface{}) string {
func getLocality(diff *schema.ResourceDiff, m any) string {
var loc string

rawStateType := diff.GetRawState().Type()
Expand All @@ -67,7 +67,7 @@ func getLocality(diff *schema.ResourceDiff, m interface{}) string {
// Should not be used on computed keys, if a computed key is going to change on zone/region change
// this function will still block the terraform plan
func LocalityCheck(keys ...string) schema.CustomizeDiffFunc {
return func(_ context.Context, diff *schema.ResourceDiff, m interface{}) error {
return func(_ context.Context, diff *schema.ResourceDiff, m any) error {
l := getLocality(diff, m)

if l == "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/datasource/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
)

func NewZonedID(idI interface{}, fallBackZone scw.Zone) string {
func NewZonedID(idI any, fallBackZone scw.Zone) string {
zone, id, err := zonal.ParseID(idI.(string))
if err != nil {
id = idI.(string)
Expand All @@ -17,7 +17,7 @@ func NewZonedID(idI interface{}, fallBackZone scw.Zone) string {
return zonal.NewIDString(zone, id)
}

func NewRegionalID(idI interface{}, fallBackRegion scw.Region) string {
func NewRegionalID(idI any, fallBackRegion scw.Region) string {
region, id, err := regional.ParseID(idI.(string))
if err != nil {
id = idI.(string)
Expand Down
4 changes: 2 additions & 2 deletions internal/datasource/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func notFound(err error) bool {
}

type TooManyResultsError struct {
LastRequest interface{}
LastRequest any
Count int
}

Expand All @@ -74,7 +74,7 @@ func (e *TooManyResultsError) Is(err error) bool {
return ok
}

func (e *TooManyResultsError) As(target interface{}) bool {
func (e *TooManyResultsError) As(target any) bool {
t, ok := target.(**retry.NotFoundError)
if !ok {
return false
Expand Down
8 changes: 4 additions & 4 deletions internal/dsf/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func ExtractBaseKey(k string) string {
func GetStringListsFromState(key string, d *schema.ResourceData) ([]string, []string) {
oldList, newList := d.GetChange(key)

oldListStr := make([]string, len(oldList.([]interface{})))
newListStr := make([]string, len(newList.([]interface{})))
oldListStr := make([]string, len(oldList.([]any)))
newListStr := make([]string, len(newList.([]any)))

for i, v := range oldList.([]interface{}) {
for i, v := range oldList.([]any) {
oldListStr[i] = fmt.Sprint(v)
}

for i, v := range newList.([]interface{}) {
for i, v := range newList.([]any) {
newListStr[i] = fmt.Sprint(v)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/locality/ids.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package locality

// ExpandID returns the id whether it is a localizedID or a raw ID.
func ExpandID(id interface{}) string {
func ExpandID(id any) string {
_, ID, err := ParseLocalizedID(id.(string))
if err != nil {
return id.(string)
Expand All @@ -10,10 +10,10 @@ func ExpandID(id interface{}) string {
return ID
}

func ExpandIDs(data interface{}) []string {
expandedIDs := make([]string, 0, len(data.([]interface{})))
func ExpandIDs(data any) []string {
expandedIDs := make([]string, 0, len(data.([]any)))

for _, s := range data.([]interface{}) {
for _, s := range data.([]any) {
if s == nil {
s = ""
}
Expand Down
2 changes: 1 addition & 1 deletion internal/locality/regional/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (z ID) String() string {
return fmt.Sprintf("%s/%s", z.Region, z.ID)
}

func ExpandID(id interface{}) ID {
func ExpandID(id any) ID {
regionalID := ID{}
tab := strings.Split(id.(string), "/")

Expand Down
2 changes: 1 addition & 1 deletion internal/locality/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// ValidateStringInSliceWithWarning helps to only returns warnings in case we got a non-public locality passed
func ValidateStringInSliceWithWarning(correctValues []string, field string) schema.SchemaValidateDiagFunc {
return func(i interface{}, path cty.Path) diag.Diagnostics {
return func(i any, path cty.Path) diag.Diagnostics {
_, rawErr := validation.StringInSlice(correctValues, true)(i, field)

var res diag.Diagnostics
Expand Down
2 changes: 1 addition & 1 deletion internal/locality/zonal/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (z ID) String() string {
return fmt.Sprintf("%s/%s", z.Zone, z.ID)
}

func ExpandID(id interface{}) ID {
func ExpandID(id any) ID {
zonedID := ID{}
tab := strings.Split(id.(string), "/")

Expand Down
10 changes: 5 additions & 5 deletions internal/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ type Logger struct{}
var L = Logger{}

// Debugf logs to the DEBUG log. Arguments are handled in the manner of fmt.Printf.
func (l Logger) Debugf(format string, args ...interface{}) {
func (l Logger) Debugf(format string, args ...any) {
log.Printf("[DEBUG] "+format, args...)
}

// Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf.
func (l Logger) Infof(format string, args ...interface{}) {
func (l Logger) Infof(format string, args ...any) {
log.Printf("[INFO] "+format, args...)
}

// Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf.
func (l Logger) Warningf(format string, args ...interface{}) {
func (l Logger) Warningf(format string, args ...any) {
log.Printf("[WARN] "+format, args...)
}

// Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf.
func (l Logger) Errorf(format string, args ...interface{}) {
func (l Logger) Errorf(format string, args ...any) {
log.Printf("[ERROR] "+format, args...)
}

// Printf logs to the DEBUG log. Arguments are handled in the manner of fmt.Printf.
func (l Logger) Printf(format string, args ...interface{}) {
func (l Logger) Printf(format string, args ...any) {
l.Debugf(format, args...)
}

Expand Down
20 changes: 10 additions & 10 deletions internal/meta/extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
// terraformResourceData is an interface for *schema.ResourceData. (used for mock)
type terraformResourceData interface {
HasChange(string) bool
GetOk(string) (interface{}, bool)
Get(string) interface{}
GetOk(string) (any, bool)
Get(string) any
Id() string
}

// ExtractZone will try to guess the zone from the following:
// - zone field of the resource data
// - default zone from config
func ExtractZone(d terraformResourceData, m interface{}) (scw.Zone, error) {
func ExtractZone(d terraformResourceData, m any) (scw.Zone, error) {
rawZone, exist := d.GetOk("zone")
if exist {
return scw.ParseZone(rawZone.(string))
Expand All @@ -40,7 +40,7 @@ func ExtractZone(d terraformResourceData, m interface{}) (scw.Zone, error) {
// ExtractRegion will try to guess the region from the following:
// - region field of the resource data
// - default region from config
func ExtractRegion(d terraformResourceData, m interface{}) (scw.Region, error) {
func ExtractRegion(d terraformResourceData, m any) (scw.Region, error) {
rawRegion, exist := d.GetOk("region")
if exist {
return scw.ParseRegion(rawRegion.(string))
Expand All @@ -58,7 +58,7 @@ func ExtractRegion(d terraformResourceData, m interface{}) (scw.Region, error) {
// - region field of the resource data
// - default region given in argument
// - default region from config
func ExtractRegionWithDefault(d terraformResourceData, m interface{}, defaultRegion scw.Region) (scw.Region, error) {
func ExtractRegionWithDefault(d terraformResourceData, m any, defaultRegion scw.Region) (scw.Region, error) {
rawRegion, exist := d.GetOk("region")
if exist {
return scw.ParseRegion(rawRegion.(string))
Expand All @@ -79,7 +79,7 @@ func ExtractRegionWithDefault(d terraformResourceData, m interface{}, defaultReg
// ExtractProjectID will try to guess the project id from the following:
// - project_id field of the resource data
// - default project id from config
func ExtractProjectID(d terraformResourceData, m interface{}) (projectID string, isDefault bool, err error) {
func ExtractProjectID(d terraformResourceData, m any) (projectID string, isDefault bool, err error) {
rawProjectID, exist := d.GetOk("project_id")
if exist {
return rawProjectID.(string), false, nil
Expand All @@ -93,15 +93,15 @@ func ExtractProjectID(d terraformResourceData, m interface{}) (projectID string,
return "", false, ErrProjectIDNotFound
}

func ExtractScwClient(m interface{}) *scw.Client {
func ExtractScwClient(m any) *scw.Client {
return m.(*Meta).ScwClient()
}

func ExtractHTTPClient(m interface{}) *http.Client {
func ExtractHTTPClient(m any) *http.Client {
return m.(*Meta).HTTPClient()
}

func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Type) (interface{}, bool) {
func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Type) (any, bool) {
if key == "" {
return rawConfig, false
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Typ

// GetRawConfigForKey returns the value for a specific key in the user's raw configuration, which can be useful on resources' update
// The value for the key to look for must be a primitive type (bool, string, number) and the expected type of the value should be passed as the ty parameter
func GetRawConfigForKey(d *schema.ResourceData, key string, ty cty.Type) (interface{}, bool) {
func GetRawConfigForKey(d *schema.ResourceData, key string, ty cty.Type) (any, bool) {
rawConfig := d.GetRawConfig()
if rawConfig.IsNull() {
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func Provider(config *Config) plugin.ProviderFunc {

addBetaResources(p)

p.ConfigureContextFunc = func(ctx context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) {
p.ConfigureContextFunc = func(ctx context.Context, data *schema.ResourceData) (any, diag.Diagnostics) {
terraformVersion := p.TerraformVersion

// If we provide meta in config use it. This is useful for tests
Expand Down
4 changes: 2 additions & 2 deletions internal/services/account/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
)

func NewProjectAPI(m interface{}) *accountSDK.ProjectAPI {
func NewProjectAPI(m any) *accountSDK.ProjectAPI {
return accountSDK.NewProjectAPI(meta.ExtractScwClient(m))
}

func GetOrganizationID(m interface{}, d *schema.ResourceData) *string {
func GetOrganizationID(m any, d *schema.ResourceData) *string {
orgID, orgIDExist := d.GetOk("organization_id")

if orgIDExist {
Expand Down
8 changes: 4 additions & 4 deletions internal/services/account/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func ResourceProject() *schema.Resource {
}
}

func resourceAccountProjectCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceAccountProjectCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
accountAPI := NewProjectAPI(m)

request := &accountSDK.ProjectAPICreateProjectRequest{
Expand All @@ -79,7 +79,7 @@ func resourceAccountProjectCreate(ctx context.Context, d *schema.ResourceData, m
return resourceAccountProjectRead(ctx, d, m)
}

func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
accountAPI := NewProjectAPI(m)

res, err := accountAPI.GetProject(&accountSDK.ProjectAPIGetProjectRequest{
Expand All @@ -104,7 +104,7 @@ func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m i
return nil
}

func resourceAccountProjectUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceAccountProjectUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
accountAPI := NewProjectAPI(m)

req := &accountSDK.ProjectAPIUpdateProjectRequest{
Expand Down Expand Up @@ -133,7 +133,7 @@ func resourceAccountProjectUpdate(ctx context.Context, d *schema.ResourceData, m
return resourceAccountProjectRead(ctx, d, m)
}

func resourceAccountProjectDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceAccountProjectDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
accountAPI := NewProjectAPI(m)

err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError {
Expand Down
Loading
Loading