From ad997320fbb539b283f27c569e967c02b620c0a7 Mon Sep 17 00:00:00 2001 From: DenBeke Date: Tue, 11 Jun 2019 16:18:16 +0200 Subject: [PATCH] fix: removed defaultfunc from 'token' to supress useless warnings (#156) --- scaleway/provider.go | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/scaleway/provider.go b/scaleway/provider.go index 72db02c642..952ca1349b 100644 --- a/scaleway/provider.go +++ b/scaleway/provider.go @@ -55,6 +55,25 @@ func Provider() terraform.ResourceProvider { if secretKey, exist := scwConfig.GetSecretKey(); exist { return secretKey, nil } + + // Keep the deprecated behavior from 'token'. + for _, k := range []string{"SCALEWAY_TOKEN", "SCALEWAY_ACCESS_KEY"} { + if os.Getenv(k) != "" { + l.Warningf("%s is deprecated, please use SCW_SECRET_KEY instead", k) + return os.Getenv(k), nil + } + } + if path, err := homedir.Expand("~/.scwrc"); err == nil { + scwAPIKey, _, err := readDeprecatedScalewayConfig(path) + if err != nil { + // No error is returned here to allow user to use `secret_key`. + l.Errorf("cannot parse deprecated config file: %s", err) + return nil, nil + } + // Depreciation log is already handled by scwconfig. + return scwAPIKey, nil + } + // No error is returned here to allow user to use `secret_key`. return nil, nil }), }, @@ -119,27 +138,6 @@ func Provider() terraform.ResourceProvider { Type: schema.TypeString, Optional: true, // To allow user to use `secret_key`. Deprecated: "Use `secret_key` instead.", - DefaultFunc: schema.SchemaDefaultFunc(func() (interface{}, error) { - // Keep the deprecated behavior - for _, k := range []string{"SCALEWAY_TOKEN", "SCALEWAY_ACCESS_KEY"} { - if os.Getenv(k) != "" { - l.Warningf("%s is deprecated, please use SCW_SECRET_KEY instead", k) - return os.Getenv(k), nil - } - } - if path, err := homedir.Expand("~/.scwrc"); err == nil { - scwAPIKey, _, err := readDeprecatedScalewayConfig(path) - if err != nil { - // No error is returned here to allow user to use `secret_key`. - l.Errorf("cannot parse deprecated config file: %s", err) - return nil, nil - } - // Depreciation log is already handled by scwconfig. - return scwAPIKey, nil - } - // No error is returned here to allow user to use `secret_key`. - return nil, nil - }), }, "organization": { Type: schema.TypeString,