diff --git a/.golangci.yml b/.golangci.yml index dafe334b30..c35ba0e1ed 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,6 +18,7 @@ linters: - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false] - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false] + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix] - forbidigo # Forbids identifiers [fast: true, auto-fix: false] - gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false] @@ -48,6 +49,7 @@ linters: - musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false] - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] - nilerr # Finds the code that returns nil even if it checks that the error is not nil. [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: true] - noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false] - nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false] @@ -74,6 +76,7 @@ linters: - unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false] - unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false] + - usetesting # Reports uses of functions with replacement inside the testing package. [auto-fix] - wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false] - whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] - zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false] @@ -97,7 +100,6 @@ linters: - mnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false] - 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] - 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] diff --git a/internal/acctest/acctest.go b/internal/acctest/acctest.go index b9fab699df..8e81109887 100644 --- a/internal/acctest/acctest.go +++ b/internal/acctest/acctest.go @@ -98,6 +98,7 @@ func extractGeneratedNamePrefix(name string) string { // ^ dashIndex = strings.LastIndex(name, "-") name = name[:dashIndex] + return name } @@ -155,6 +156,7 @@ func compareJSONBodies(expected, actual map[string]interface{}) bool { return false } } + return true } diff --git a/internal/acctest/checks.go b/internal/acctest/checks.go index e3142780ef..b701d01c57 100644 --- a/internal/acctest/checks.go +++ b/internal/acctest/checks.go @@ -26,6 +26,7 @@ func CheckResourceIDChanged(resourceName string, resourceID *string) resource.Te return errors.New("resource ID persisted when it should have changed") } *resourceID = rs.Primary.ID + return nil } } @@ -42,6 +43,7 @@ func CheckResourceIDPersisted(resourceName string, resourceID *string) resource. return errors.New("resource ID changed when it should have persisted") } *resourceID = rs.Primary.ID + return nil } } @@ -90,6 +92,7 @@ func CheckResourceAttrFunc(name string, key string, test func(string) error) res if err != nil { return fmt.Errorf("test for %s %s did not pass test: %s", name, key, err) } + return nil } } @@ -100,6 +103,7 @@ func CheckResourceAttrIPv4(name string, key string) resource.TestCheckFunc { if ip.To4() == nil { return fmt.Errorf("%s is not a valid IPv4", value) } + return nil }) } @@ -110,6 +114,7 @@ func CheckResourceAttrIPv6(name string, key string) resource.TestCheckFunc { if ip.To16() == nil { return fmt.Errorf("%s is not a valid IPv6", value) } + return nil }) } @@ -120,6 +125,7 @@ func CheckResourceAttrIP(name string, key string) resource.TestCheckFunc { if ip == nil { return fmt.Errorf("%s is not a valid IP", value) } + return nil }) } diff --git a/internal/acctest/domain.go b/internal/acctest/domain.go index dd087c9d10..c8962cceef 100644 --- a/internal/acctest/domain.go +++ b/internal/acctest/domain.go @@ -36,12 +36,14 @@ func init() { for _, reservedDomain := range reservedDomains { if reservedDomain.MatchString(TestDomain) { isReserved = true + break } } if isReserved { logging.L.Warningf("TF_TEST_DOMAIN cannot be a Scaleway required domain. Please use another one.") + return } diff --git a/internal/acctest/sweepers.go b/internal/acctest/sweepers.go index 1df4040980..d84ca0e5b6 100644 --- a/internal/acctest/sweepers.go +++ b/internal/acctest/sweepers.go @@ -16,6 +16,7 @@ func Sweep(f func(scwClient *scw.Client) error) error { if err != nil { return err } + return f(m.ScwClient()) } @@ -30,6 +31,7 @@ func SweepZones(zones []scw.Zone, f func(scwClient *scw.Client, zone scw.Zone) e logging.L.Warningf("error running sweepZones, ignoring: %s", err) } } + return nil } @@ -41,6 +43,7 @@ func SweepRegions(regions []scw.Region, f func(scwClient *scw.Client, region scw return SweepZones(zones, func(scwClient *scw.Client, zone scw.Zone) error { r, _ := zone.Region() + return f(scwClient, r) }) } @@ -56,5 +59,6 @@ func sharedClientForZone(zone scw.Zone) (*scw.Client, error) { if err != nil { return nil, err } + return m.ScwClient(), nil } diff --git a/internal/acctest/validate_cassettes_test.go b/internal/acctest/validate_cassettes_test.go index 1d7ecdbbfd..60291b0ba4 100644 --- a/internal/acctest/validate_cassettes_test.go +++ b/internal/acctest/validate_cassettes_test.go @@ -40,6 +40,7 @@ func getTestFiles() (map[string]struct{}, error) { if isCassette && !isException { filesMap[fileNameWithoutExtSuffix(path)] = struct{}{} } + return nil }) if err != nil { @@ -87,8 +88,10 @@ func checkErrCodeExcept(i *cassette.Interaction, c *cassette.Cassette, codes ... return true } } + return false } + return true } diff --git a/internal/acctest/vcr.go b/internal/acctest/vcr.go index 2e2c56014a..03c096c92f 100644 --- a/internal/acctest/vcr.go +++ b/internal/acctest/vcr.go @@ -70,6 +70,7 @@ func compareJSONFields(expected, actualI interface{}) bool { if _, isString := expected.(string); !isString { return false } + return compareJSONFieldsStrings(expected.(string), actual) default: // Consider equality when not handled @@ -116,6 +117,7 @@ func cassetteBodyMatcher(actualRequest *http.Request, cassetteRequest cassette.R } else if _, isFile := actualRequest.Body.(*os.File); isFile { return true // Body match if request is sending a file, maybe do more check here } + return false } @@ -243,6 +245,7 @@ func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error { return fmt.Errorf("failed to marshal anonymized body: %w", err) } i.Response.Body = string(anonymizedBody) + return nil } @@ -290,6 +293,7 @@ func getHTTPRecoder(t *testing.T, pkgFolder string, update bool) (client *http.C delete(i.Request.Headers, "x-auth-token") delete(i.Request.Headers, "X-Auth-Token") delete(i.Request.Headers, "Authorization") + return nil }, recorder.BeforeSaveHook) diff --git a/internal/cdf/locality.go b/internal/cdf/locality.go index eb181f9419..5be96980d5 100644 --- a/internal/cdf/locality.go +++ b/internal/cdf/locality.go @@ -57,6 +57,7 @@ func getLocality(diff *schema.ResourceDiff, m interface{}) string { region, _ := meta.ExtractRegion(diff, m) loc = region.String() } + return loc } @@ -91,6 +92,7 @@ func LocalityCheck(keys ...string) schema.CustomizeDiffFunc { } } } + return nil } } diff --git a/internal/datasource/schemas.go b/internal/datasource/schemas.go index 25aadf928c..86a843ac07 100644 --- a/internal/datasource/schemas.go +++ b/internal/datasource/schemas.go @@ -49,6 +49,7 @@ func SchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.S switch v.Type { case schema.TypeSet: dv.Set = v.Set + fallthrough case schema.TypeList: // List & Set types are generally used for 2 cases: @@ -70,6 +71,7 @@ func SchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.S } ds[k] = dv } + return ds } diff --git a/internal/datasource/search.go b/internal/datasource/search.go index 8475a3a41c..986628a52f 100644 --- a/internal/datasource/search.go +++ b/internal/datasource/search.go @@ -18,6 +18,7 @@ func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, err if foundFlag { // More than one element found with the same search name var zero T + return zero, fmt.Errorf("multiple elements found with the name %s", searchName) } found = elem @@ -27,6 +28,7 @@ func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, err if !foundFlag { var zero T + return zero, fmt.Errorf("no element found with the name %s", searchName) } @@ -51,6 +53,7 @@ func SingularDataSourceFindError(resourceType string, err error) error { // retry.NotFoundError. func notFound(err error) bool { var e *retry.NotFoundError // nosemgrep:ci.is-not-found-error + return errors.As(err, &e) } @@ -65,6 +68,7 @@ func (e *TooManyResultsError) Error() string { func (e *TooManyResultsError) Is(err error) bool { _, ok := err.(*TooManyResultsError) //nolint:errorlint // Explicitly does *not* match down the error tree + return ok } diff --git a/internal/dsf/time.go b/internal/dsf/time.go index d88b45ce05..0885eb96eb 100644 --- a/internal/dsf/time.go +++ b/internal/dsf/time.go @@ -15,6 +15,7 @@ func Duration(_, oldValue, newValue string, _ *schema.ResourceData) bool { if err1 != nil || err2 != nil { return false } + return d1 == d2 } @@ -27,5 +28,6 @@ func TimeRFC3339(_, oldValue, newValue string, _ *schema.ResourceData) bool { if err1 != nil || err2 != nil { return false } + return t1.Equal(t2) } diff --git a/internal/httperrors/http.go b/internal/httperrors/http.go index 40a35f1591..ea8b4b1050 100644 --- a/internal/httperrors/http.go +++ b/internal/httperrors/http.go @@ -17,23 +17,27 @@ func IsHTTPCodeError(err error, statusCode int) bool { if errors.As(err, &responseError) && responseError.StatusCode == statusCode { return true } + return false } // Is404 returns true if err is an HTTP 404 error func Is404(err error) bool { notFoundError := &scw.ResourceNotFoundError{} + return IsHTTPCodeError(err, http.StatusNotFound) || errors.As(err, ¬FoundError) } func Is412(err error) bool { preConditionFailedError := &scw.PreconditionFailedError{} + return IsHTTPCodeError(err, http.StatusPreconditionFailed) || errors.As(err, &preConditionFailedError) } // Is403 returns true if err is an HTTP 403 error func Is403(err error) bool { permissionsDeniedError := &scw.PermissionsDeniedError{} + return IsHTTPCodeError(err, http.StatusForbidden) || errors.As(err, &permissionsDeniedError) } @@ -41,6 +45,7 @@ func Is403(err error) bool { func Is409(err error) bool { // check transient error transientStateError := &scw.TransientStateError{} + return IsHTTPCodeError(err, http.StatusConflict) || errors.As(err, &transientStateError) } diff --git a/internal/locality/ids.go b/internal/locality/ids.go index 6a771c9c31..975e61f157 100644 --- a/internal/locality/ids.go +++ b/internal/locality/ids.go @@ -6,6 +6,7 @@ func ExpandID(id interface{}) string { if err != nil { return id.(string) } + return ID } @@ -18,5 +19,6 @@ func ExpandIDs(data interface{}) []string { expandedID := ExpandID(s.(string)) expandedIDs = append(expandedIDs, expandedID) } + return expandedIDs } diff --git a/internal/locality/parsing.go b/internal/locality/parsing.go index 038abe5a46..68ed4b4d0d 100644 --- a/internal/locality/parsing.go +++ b/internal/locality/parsing.go @@ -11,6 +11,7 @@ func ParseLocalizedID(localizedID string) (locality, id string, err error) { if len(tab) != 2 { return "", localizedID, fmt.Errorf("cant parse localized id: %s", localizedID) } + return tab[0], tab[1], nil } @@ -20,6 +21,7 @@ func ParseLocalizedNestedID(localizedID string) (locality string, innerID, outer if len(tab) < 3 { return "", "", localizedID, fmt.Errorf("cant parse localized id: %s", localizedID) } + return tab[0], tab[1], strings.Join(tab[2:], "/"), nil } @@ -53,5 +55,6 @@ func CompareLocalities(loc1, loc2 string) bool { if strings.HasPrefix(loc1, loc2) || strings.HasPrefix(loc2, loc1) { return true } + return false } diff --git a/internal/locality/regional/ids.go b/internal/locality/regional/ids.go index 15f37dc01f..c27ab8bde7 100644 --- a/internal/locality/regional/ids.go +++ b/internal/locality/regional/ids.go @@ -52,6 +52,7 @@ func ParseNestedID(regionalNestedID string) (region scw.Region, outerID, innerID } region, err = scw.ParseRegion(loc) + return } @@ -63,6 +64,7 @@ func ParseID(regionalID string) (region scw.Region, id string, err error) { } region, err = scw.ParseRegion(loc) + return } @@ -74,5 +76,6 @@ func NewRegionalIDs(region scw.Region, ids []string) []string { for i, id := range ids { flattenedIDs[i] = NewIDString(region, id) } + return flattenedIDs } diff --git a/internal/locality/validation.go b/internal/locality/validation.go index 1f3ee3f24b..bb5a1e2d88 100644 --- a/internal/locality/validation.go +++ b/internal/locality/validation.go @@ -19,6 +19,7 @@ func ValidateStringInSliceWithWarning(correctValues []string, field string) sche AttributePath: path, }) } + return res } } diff --git a/internal/locality/zonal/ids.go b/internal/locality/zonal/ids.go index cb99f88f57..853dde7beb 100644 --- a/internal/locality/zonal/ids.go +++ b/internal/locality/zonal/ids.go @@ -57,6 +57,7 @@ func ParseID(zonedID string) (zone scw.Zone, id string, err error) { } zone, err = scw.ParseZone(rawZone) + return } @@ -68,5 +69,6 @@ func ParseNestedID(zonedNestedID string) (zone scw.Zone, outerID, innerID string } zone, err = scw.ParseZone(rawZone) + return } diff --git a/internal/meta/extractors.go b/internal/meta/extractors.go index f32370554c..3df6f62ec7 100644 --- a/internal/meta/extractors.go +++ b/internal/meta/extractors.go @@ -130,6 +130,7 @@ func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Typ if value.IsNull() { return nil, false } + return value.AsString(), true case cty.Bool: if value.IsNull() { @@ -138,16 +139,19 @@ func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Typ if value.True() { return true, true } + return false, true case cty.Number: if value.IsNull() { return nil, false } valueInt, _ := value.AsBigFloat().Int64() + return valueInt, true } } } + return nil, false } @@ -158,5 +162,6 @@ func GetRawConfigForKey(d *schema.ResourceData, key string, ty cty.Type) (interf if rawConfig.IsNull() { return nil, false } + return getKeyInRawConfigMap(rawConfig.AsValueMap(), key, ty) } diff --git a/internal/meta/meta.go b/internal/meta/meta.go index b55a1825c3..37aefaadcc 100644 --- a/internal/meta/meta.go +++ b/internal/meta/meta.go @@ -221,6 +221,7 @@ func loadProfile(ctx context.Context, d *schema.ResourceData) (*scw.Profile, *Cr tflog.Debug(ctx, "cannot guess region: "+err.Error()) } } + return profile, credentialsSource, nil } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 19ae83710a..d2b683deaa 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -332,6 +332,7 @@ func Provider(config *Config) plugin.ProviderFunc { if err != nil { return nil, diag.FromErr(err) } + return m, nil } diff --git a/internal/services/account/project.go b/internal/services/account/project.go index 4208fcf381..0106e23d6a 100644 --- a/internal/services/account/project.go +++ b/internal/services/account/project.go @@ -87,8 +87,10 @@ func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -143,6 +145,7 @@ func resourceAccountProjectDelete(ctx context.Context, d *schema.ResourceData, m return retry.NonRetryableError(err) } + return nil }) if err != nil { diff --git a/internal/services/account/testfuncs/sweep.go b/internal/services/account/testfuncs/sweep.go index 0960176e4d..21f16803fb 100644 --- a/internal/services/account/testfuncs/sweep.go +++ b/internal/services/account/testfuncs/sweep.go @@ -40,6 +40,7 @@ func testSweepAccountProject(_ string) error { return fmt.Errorf("failed to delete project: %w", err) } } + return nil }) } diff --git a/internal/services/applesilicon/clients.go b/internal/services/applesilicon/clients.go index 4992c8c9fc..d47ab90f21 100644 --- a/internal/services/applesilicon/clients.go +++ b/internal/services/applesilicon/clients.go @@ -16,6 +16,7 @@ func newAPIWithZone(d *schema.ResourceData, m interface{}) (*applesilicon.API, s if err != nil { return nil, "", err } + return asAPI, zone, nil } @@ -27,5 +28,6 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*applesilicon.API, scw.Zone, if err != nil { return nil, "", "", err } + return asAPI, zone, ID, nil } diff --git a/internal/services/applesilicon/server.go b/internal/services/applesilicon/server.go index 5e774db18a..658096a2aa 100644 --- a/internal/services/applesilicon/server.go +++ b/internal/services/applesilicon/server.go @@ -121,8 +121,10 @@ func ResourceAppleSiliconServerRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/baremetal/helper_test.go b/internal/services/baremetal/helper_test.go index bf9fefe06a..7eb002440c 100644 --- a/internal/services/baremetal/helper_test.go +++ b/internal/services/baremetal/helper_test.go @@ -12,5 +12,6 @@ func IsOfferAvailable(offerID string, zone scw.Zone, tt *acctest.TestTools) bool Zone: zone, OfferID: offerID, }) + return offer.Stock == baremetal.OfferStockAvailable } diff --git a/internal/services/baremetal/helpers.go b/internal/services/baremetal/helpers.go index 4dfad0c874..29f3b1fc84 100644 --- a/internal/services/baremetal/helpers.go +++ b/internal/services/baremetal/helpers.go @@ -34,6 +34,7 @@ func newAPIWithZone(d *schema.ResourceData, m interface{}) (*baremetal.API, scw. if err != nil { return nil, "", err } + return api, zone, nil } @@ -45,6 +46,7 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*baremetal.API, zonal.ID, er if err != nil { return nil, zonal.ID{}, err } + return api, zonal.NewID(zone, ID), nil } @@ -56,6 +58,7 @@ func newPrivateNetworkAPIWithZone(d *schema.ResourceData, m interface{}) (*barem if err != nil { return nil, "", err } + return privateNetworkAPI, zone, nil } @@ -67,6 +70,7 @@ func NewPrivateNetworkAPIWithZoneAndID(m interface{}, id string) (*baremetalV3.P if err != nil { return nil, zonal.ID{}, err } + return privateNetworkAPI, zonal.NewID(zone, ID), nil } @@ -98,6 +102,7 @@ func detachAllPrivateNetworkFromServer(ctx context.Context, d *schema.ResourceDa if err != nil && !httperrors.Is404(err) { return err } + return nil } @@ -155,6 +160,7 @@ func compareOptions(slice1, slice2 []*baremetal.ServerOption) []*baremetal.Serve } } } + return diff } diff --git a/internal/services/baremetal/option_data_source.go b/internal/services/baremetal/option_data_source.go index 8e362594ad..b07f203151 100644 --- a/internal/services/baremetal/option_data_source.go +++ b/internal/services/baremetal/option_data_source.go @@ -73,6 +73,7 @@ func dataSourceOptionRead(ctx context.Context, d *schema.ResourceData, m interfa for _, option := range res.Options { if option.Name == d.Get("name") { optionID, optionManageable, optionName = option.ID, option.Manageable, option.Name + break } } diff --git a/internal/services/baremetal/os_data_source.go b/internal/services/baremetal/os_data_source.go index 293ce71c00..e645a8d609 100644 --- a/internal/services/baremetal/os_data_source.go +++ b/internal/services/baremetal/os_data_source.go @@ -75,6 +75,7 @@ func DataSourceOSRead(ctx context.Context, d *schema.ResourceData, m interface{} for _, os := range res.Os { if os.Name == d.Get("name") && os.Version == d.Get("version") { osID, osVersion, osName = os.ID, os.Version, os.Name + break } } diff --git a/internal/services/baremetal/server.go b/internal/services/baremetal/server.go index 93b63b771e..3c5d134770 100644 --- a/internal/services/baremetal/server.go +++ b/internal/services/baremetal/server.go @@ -65,6 +65,7 @@ func ResourceServer() *schema.Resource { } // if the offer was provided by name offerName, ok := d.GetOk("offer_name") + return ok && newValue == offerName }, }, @@ -429,8 +430,10 @@ func ResourceServerRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -676,6 +679,7 @@ func ResourceServerDelete(ctx context.Context, d *schema.ResourceData, m interfa if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } @@ -693,6 +697,7 @@ func installAttributeMissing(field *baremetal.OSOSField, d *schema.ResourceData, return true } } + return false } @@ -743,5 +748,6 @@ func validateInstallConfig(ctx context.Context, d *schema.ResourceData, m interf }) } } + return diags } diff --git a/internal/services/baremetal/server_data_source.go b/internal/services/baremetal/server_data_source.go index acde378366..6e96e31ede 100644 --- a/internal/services/baremetal/server_data_source.go +++ b/internal/services/baremetal/server_data_source.go @@ -77,5 +77,6 @@ func DataSourceServerRead(ctx context.Context, d *schema.ResourceData, m interfa if d.Id() == "" { return diag.Errorf("baremetal server (%s) not found", zoneID) } + return nil } diff --git a/internal/services/baremetal/server_test.go b/internal/services/baremetal/server_test.go index 62b9446439..a27b3c02e7 100644 --- a/internal/services/baremetal/server_test.go +++ b/internal/services/baremetal/server_test.go @@ -1082,6 +1082,7 @@ func testAccChechPartitioning(tt *acctest.TestTools, n string, source string) re if !reflect.DeepEqual(&schema, server.Install.PartitioningSchema) { return fmt.Errorf("server %s has not custom partitioning install", n) } + return nil } } diff --git a/internal/services/baremetal/testfuncs/checks.go b/internal/services/baremetal/testfuncs/checks.go index ad1677e94a..3c63a83790 100644 --- a/internal/services/baremetal/testfuncs/checks.go +++ b/internal/services/baremetal/testfuncs/checks.go @@ -38,6 +38,7 @@ func CheckServerDestroy(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/baremetal/testfuncs/sweep.go b/internal/services/baremetal/testfuncs/sweep.go index ed17b57b55..3d60459b64 100644 --- a/internal/services/baremetal/testfuncs/sweep.go +++ b/internal/services/baremetal/testfuncs/sweep.go @@ -24,6 +24,7 @@ func testSweepServer(_ string) error { listServers, err := baremetalAPI.ListServers(&baremetalSDK.ListServersRequest{Zone: zone}, scw.WithAllPages()) if err != nil { logging.L.Warningf("error listing servers in (%s) in sweeper: %s", zone, err) + return nil } diff --git a/internal/services/baremetal/types.go b/internal/services/baremetal/types.go index d209f5fb17..fd884b2fa9 100644 --- a/internal/services/baremetal/types.go +++ b/internal/services/baremetal/types.go @@ -52,6 +52,7 @@ func expandPrivateNetworks(pn interface{}) map[string]*[]string { } privateNetworks[id] = ipamIPIDs } + return privateNetworks } @@ -68,6 +69,7 @@ func flattenCPUs(cpus []*baremetal.CPU) interface{} { "thread_count": cpu.ThreadCount, }) } + return flattenedCPUs } @@ -82,6 +84,7 @@ func flattenDisks(disks []*baremetal.Disk) interface{} { "capacity": disk.Capacity, }) } + return flattenedDisks } @@ -98,6 +101,7 @@ func flattenMemory(memories []*baremetal.Memory) interface{} { "is_ecc": memory.IsEcc, }) } + return flattenedMemories } @@ -114,6 +118,7 @@ func flattenIPs(ips []*baremetal.IP) interface{} { "version": ip.Version.String(), }) } + return flatIPs } @@ -132,6 +137,7 @@ func flattenIPv4s(ips []*baremetal.IP) interface{} { }) } } + return flatIPs } @@ -150,6 +156,7 @@ func flattenIPv6s(ips []*baremetal.IP) interface{} { }) } } + return flatIPs } @@ -165,6 +172,7 @@ func flattenOptions(zone scw.Zone, options []*baremetal.ServerOption) interface{ "name": option.Name, }) } + return flattenedOptions } @@ -180,5 +188,6 @@ func flattenPrivateNetworks(region scw.Region, privateNetworks []*baremetalV3.Se "updated_at": types.FlattenTime(privateNetwork.UpdatedAt), }) } + return flattenedPrivateNetworks } diff --git a/internal/services/block/snapshot.go b/internal/services/block/snapshot.go index 19e1e57ecd..fb141de8ac 100644 --- a/internal/services/block/snapshot.go +++ b/internal/services/block/snapshot.go @@ -97,8 +97,10 @@ func ResourceBlockSnapshotRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -125,8 +127,10 @@ func ResourceBlockSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/block/volume.go b/internal/services/block/volume.go index 8aa9228615..c00562e12a 100644 --- a/internal/services/block/volume.go +++ b/internal/services/block/volume.go @@ -133,8 +133,10 @@ func ResourceBlockVolumeRead(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -167,8 +169,10 @@ func ResourceBlockVolumeUpdate(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -207,8 +211,10 @@ func ResourceBlockVolumeDelete(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/cockpit/alert_manager.go b/internal/services/cockpit/alert_manager.go index 46849d3720..c40d1c5d02 100644 --- a/internal/services/cockpit/alert_manager.go +++ b/internal/services/cockpit/alert_manager.go @@ -112,6 +112,7 @@ func ResourceCockpitAlertManagerCreate(ctx context.Context, d *schema.ResourceDa } d.SetId(ResourceCockpitAlertManagerID(region, projectID)) + return ResourceCockpitAlertManagerRead(ctx, d, meta) } @@ -153,6 +154,7 @@ func ResourceCockpitAlertManagerRead(ctx context.Context, d *schema.ResourceData } } _ = d.Set("contact_points", contactPointsList) + return nil } diff --git a/internal/services/cockpit/alert_manager_test.go b/internal/services/cockpit/alert_manager_test.go index 66f99edea4..9bc9378c64 100644 --- a/internal/services/cockpit/alert_manager_test.go +++ b/internal/services/cockpit/alert_manager_test.go @@ -219,6 +219,7 @@ func testAccCheckAlertManagerEnabled(tt *acctest.TestTools, resourceName string, if alertManager.ManagedAlertsEnabled != expectedEnabled { return fmt.Errorf("alert manager enabled state %t does not match expected state %t", alertManager.AlertManagerEnabled, expectedEnabled) } + return nil } } @@ -244,6 +245,7 @@ func testAccCheckCockpitContactPointExists(tt *acctest.TestTools, resourceName s return nil } } + return fmt.Errorf("contact point with email %s not found in project %s", rs.Primary.Attributes["emails.0"], projectID) } } @@ -274,6 +276,7 @@ func testAccCockpitAlertManagerAndContactsDestroy(tt *acctest.TestTools) resourc return fmt.Errorf("cockpit alert manager (%s) is still enabled", rs.Primary.ID) } } + return nil } } diff --git a/internal/services/cockpit/cockpit.go b/internal/services/cockpit/cockpit.go index f575f3e386..1f6d475751 100644 --- a/internal/services/cockpit/cockpit.go +++ b/internal/services/cockpit/cockpit.go @@ -112,6 +112,7 @@ func ResourceCockpitCreate(ctx context.Context, d *schema.ResourceData, m interf for _, plan := range plans.Plans { if plan.Name.String() == targetPlan { planName = plan.Name.String() + break } } @@ -222,6 +223,7 @@ func ResourceCockpitUpdate(ctx context.Context, d *schema.ResourceData, m interf for _, plan := range plans.Plans { if plan.Name.String() == targetPlan { planName = plan.Name.String() + break } } diff --git a/internal/services/cockpit/cockpit_data_source.go b/internal/services/cockpit/cockpit_data_source.go index fed9bec77f..03de1a4a80 100644 --- a/internal/services/cockpit/cockpit_data_source.go +++ b/internal/services/cockpit/cockpit_data_source.go @@ -59,8 +59,10 @@ func dataSourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _ = d.Set("project_id", d.Get("project_id").(string)) @@ -102,5 +104,6 @@ func dataSourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interf _ = d.Set("endpoints", endpoints) _ = d.Set("push_url", createCockpitPushURLList(endpoints)) d.SetId(projectID) + return nil } diff --git a/internal/services/cockpit/grafana_user.go b/internal/services/cockpit/grafana_user.go index c0fb2484b7..6a9536d6a0 100644 --- a/internal/services/cockpit/grafana_user.go +++ b/internal/services/cockpit/grafana_user.go @@ -82,6 +82,7 @@ func ResourceCockpitGrafanaUserCreate(ctx context.Context, d *schema.ResourceDat _ = d.Set("password", grafanaUser.Password) d.SetId(cockpitIDWithProjectID(projectID, strconv.FormatUint(uint64(grafanaUser.ID), 10))) + return ResourceCockpitGrafanaUserRead(ctx, d, m) } @@ -97,8 +98,10 @@ func ResourceCockpitGrafanaUserRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -106,12 +109,14 @@ func ResourceCockpitGrafanaUserRead(ctx context.Context, d *schema.ResourceData, for _, user := range res.GrafanaUsers { if user.ID == grafanaUserID { grafanaUser = user + break } } if grafanaUser == nil { d.SetId("") + return nil } @@ -121,8 +126,10 @@ func ResourceCockpitGrafanaUserRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -148,6 +155,7 @@ func ResourceCockpitGrafanaUserDelete(ctx context.Context, d *schema.ResourceDat if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/cockpit/grafana_user_test.go b/internal/services/cockpit/grafana_user_test.go index b32915720c..b61f0f30f2 100644 --- a/internal/services/cockpit/grafana_user_test.go +++ b/internal/services/cockpit/grafana_user_test.go @@ -145,6 +145,7 @@ func isGrafanaUserPresent(tt *acctest.TestTools, n string) resource.TestCheckFun for _, user := range res.GrafanaUsers { if user.ID == grafanaUserID { grafanaUser = user + break } } diff --git a/internal/services/cockpit/helpers_cockpit.go b/internal/services/cockpit/helpers_cockpit.go index dc0cd8bc00..78a7e6d784 100644 --- a/internal/services/cockpit/helpers_cockpit.go +++ b/internal/services/cockpit/helpers_cockpit.go @@ -40,6 +40,7 @@ func cockpitAPIWithRegion(d *schema.ResourceData, m interface{}) (*cockpit.Regio if err != nil { return nil, "", err } + return api, region, err } @@ -50,6 +51,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*cockpit.RegionalAPI, scw. if err != nil { return nil, "", "", err } + return api, region, id, nil } @@ -84,6 +86,7 @@ func parseCockpitID(id string) (projectID string, cockpitID string, err error) { if len(parts) != 2 { return "", "", fmt.Errorf("invalid cockpit ID: %s", id) } + return parts[0], parts[1], nil } @@ -120,5 +123,6 @@ func getDefaultProjectID(ctx context.Context, m interface{}) (string, error) { if err != nil { return "", err } + return res.Projects[0].ID, nil } diff --git a/internal/services/cockpit/plan_data_source.go b/internal/services/cockpit/plan_data_source.go index 1e9c1d245f..b6e0a181d3 100644 --- a/internal/services/cockpit/plan_data_source.go +++ b/internal/services/cockpit/plan_data_source.go @@ -40,6 +40,7 @@ func DataSourceCockpitPlanRead(ctx context.Context, d *schema.ResourceData, m in for _, p := range res.Plans { if p.Name.String() == name { plan = p + break } } diff --git a/internal/services/cockpit/source.go b/internal/services/cockpit/source.go index 6ac3e43bf9..7f4b4c73e6 100644 --- a/internal/services/cockpit/source.go +++ b/internal/services/cockpit/source.go @@ -106,6 +106,7 @@ func ResourceCockpitSourceCreate(ctx context.Context, d *schema.ResourceData, me } d.SetId(regional.NewIDString(region, res.ID)) + return ResourceCockpitSourceRead(ctx, d, meta) } @@ -122,8 +123,10 @@ func ResourceCockpitSourceRead(ctx context.Context, d *schema.ResourceData, meta if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/cockpit/source_data_source.go b/internal/services/cockpit/source_data_source.go index 962a494b0a..8d72c464bb 100644 --- a/internal/services/cockpit/source_data_source.go +++ b/internal/services/cockpit/source_data_source.go @@ -86,6 +86,7 @@ func dataSourceCockpitSourceRead(ctx context.Context, d *schema.ResourceData, me if _, ok := d.GetOk("id"); ok { return fetchDataSourceByID(ctx, d, meta) } + return fetchDataSourceByFilters(ctx, d, meta) } @@ -104,6 +105,7 @@ func fetchDataSourceByID(ctx context.Context, d *schema.ResourceData, meta inter return diag.FromErr(err) } flattenDataSource(d, res) + return nil } @@ -138,13 +140,16 @@ func fetchDataSourceByFilters(ctx context.Context, d *schema.ResourceData, meta for _, ds := range res.DataSources { if ds.Name == name.(string) { flattenDataSource(d, ds) + return nil } } + return diag.Errorf("no data source found with name '%s'", name.(string)) } flattenDataSource(d, res.DataSources[0]) + return nil } diff --git a/internal/services/cockpit/token.go b/internal/services/cockpit/token.go index 916c7aee97..9c90d9e850 100644 --- a/internal/services/cockpit/token.go +++ b/internal/services/cockpit/token.go @@ -178,6 +178,7 @@ func ResourceCockpitTokenCreate(ctx context.Context, d *schema.ResourceData, m i _ = d.Set("secret_key", res.SecretKey) d.SetId(regional.NewIDString(region, res.ID)) + return ResourceCockpitTokenRead(ctx, d, m) } @@ -194,8 +195,10 @@ func ResourceCockpitTokenRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/cockpit/types.go b/internal/services/cockpit/types.go index 82e8a1075b..4feeab5fca 100644 --- a/internal/services/cockpit/types.go +++ b/internal/services/cockpit/types.go @@ -68,6 +68,7 @@ func createCockpitPushURLList(endpoints []map[string]interface{}) []map[string]i result = append(result, newEndpoint) } } + return result } @@ -116,6 +117,7 @@ func flattenCockpitTokenScopes(scopes []cockpit.TokenScope) []interface{} { for key, mappedScope := range scopeMapping { if scope == mappedScope { result[key] = true + break } } diff --git a/internal/services/container/container.go b/internal/services/container/container.go index 111000475a..245b8fe0d7 100644 --- a/internal/services/container/container.go +++ b/internal/services/container/container.go @@ -254,8 +254,10 @@ func ResourceContainerRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.Errorf("unexpected waiting container error: %s", err) } diff --git a/internal/services/container/cron.go b/internal/services/container/cron.go index 70ecb8810f..a7ea8f3730 100644 --- a/internal/services/container/cron.go +++ b/internal/services/container/cron.go @@ -114,8 +114,10 @@ func ResourceContainerCronRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -201,5 +203,6 @@ func ResourceContainerCronDelete(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } tflog.Info(ctx, "[INFO] cron job deleted") + return nil } diff --git a/internal/services/container/domain.go b/internal/services/container/domain.go index eb1f93915b..86139bd170 100644 --- a/internal/services/container/domain.go +++ b/internal/services/container/domain.go @@ -102,8 +102,10 @@ func ResourceContainerDomainRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -125,8 +127,10 @@ func ResourceContainerDomainDelete(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/container/helpers_container.go b/internal/services/container/helpers_container.go index fcd2ce4437..7c8bcc0f54 100644 --- a/internal/services/container/helpers_container.go +++ b/internal/services/container/helpers_container.go @@ -32,6 +32,7 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*container.API, sc if err != nil { return nil, "", err } + return api, region, nil } @@ -43,6 +44,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*container.API, scw.Region if err != nil { return nil, "", "", err } + return api, region, id, nil } @@ -156,6 +158,7 @@ func retryCreateContainerDomain(ctx context.Context, containerAPI *container.API if err != nil && isContainerDNSResolveError(err) { continue } + return domain, err case <-timeoutChannel: return containerAPI.CreateDomain(req, scw.WithContext(ctx)) diff --git a/internal/services/container/namespace.go b/internal/services/container/namespace.go index ab5e74e700..b792e2a0cf 100644 --- a/internal/services/container/namespace.go +++ b/internal/services/container/namespace.go @@ -144,8 +144,10 @@ func ResourceContainerNamespaceRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -211,8 +213,10 @@ func ResourceContainerNamespaceDelete(ctx context.Context, d *schema.ResourceDat if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/container/token.go b/internal/services/container/token.go index 4a3c3cc04f..7012b72de7 100644 --- a/internal/services/container/token.go +++ b/internal/services/container/token.go @@ -100,8 +100,10 @@ func ResourceContainerTokenRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/container/trigger.go b/internal/services/container/trigger.go index 67fa4ca176..15f29bb285 100644 --- a/internal/services/container/trigger.go +++ b/internal/services/container/trigger.go @@ -194,8 +194,10 @@ func ResourceContainerTriggerRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -229,8 +231,10 @@ func ResourceContainerTriggerUpdate(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/domain/helpers.go b/internal/services/domain/helpers.go index 8da36b6df9..5cadd1abc8 100644 --- a/internal/services/domain/helpers.go +++ b/internal/services/domain/helpers.go @@ -24,6 +24,7 @@ func getRecordFromTypeAndData(dnsType domain.RecordType, data string, records [] return nil, errors.New("multiple records found with same type and data") } currentRecord = r + break } } @@ -40,5 +41,6 @@ func FindDefaultReverse(address string) string { for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 { parts[i], parts[j] = parts[j], parts[i] } + return strings.Join(parts, "-") + ".instances.scw.cloud" } diff --git a/internal/services/domain/record.go b/internal/services/domain/record.go index 72868dc9e2..30a2bc67cf 100644 --- a/internal/services/domain/record.go +++ b/internal/services/domain/record.go @@ -311,6 +311,7 @@ func resourceRecordCreate(ctx context.Context, d *schema.ResourceData, m interfa d.SetId(recordID) tflog.Debug(ctx, fmt.Sprintf("record ID[%s]", recordID)) + return resourceDomainRecordRead(ctx, d, m) } @@ -338,8 +339,10 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -368,8 +371,10 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -380,6 +385,7 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m int if record == nil { d.SetId("") + return nil } @@ -387,8 +393,10 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -418,6 +426,7 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m int } else { _ = d.Set("fqdn", fmt.Sprintf("%s.%s", record.Name, dnsZone)) } + return nil } @@ -500,6 +509,7 @@ func resourceDomainRecordDelete(ctx context.Context, d *schema.ResourceData, m i if httperrors.Is404(err) || httperrors.Is403(err) { return nil } + return diag.FromErr(err) } @@ -516,6 +526,7 @@ func resourceDomainRecordDelete(ctx context.Context, d *schema.ResourceData, m i if httperrors.Is404(err) || httperrors.Is403(err) { return nil } + return diag.FromErr(err) } @@ -527,6 +538,7 @@ func resourceDomainRecordDelete(ctx context.Context, d *schema.ResourceData, m i if httperrors.Is404(err) || httperrors.Is403(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/domain/record_data_source.go b/internal/services/domain/record_data_source.go index 78300c0ae4..ea17fd2b92 100644 --- a/internal/services/domain/record_data_source.go +++ b/internal/services/domain/record_data_source.go @@ -70,5 +70,6 @@ func DataSourceRecordRead(ctx context.Context, d *schema.ResourceData, m interfa } d.SetId(fmt.Sprintf("%s/%s", d.Get("dns_zone"), recordID.(string))) + return resourceDomainRecordRead(ctx, d, m) } diff --git a/internal/services/domain/record_test.go b/internal/services/domain/record_test.go index a0d0cc852f..ded70bb407 100644 --- a/internal/services/domain/record_test.go +++ b/internal/services/domain/record_test.go @@ -832,6 +832,7 @@ func testAccCheckDomainRecordDestroy(tt *acctest.TestTools) resource.TestCheckFu if listDNSZones.TotalCount > 0 { return fmt.Errorf("zone %s still exist", rs.Primary.Attributes["dns_zone"]) } + return nil } diff --git a/internal/services/domain/types.go b/internal/services/domain/types.go index 5737331f6a..3478411911 100644 --- a/internal/services/domain/types.go +++ b/internal/services/domain/types.go @@ -110,6 +110,7 @@ func flattenDomainHTTPService(config *domain.RecordHTTPServiceConfig) interface{ ips = append(ips, ip.String()) } } + return []map[string]interface{}{ { "must_contain": types.FlattenStringPtr(config.MustContain), @@ -179,6 +180,7 @@ func expandDomainWeighted(i interface{}, ok bool) *domain.RecordWeightedConfig { }) } } + return &domain.RecordWeightedConfig{ WeightedIPs: weightedIPs, } diff --git a/internal/services/domain/zone.go b/internal/services/domain/zone.go index a1fd31a936..12f8ed410e 100644 --- a/internal/services/domain/zone.go +++ b/internal/services/domain/zone.go @@ -117,6 +117,7 @@ func resourceDomainZoneCreate(ctx context.Context, d *schema.ResourceData, m int if httperrors.Is409(err) { return resourceDomainZoneRead(ctx, d, m) } + return diag.FromErr(err) } d.SetId(fmt.Sprintf("%s.%s", dnsZone.Subdomain, dnsZone.Domain)) @@ -136,8 +137,10 @@ func resourceDomainZoneRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -177,6 +180,7 @@ func resourceZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface return diag.FromErr(err) } } + return resourceDomainZoneRead(ctx, d, m) } @@ -188,6 +192,7 @@ func resourceZoneDelete(ctx context.Context, d *schema.ResourceData, m interface if httperrors.Is404(err) || httperrors.Is403(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/domain/zone_test.go b/internal/services/domain/zone_test.go index de19df7f34..31102cb34b 100644 --- a/internal/services/domain/zone_test.go +++ b/internal/services/domain/zone_test.go @@ -95,6 +95,7 @@ func testAccCheckDomainZoneDestroy(tt *acctest.TestTools) resource.TestCheckFunc rs.Primary.Attributes["subdomain"], rs.Primary.Attributes["domain"]) } + return nil } diff --git a/internal/services/flexibleip/helpers_flexible_ip.go b/internal/services/flexibleip/helpers_flexible_ip.go index 0411569ef4..f805559a89 100644 --- a/internal/services/flexibleip/helpers_flexible_ip.go +++ b/internal/services/flexibleip/helpers_flexible_ip.go @@ -25,6 +25,7 @@ func fipAPIWithZone(d *schema.ResourceData, m interface{}) (*flexibleip.API, scw if err != nil { return nil, "", err } + return api, zone, nil } @@ -36,6 +37,7 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*flexibleip.API, scw.Zone, s if err != nil { return nil, "", "", err } + return fipAPI, zone, ID, nil } diff --git a/internal/services/flexibleip/ip.go b/internal/services/flexibleip/ip.go index 4d1ec0d9ee..f1c120414b 100644 --- a/internal/services/flexibleip/ip.go +++ b/internal/services/flexibleip/ip.go @@ -117,6 +117,7 @@ func ResourceFlexibleIPCreate(ctx context.Context, d *schema.ResourceData, m int if err != nil { return diag.FromErr(err) } + return ResourceFlexibleIPRead(ctx, d, m) } @@ -140,8 +141,10 @@ func ResourceFlexibleIPRead(ctx context.Context, d *schema.ResourceData, m inter // We check for 403 because flexible API returns 403 for a deleted IP if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/flexibleip/mac_address.go b/internal/services/flexibleip/mac_address.go index 25807b7909..a57b0069b7 100644 --- a/internal/services/flexibleip/mac_address.go +++ b/internal/services/flexibleip/mac_address.go @@ -148,8 +148,10 @@ func ResourceFlexibleIPMACRead(ctx context.Context, d *schema.ResourceData, m in // We check for 403 because flexible API returns 403 for a deleted IP if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/flexibleip/testfuncs/sweep.go b/internal/services/flexibleip/testfuncs/sweep.go index 7921836dc1..994c12a247 100644 --- a/internal/services/flexibleip/testfuncs/sweep.go +++ b/internal/services/flexibleip/testfuncs/sweep.go @@ -24,6 +24,7 @@ func testSweepFlexibleIP(_ string) error { listIPs, err := fipAPI.ListFlexibleIPs(&flexibleipSDK.ListFlexibleIPsRequest{Zone: zone}, scw.WithAllPages()) if err != nil { logging.L.Warningf("error listing ips in (%s) in sweeper: %s", zone, err) + return nil } diff --git a/internal/services/flexibleip/types.go b/internal/services/flexibleip/types.go index d0caf6063e..7620ce3e90 100644 --- a/internal/services/flexibleip/types.go +++ b/internal/services/flexibleip/types.go @@ -9,6 +9,7 @@ func flattenFlexibleIPMacAddress(mac *flexibleip.MACAddress) interface{} { if mac == nil { return nil } + return []map[string]interface{}{ { "id": mac.ID, diff --git a/internal/services/function/cron.go b/internal/services/function/cron.go index 5a9f8051d3..91e389ee5f 100644 --- a/internal/services/function/cron.go +++ b/internal/services/function/cron.go @@ -118,8 +118,10 @@ func ResourceFunctionCronRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -134,6 +136,7 @@ func ResourceFunctionCronRead(ctx context.Context, d *schema.ResourceData, m int _ = d.Set("args", args) _ = d.Set("status", cron.Status) _ = d.Set("region", region.String()) + return nil } @@ -191,8 +194,10 @@ func ResourceFunctionCronDelete(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/function/domain.go b/internal/services/function/domain.go index e5d49bcf3e..508187cc05 100644 --- a/internal/services/function/domain.go +++ b/internal/services/function/domain.go @@ -101,8 +101,10 @@ func ResourceFunctionDomainRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -124,8 +126,10 @@ func ResourceFunctionDomainDelete(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return nil } diff --git a/internal/services/function/function.go b/internal/services/function/function.go index f9c0bed336..538ed43109 100644 --- a/internal/services/function/function.go +++ b/internal/services/function/function.go @@ -266,8 +266,10 @@ func ResourceFunctionRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -319,8 +321,10 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/function/helpers.go b/internal/services/function/helpers.go index e54268558f..b189bc5c58 100644 --- a/internal/services/function/helpers.go +++ b/internal/services/function/helpers.go @@ -35,6 +35,7 @@ func functionAPIWithRegion(d *schema.ResourceData, m interface{}) (*function.API if err != nil { return nil, "", err } + return api, region, nil } @@ -46,6 +47,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*function.API, scw.Region, if err != nil { return nil, "", "", err } + return api, region, id, nil } @@ -122,6 +124,7 @@ func functionDeploy(ctx context.Context, functionAPI *function.API, region scw.R if err != nil { return errors.New("failed to deploy function") } + return nil } @@ -163,6 +166,7 @@ func retryCreateFunctionDomain(ctx context.Context, functionAPI *function.API, r if err != nil && isFunctionDNSResolveError(err) { continue } + return domain, err case <-timeoutChannel: return functionAPI.CreateDomain(req, scw.WithContext(ctx)) diff --git a/internal/services/function/namespace.go b/internal/services/function/namespace.go index df98a54ba3..86095e52fe 100644 --- a/internal/services/function/namespace.go +++ b/internal/services/function/namespace.go @@ -135,8 +135,10 @@ func ResourceFunctionNamespaceRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -163,8 +165,10 @@ func ResourceFunctionNamespaceUpdate(ctx context.Context, d *schema.ResourceData if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/function/token.go b/internal/services/function/token.go index e11a7c14c9..86e494f399 100644 --- a/internal/services/function/token.go +++ b/internal/services/function/token.go @@ -102,8 +102,10 @@ func ResourceFunctionTokenRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/function/trigger.go b/internal/services/function/trigger.go index c6f4099e48..d5603b73ed 100644 --- a/internal/services/function/trigger.go +++ b/internal/services/function/trigger.go @@ -194,8 +194,10 @@ func ResourceFunctionTriggerRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -229,8 +231,10 @@ func ResourceFunctionTriggerUpdate(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iam/api_key.go b/internal/services/iam/api_key.go index 025514a6ec..1efe7d2ff9 100644 --- a/internal/services/iam/api_key.go +++ b/internal/services/iam/api_key.go @@ -117,8 +117,10 @@ func resourceIamAPIKeyRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _ = d.Set("description", res.Description) diff --git a/internal/services/iam/api_key_data_source.go b/internal/services/iam/api_key_data_source.go index 3b297f3082..46e72cc8f2 100644 --- a/internal/services/iam/api_key_data_source.go +++ b/internal/services/iam/api_key_data_source.go @@ -14,6 +14,7 @@ func DataSourceAPIKey() *schema.Resource { dsSchema["access_key"].Required = true dsSchema["access_key"].Computed = false delete(dsSchema, "secret_key") + return &schema.Resource{ ReadContext: DataSourceIamAPIKeyRead, Schema: dsSchema, diff --git a/internal/services/iam/application.go b/internal/services/iam/application.go index 83d7b26864..67d8fc3b5a 100644 --- a/internal/services/iam/application.go +++ b/internal/services/iam/application.go @@ -87,8 +87,10 @@ func resourceIamApplicationRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _ = d.Set("name", app.Name) diff --git a/internal/services/iam/group.go b/internal/services/iam/group.go index b6e3d4662f..0d097c71f8 100644 --- a/internal/services/iam/group.go +++ b/internal/services/iam/group.go @@ -121,8 +121,10 @@ func resourceIamGroupRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iam/group_membership.go b/internal/services/iam/group_membership.go index 329883f7f1..8e03f5957d 100644 --- a/internal/services/iam/group_membership.go +++ b/internal/services/iam/group_membership.go @@ -92,6 +92,7 @@ func resourceIamGroupMembershipRead(ctx context.Context, d *schema.ResourceData, for _, groupUserID := range group.UserIDs { if groupUserID == userID { foundInGroup = true + break } } @@ -99,6 +100,7 @@ func resourceIamGroupMembershipRead(ctx context.Context, d *schema.ResourceData, for _, groupApplicationID := range group.ApplicationIDs { if groupApplicationID == applicationID { foundInGroup = true + break } } @@ -141,6 +143,7 @@ func resourceIamGroupMembershipDelete(ctx context.Context, d *schema.ResourceDat return nil } + return diag.FromErr(err) } diff --git a/internal/services/iam/policy.go b/internal/services/iam/policy.go index 5247631b07..776f5bbb1e 100644 --- a/internal/services/iam/policy.go +++ b/internal/services/iam/policy.go @@ -159,8 +159,10 @@ func resourceIamPolicyRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _ = d.Set("name", pol.Name) @@ -261,8 +263,10 @@ func resourceIamPolicyDelete(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iam/ssh_key.go b/internal/services/iam/ssh_key.go index 015765210f..d39e2c978a 100644 --- a/internal/services/iam/ssh_key.go +++ b/internal/services/iam/ssh_key.go @@ -53,6 +53,7 @@ func ResourceSSKKey() *schema.Resource { marshalledNewValue := ssh.MarshalAuthorizedKey(parsedNewValue) areEqual := bytes.Equal(marshalledOldValue, marshalledNewValue) + return areEqual }, }, @@ -119,8 +120,10 @@ func resourceIamSSHKeyRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iam/testfuncs/sweep.go b/internal/services/iam/testfuncs/sweep.go index 222deb2e01..94483e55a7 100644 --- a/internal/services/iam/testfuncs/sweep.go +++ b/internal/services/iam/testfuncs/sweep.go @@ -64,6 +64,7 @@ func testSweepUser(_ string) error { return fmt.Errorf("failed to delete user: %w", err) } } + return nil }) } @@ -121,6 +122,7 @@ func testSweepIamPolicy(_ string) error { return fmt.Errorf("failed to delete policy: %w", err) } } + return nil }) } @@ -151,6 +153,7 @@ func testSweepIamGroup(_ string) error { return fmt.Errorf("failed to delete group: %w", err) } } + return nil }) } @@ -182,6 +185,7 @@ func testSweepIamApplication(_ string) error { return fmt.Errorf("failed to delete application: %w", err) } } + return nil }) } @@ -214,6 +218,7 @@ func testSweepIamAPIKey(_ string) error { return fmt.Errorf("failed to delete api key: %w", err) } } + return nil }) } diff --git a/internal/services/iam/types.go b/internal/services/iam/types.go index c1cde3f468..9fc654c7c4 100644 --- a/internal/services/iam/types.go +++ b/internal/services/iam/types.go @@ -13,6 +13,7 @@ func expandPermissionSetNames(rawPermissions interface{}) *[]string { for _, rawPermission := range permissionSet.List() { permissions = append(permissions, rawPermission.(string)) } + return &permissions } @@ -21,6 +22,7 @@ func flattenPermissionSetNames(permissions []string) *schema.Set { for _, perm := range permissions { rawPermissions = append(rawPermissions, perm) } + return schema.NewSet(func(i interface{}) int { return types.StringHashcode(i.(string)) }, rawPermissions) @@ -43,6 +45,7 @@ func expandPolicyRuleSpecs(d interface{}) []*iam.RuleSpecs { } rules = append(rules, rule) } + return rules } @@ -67,5 +70,6 @@ func flattenPolicyRules(rules []*iam.Rule) interface{} { rawRules = append(rawRules, rawRule) } + return rawRules } diff --git a/internal/services/iam/user.go b/internal/services/iam/user.go index 3f19ab33ff..bbd0aaa293 100644 --- a/internal/services/iam/user.go +++ b/internal/services/iam/user.go @@ -107,8 +107,10 @@ func resourceIamUserRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/inference/deployment.go b/internal/services/inference/deployment.go index 6789aef461..a4ac9995ca 100644 --- a/internal/services/inference/deployment.go +++ b/internal/services/inference/deployment.go @@ -254,8 +254,10 @@ func ResourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -302,6 +304,7 @@ func ResourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter if publicEndpoints != nil { _ = d.Set("public_endpoint", publicEndpoints) } + return nil } @@ -315,8 +318,10 @@ func ResourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/inference/testfuncs/checks.go b/internal/services/inference/testfuncs/checks.go index 344c5384ec..5f9afb2e9a 100644 --- a/internal/services/inference/testfuncs/checks.go +++ b/internal/services/inference/testfuncs/checks.go @@ -36,6 +36,7 @@ func IsDeploymentDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/instance/helpers_instance.go b/internal/services/instance/helpers_instance.go index 379273981e..ee2c78af86 100644 --- a/internal/services/instance/helpers_instance.go +++ b/internal/services/instance/helpers_instance.go @@ -55,6 +55,7 @@ func newAPIWithZone(d *schema.ResourceData, m interface{}) (*instance.API, scw.Z if err != nil { return nil, "", err } + return instanceAPI, zone, nil } @@ -66,6 +67,7 @@ func NewAPIWithZoneAndID(m interface{}, zonedID string) (*instance.API, scw.Zone if err != nil { return nil, "", "", err } + return instanceAPI, zone, ID, nil } @@ -77,6 +79,7 @@ func NewAPIWithZoneAndNestedID(m interface{}, zonedNestedID string) (*instance.A if err != nil { return nil, "", "", "", err } + return instanceAPI, zone, innerID, outerID, nil } @@ -92,6 +95,7 @@ func orderVolumes(v map[string]*instance.Volume) []*instance.Volume { for _, index := range indexes { orderedVolumes = append(orderedVolumes, v[index]) } + return orderedVolumes } @@ -107,6 +111,7 @@ func sortVolumeServer(v map[string]*instance.VolumeServer) []*instance.VolumeSer for _, index := range indexes { sortedVolumes = append(sortedVolumes, v[index]) } + return sortedVolumes } @@ -122,6 +127,7 @@ func serverStateFlatten(fromState instance.ServerState) (string, error) { case instance.ServerStateLocked: return "", errors.New("server is locked, please contact Scaleway support: https://console.scaleway.com/support/tickets") } + return "", errors.New("server is in an invalid state, someone else might be executing action at the same time") } @@ -203,6 +209,7 @@ func reachState(ctx context.Context, api *BlockAndInstanceAPI, zone scw.Zone, se return err } } + return nil } @@ -218,6 +225,7 @@ func getServerType(ctx context.Context, apiInstance *instance.API, zone scw.Zone if serverType == nil { tflog.Warn(ctx, "unrecognized server type: "+commercialType) } + return serverType } @@ -248,6 +256,7 @@ func validateLocalVolumeSizes(volumes map[string]*instance.VolumeServerTemplate, } maxSize := humanize.Bytes(uint64(volumeConstraint.MaxSize)) + return fmt.Errorf("%s total local volume size must be between %s and %s", commercialType, minSize, maxSize) } @@ -305,6 +314,7 @@ func newPrivateNICHandler(api *instance.API, server string, zone scw.Zone) (*pri serverID: server, zone: zone, } + return handler, handler.flatPrivateNICs() } @@ -386,6 +396,7 @@ func (ph *privateNICsHandler) set(d *schema.ResourceData) error { } privateNetworks = append(privateNetworks, keyRaw.(map[string]interface{})) } + return d.Set("private_network", privateNetworks) } @@ -398,6 +409,7 @@ func (ph *privateNICsHandler) get(key string) (interface{}, error) { if !ok { return nil, fmt.Errorf("could not find private network ID %s on locality %s", key, loc) } + return map[string]interface{}{ "pn_id": key, "mac_address": pn.MacAddress, @@ -437,9 +449,11 @@ func retryUpdateReverseDNS(ctx context.Context, instanceAPI *instance.API, req * if err != nil && IsIPReverseDNSResolveError(err) { continue } + return err case <-timeoutChannel: _, err := instanceAPI.UpdateIP(req, scw.WithContext(ctx)) + return err } } @@ -478,6 +492,7 @@ func instanceServerAdditionalVolumeTemplate(api *BlockAndInstanceAPI, zone scw.Z if err != nil { return nil, err } + return vol.VolumeTemplate(), nil } diff --git a/internal/services/instance/image.go b/internal/services/instance/image.go index e9fcdc3862..0ef18d8c7a 100644 --- a/internal/services/instance/image.go +++ b/internal/services/instance/image.go @@ -236,8 +236,10 @@ func ResourceInstanceImageRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/image_data_source.go b/internal/services/instance/image_data_source.go index 482650cfd8..8336e6eaa1 100644 --- a/internal/services/instance/image_data_source.go +++ b/internal/services/instance/image_data_source.go @@ -134,6 +134,7 @@ func DataSourceInstanceImageRead(ctx context.Context, d *schema.ResourceData, m for _, image := range matchingImages { if image.Name == d.Get("name").(string) { imageID = image.ID + break } } diff --git a/internal/services/instance/ip.go b/internal/services/instance/ip.go index 1b12a2185f..aeba6851d6 100644 --- a/internal/services/instance/ip.go +++ b/internal/services/instance/ip.go @@ -105,6 +105,7 @@ func ResourceInstanceIPCreate(ctx context.Context, d *schema.ResourceData, m int } d.SetId(zonal.NewIDString(zone, res.IP.ID)) + return ResourceInstanceIPRead(ctx, d, m) } @@ -144,8 +145,10 @@ func ResourceInstanceIPRead(ctx context.Context, d *schema.ResourceData, m inter // We check for 403 because instanceSDK API returns 403 for a deleted IP if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -195,8 +198,10 @@ func ResourceInstanceIPDelete(ctx context.Context, d *schema.ResourceData, m int // We check for 403 because instanceSDK API returns 403 for a deleted IP if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/ip_data_source.go b/internal/services/instance/ip_data_source.go index e1548cea61..aa5bce82d2 100644 --- a/internal/services/instance/ip_data_source.go +++ b/internal/services/instance/ip_data_source.go @@ -58,8 +58,10 @@ func DataSourceInstanceIPRead(ctx context.Context, d *schema.ResourceData, m int // We check for 403 because instance API returns 403 for a deleted IP if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } ID = res.IP.ID diff --git a/internal/services/instance/ip_reverse_dns.go b/internal/services/instance/ip_reverse_dns.go index 195946588e..baf27dc363 100644 --- a/internal/services/instance/ip_reverse_dns.go +++ b/internal/services/instance/ip_reverse_dns.go @@ -99,13 +99,16 @@ func ResourceInstanceIPReverseDNSRead(ctx context.Context, d *schema.ResourceDat // We check for 403 because instanceSDK API returns 403 for a deleted IP if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _ = d.Set("zone", string(zone)) _ = d.Set("reverse", res.IP.Reverse) + return nil } @@ -155,5 +158,6 @@ func ResourceInstanceIPReverseDNSDelete(ctx context.Context, d *schema.ResourceD } d.SetId("") + return nil } diff --git a/internal/services/instance/placement_group.go b/internal/services/instance/placement_group.go index 5bf41a27aa..1b658b4228 100644 --- a/internal/services/instance/placement_group.go +++ b/internal/services/instance/placement_group.go @@ -87,6 +87,7 @@ func ResourceInstancePlacementGroupCreate(ctx context.Context, d *schema.Resourc } d.SetId(zonal.NewIDString(zone, res.PlacementGroup.ID)) + return ResourceInstancePlacementGroupRead(ctx, d, m) } @@ -103,8 +104,10 @@ func ResourceInstancePlacementGroupRead(ctx context.Context, d *schema.ResourceD if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/placement_group_test.go b/internal/services/instance/placement_group_test.go index ad6083cb43..ba55e61d69 100644 --- a/internal/services/instance/placement_group_test.go +++ b/internal/services/instance/placement_group_test.go @@ -194,6 +194,7 @@ func isPlacementGroupDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/instance/private_nic.go b/internal/services/instance/private_nic.go index 013db78b07..3c045bd975 100644 --- a/internal/services/instance/private_nic.go +++ b/internal/services/instance/private_nic.go @@ -141,8 +141,10 @@ func ResourceInstancePrivateNICRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -207,6 +209,7 @@ func ResourceInstancePrivateNICDelete(ctx context.Context, d *schema.ResourceDat if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } @@ -219,6 +222,7 @@ func ResourceInstancePrivateNICDelete(ctx context.Context, d *schema.ResourceDat if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } @@ -227,6 +231,7 @@ func ResourceInstancePrivateNICDelete(ctx context.Context, d *schema.ResourceDat if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/security_group.go b/internal/services/instance/security_group.go index 8b0c765fc3..f859a546c5 100644 --- a/internal/services/instance/security_group.go +++ b/internal/services/instance/security_group.go @@ -150,8 +150,10 @@ func ResourceInstanceSecurityGroupRead(ctx context.Context, d *schema.ResourceDa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -174,6 +176,7 @@ func ResourceInstanceSecurityGroupRead(ctx context.Context, d *schema.ResourceDa _ = d.Set("inbound_rule", inboundRules) _ = d.Set("outbound_rule", outboundRules) } + return nil } @@ -476,6 +479,7 @@ func securityGroupRuleFlatten(rule *instanceSDK.SecurityGroupRule) (map[string]i "port_range": fmt.Sprintf("%d-%d", portFrom, portTo), "action": rule.Action.String(), } + return res, nil } @@ -485,6 +489,7 @@ func SecurityGroupRuleEquals(ruleA, ruleB *instanceSDK.SecurityGroupRule) (bool, if v == nil { return 0 } + return *v } portFromEqual := zeroIfNil(ruleA.DestPortFrom) == zeroIfNil(ruleB.DestPortFrom) diff --git a/internal/services/instance/security_group_data_source.go b/internal/services/instance/security_group_data_source.go index 90409785d3..4bb7b5a876 100644 --- a/internal/services/instance/security_group_data_source.go +++ b/internal/services/instance/security_group_data_source.go @@ -68,5 +68,6 @@ func DataSourceInstanceSecurityGroupRead(ctx context.Context, d *schema.Resource zonedID := datasource.NewZonedID(securityGroupID, zone) d.SetId(zonedID) _ = d.Set("security_group_id", zonedID) + return ResourceInstanceSecurityGroupRead(ctx, d, m) } diff --git a/internal/services/instance/security_group_rules.go b/internal/services/instance/security_group_rules.go index 2f4c22cbd2..1f51fab733 100644 --- a/internal/services/instance/security_group_rules.go +++ b/internal/services/instance/security_group_rules.go @@ -66,8 +66,10 @@ func ResourceInstanceSecurityGroupRulesRead(ctx context.Context, d *schema.Resou if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/security_group_test.go b/internal/services/instance/security_group_test.go index 655165904b..8a90fbc076 100644 --- a/internal/services/instance/security_group_test.go +++ b/internal/services/instance/security_group_test.go @@ -481,6 +481,7 @@ func isSecurityGroupRuleMatching(tt *acctest.TestTools, name string, index int, if ok, _ := instance.SecurityGroupRuleEquals(expected, actual); !ok { return fmt.Errorf("security group does not match %v, %v", actual, expected) } + return nil }) } diff --git a/internal/services/instance/server.go b/internal/services/instance/server.go index 507e5cbef8..31482d1cfe 100644 --- a/internal/services/instance/server.go +++ b/internal/services/instance/server.go @@ -576,8 +576,10 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i if errorCheck(err, "is not found") { log.Printf("[WARN] instance %s not found droping from state", d.Id()) d.SetId("") + return nil } + return diag.FromErr(err) } //// @@ -748,6 +750,7 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i return nil } + return nil } @@ -1244,11 +1247,13 @@ func customDiffInstanceServerImage(ctx context.Context, diff *schema.ResourceDif if httperrors.Is404(err) { return diff.ForceNew("image") } + return err } if marketplaceImage.Label != image.ID { return diff.ForceNew("image") } + return nil } diff --git a/internal/services/instance/server_data_source.go b/internal/services/instance/server_data_source.go index a55a658969..d217b1ee1e 100644 --- a/internal/services/instance/server_data_source.go +++ b/internal/services/instance/server_data_source.go @@ -68,5 +68,6 @@ func DataSourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m zonedID := datasource.NewZonedID(serverID, zone) d.SetId(zonedID) _ = d.Set("server_id", zonedID) + return ResourceInstanceServerRead(ctx, d, m) } diff --git a/internal/services/instance/server_test.go b/internal/services/instance/server_test.go index 32d4cc2409..daa5fb11a9 100644 --- a/internal/services/instance/server_test.go +++ b/internal/services/instance/server_test.go @@ -1438,6 +1438,7 @@ func serverIDsAreDifferent(nameFirst, nameSecond string) resource.TestCheckFunc if idFirst == idSecond { return fmt.Errorf("IDs of both resources were equal when they should not have been (%s and %s)", nameFirst, nameSecond) } + return nil } } diff --git a/internal/services/instance/servers_data_source.go b/internal/services/instance/servers_data_source.go index 1d3aad0338..f06b0d2574 100644 --- a/internal/services/instance/servers_data_source.go +++ b/internal/services/instance/servers_data_source.go @@ -179,6 +179,7 @@ func DataSourceInstanceServersRead(ctx context.Context, d *schema.ResourceData, state, err := serverStateFlatten(server.State) if err != nil { diags = append(diags, diag.FromErr(err)...) + continue } rawServer["state"] = state @@ -210,6 +211,7 @@ func DataSourceInstanceServersRead(ctx context.Context, d *schema.ResourceData, prefixLength, err := strconv.Atoi(server.IPv6.Netmask) //nolint:staticcheck if err != nil { diags = append(diags, diag.FromErr(fmt.Errorf("failed to read ipv6 netmask: %w", err))...) + continue } diff --git a/internal/services/instance/snapshot.go b/internal/services/instance/snapshot.go index 4e50b0ee0f..f72068374d 100644 --- a/internal/services/instance/snapshot.go +++ b/internal/services/instance/snapshot.go @@ -173,8 +173,10 @@ func ResourceInstanceSnapshotRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/testfuncs/checks.go b/internal/services/instance/testfuncs/checks.go index b672f0e43c..dee00bb493 100644 --- a/internal/services/instance/testfuncs/checks.go +++ b/internal/services/instance/testfuncs/checks.go @@ -162,6 +162,7 @@ func DoesImageExists(tt *acctest.TestTools, n string) resource.TestCheckFunc { if err != nil { return err } + return nil } } diff --git a/internal/services/instance/testfuncs/sweep.go b/internal/services/instance/testfuncs/sweep.go index edd621b1b2..4d300aac1a 100644 --- a/internal/services/instance/testfuncs/sweep.go +++ b/internal/services/instance/testfuncs/sweep.go @@ -65,6 +65,7 @@ func testSweepVolume(_ string) error { } } } + return nil }) } @@ -102,6 +103,7 @@ func testSweepServer(_ string) error { listServers, err := instanceAPI.ListServers(&instanceSDK.ListServersRequest{Zone: zone}, scw.WithAllPages()) if err != nil { logging.L.Warningf("error listing servers in (%s) in sweeper: %s", zone, err) + return nil } @@ -140,6 +142,7 @@ func testSweepSecurityGroup(_ string) error { }, scw.WithAllPages()) if err != nil { logging.L.Warningf("error listing security groups in sweeper: %s", err) + return nil } @@ -170,6 +173,7 @@ func testSweepPlacementGroup(_ string) error { }, scw.WithAllPages()) if err != nil { logging.L.Warningf("error listing placement groups in (%s) in sweeper: %s", zone, err) + return nil } @@ -194,6 +198,7 @@ func testSweepIP(_ string) error { listIPs, err := instanceAPI.ListIPs(&instanceSDK.ListIPsRequest{Zone: zone}, scw.WithAllPages()) if err != nil { logging.L.Warningf("error listing ips in (%s) in sweeper: %s", zone, err) + return nil } diff --git a/internal/services/instance/types.go b/internal/services/instance/types.go index 812d09dfb8..f285af5cdd 100644 --- a/internal/services/instance/types.go +++ b/internal/services/instance/types.go @@ -19,6 +19,7 @@ func (ph *privateNICsHandler) flatPrivateNICs() error { } ph.privateNICsMap = privateNICsMap + return nil } @@ -33,6 +34,7 @@ func expandImageExtraVolumesTemplates(snapshotIDs []string) map[string]*instance } volTemplates[strconv.Itoa(i+1)] = volTemplate } + return volTemplates } @@ -47,6 +49,7 @@ func expandImageExtraVolumesUpdateTemplates(snapshotIDs []string) map[string]*in } volTemplates[strconv.Itoa(i+1)] = volTemplate } + return volTemplates } @@ -75,6 +78,7 @@ func flattenImageExtraVolumes(volumes map[string]*instance.Volume, zone scw.Zone } volumesFlat = append(volumesFlat, volumeFlat) } + return volumesFlat } diff --git a/internal/services/instance/user_data.go b/internal/services/instance/user_data.go index cd5df66365..e8f066f186 100644 --- a/internal/services/instance/user_data.go +++ b/internal/services/instance/user_data.go @@ -118,8 +118,10 @@ func ResourceInstanceUserDataRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/volume.go b/internal/services/instance/volume.go index 738efcc1ec..58a453a2bd 100644 --- a/internal/services/instance/volume.go +++ b/internal/services/instance/volume.go @@ -142,8 +142,10 @@ func ResourceInstanceVolumeRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(fmt.Errorf("couldn't read volume: %v", err)) } @@ -242,6 +244,7 @@ func ResourceInstanceVolumeDelete(ctx context.Context, d *schema.ResourceData, m if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/instance/volume_data_source.go b/internal/services/instance/volume_data_source.go index 16238f9397..85972274a2 100644 --- a/internal/services/instance/volume_data_source.go +++ b/internal/services/instance/volume_data_source.go @@ -70,5 +70,6 @@ func DataSourceInstanceVolumeRead(ctx context.Context, d *schema.ResourceData, m if err != nil { return diag.FromErr(err) } + return ResourceInstanceVolumeRead(ctx, d, m) } diff --git a/internal/services/instance/volume_test.go b/internal/services/instance/volume_test.go index cb95f89f45..a7651fa586 100644 --- a/internal/services/instance/volume_test.go +++ b/internal/services/instance/volume_test.go @@ -247,6 +247,7 @@ func isVolumeDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/instance/waiters.go b/internal/services/instance/waiters.go index 93bef9c787..39e7175d9e 100644 --- a/internal/services/instance/waiters.go +++ b/internal/services/instance/waiters.go @@ -37,6 +37,7 @@ func waitForVolume(ctx context.Context, api *instance.API, zone scw.Zone, id str Timeout: scw.TimeDurationPtr(timeout), RetryInterval: &retryInterval, }, scw.WithContext(ctx)) + return volume, err } diff --git a/internal/services/iot/data_source_iot_device.go b/internal/services/iot/data_source_iot_device.go index 6b0608cacf..1ce39063cc 100644 --- a/internal/services/iot/data_source_iot_device.go +++ b/internal/services/iot/data_source_iot_device.go @@ -83,5 +83,6 @@ func DataSourceIotDeviceRead(ctx context.Context, d *schema.ResourceData, m inte if d.Id() == "" { return diag.Errorf("IOT Device not found (%s)", regionalID) } + return nil } diff --git a/internal/services/iot/data_source_iot_hub.go b/internal/services/iot/data_source_iot_hub.go index 9bc5f2ce4b..d23cd23623 100644 --- a/internal/services/iot/data_source_iot_hub.go +++ b/internal/services/iot/data_source_iot_hub.go @@ -75,5 +75,6 @@ func DataSourceIotHubRead(ctx context.Context, d *schema.ResourceData, m interfa if d.Id() == "" { return diag.Errorf("IOT Hub not found (%s)", regionalID) } + return nil } diff --git a/internal/services/iot/device.go b/internal/services/iot/device.go index 6c25e24089..44c307a43f 100644 --- a/internal/services/iot/device.go +++ b/internal/services/iot/device.go @@ -284,8 +284,10 @@ func ResourceIotDeviceRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iot/helpers_iot.go b/internal/services/iot/helpers_iot.go index cfcb9e497a..09e5082010 100644 --- a/internal/services/iot/helpers_iot.go +++ b/internal/services/iot/helpers_iot.go @@ -33,6 +33,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*iot.API, scw.Region, stri iotAPI := iot.NewAPI(meta.ExtractScwClient(m)) region, ID, err := regional.ParseID(id) + return iotAPI, region, ID, err } @@ -60,6 +61,7 @@ func extractRestHeaders(d *schema.ResourceData, key string) map[string]string { for k, v := range data { stringMap[k] = v.(string) } + return stringMap } @@ -67,6 +69,7 @@ func computeIotHubCaURL(productPlan iot.HubProductPlan, region scw.Region) strin if productPlan == "plan_shared" || productPlan == "plan_unknown" { return "" } + return mqttCaURLDownload + string(region) + "/" + mqttCaFileName } @@ -82,5 +85,6 @@ func computeIotHubMQTTCa(ctx context.Context, mqttCaURL string, m interface{}) ( } defer mqttCa.Body.Close() resp, _ := io.ReadAll(mqttCa.Body) + return string(resp), nil } diff --git a/internal/services/iot/hub.go b/internal/services/iot/hub.go index 55b490528a..d4865d573e 100644 --- a/internal/services/iot/hub.go +++ b/internal/services/iot/hub.go @@ -219,8 +219,10 @@ func ResourceIotHubRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iot/hub_test.go b/internal/services/iot/hub_test.go index a3d10cfd92..ddd4645289 100644 --- a/internal/services/iot/hub_test.go +++ b/internal/services/iot/hub_test.go @@ -134,6 +134,7 @@ func isHubDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/iot/network.go b/internal/services/iot/network.go index 62e56051d8..eb171e4205 100644 --- a/internal/services/iot/network.go +++ b/internal/services/iot/network.go @@ -122,8 +122,10 @@ func ResourceIotNetworkRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/iot/routes.go b/internal/services/iot/routes.go index a5413742b6..cfef42ffac 100644 --- a/internal/services/iot/routes.go +++ b/internal/services/iot/routes.go @@ -264,8 +264,10 @@ func ResourceIotRouteRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -327,6 +329,7 @@ func ResourceIotRouteDelete(ctx context.Context, d *schema.ResourceData, m inter if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/iot/testfuncs/sweep.go b/internal/services/iot/testfuncs/sweep.go index c9abce7fd0..c820e398ca 100644 --- a/internal/services/iot/testfuncs/sweep.go +++ b/internal/services/iot/testfuncs/sweep.go @@ -24,6 +24,7 @@ func testSweepHub(_ string) error { listHubs, err := iotAPI.ListHubs(&iotSDK.ListHubsRequest{Region: region}, scw.WithAllPages()) if err != nil { logging.L.Debugf("sweeper: destroying the iot hub in (%s)", region) + return fmt.Errorf("error listing hubs in (%s) in sweeper: %s", region, err) } diff --git a/internal/services/ipam/helpers.go b/internal/services/ipam/helpers.go index e149dc6f79..b74d67be26 100644 --- a/internal/services/ipam/helpers.go +++ b/internal/services/ipam/helpers.go @@ -36,6 +36,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*ipam.API, scw.Region, str if err != nil { return nil, "", "", err } + return ipamAPI, region, ID, err } diff --git a/internal/services/ipam/ip.go b/internal/services/ipam/ip.go index fba710c59c..1be7753afc 100644 --- a/internal/services/ipam/ip.go +++ b/internal/services/ipam/ip.go @@ -230,8 +230,10 @@ func ResourceIPAMIPRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/ipam/ip_reverse_dns.go b/internal/services/ipam/ip_reverse_dns.go index 2c75d7eb31..5ef95772b4 100644 --- a/internal/services/ipam/ip_reverse_dns.go +++ b/internal/services/ipam/ip_reverse_dns.go @@ -101,8 +101,10 @@ func ResourceIPAMIPReverseDNSRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -112,6 +114,7 @@ func ResourceIPAMIPReverseDNSRead(ctx context.Context, d *schema.ResourceData, m if reverse.Hostname == managedHostname && reverse.Address.String() == managedAddress { _ = d.Set("hostname", reverse.Hostname) _ = d.Set("address", types.FlattenIPPtr(reverse.Address)) + break } } @@ -166,5 +169,6 @@ func ResourceIPAMIPReverseDNSDelete(ctx context.Context, d *schema.ResourceData, } d.SetId("") + return nil } diff --git a/internal/services/ipam/ip_reverse_dns_test.go b/internal/services/ipam/ip_reverse_dns_test.go index 501b54666f..ca238633d4 100644 --- a/internal/services/ipam/ip_reverse_dns_test.go +++ b/internal/services/ipam/ip_reverse_dns_test.go @@ -100,8 +100,10 @@ func testCheckResourceAttrExpectedIPAddress(resourceName string) resource.TestCh if output, ok := rootModule.Outputs["calculated_ip_address"]; ok && output != nil { expectedIPAddress := output.Value.(string) + return resource.TestCheckResourceAttr(resourceName, "address", expectedIPAddress)(s) } + return errors.New("calculated_ip_address output not set or is nil") } } diff --git a/internal/services/ipam/types.go b/internal/services/ipam/types.go index 4c1ffe90bf..1731e434d6 100644 --- a/internal/services/ipam/types.go +++ b/internal/services/ipam/types.go @@ -34,6 +34,7 @@ func expandIPSource(raw interface{}) *ipam.Source { } rawMap := raw.([]interface{})[0].(map[string]interface{}) + return &ipam.Source{ Zonal: types.ExpandStringPtr(rawMap["zonal"].(string)), PrivateNetworkID: types.ExpandStringPtr(locality.ExpandID(rawMap["private_network_id"].(string))), @@ -47,6 +48,7 @@ func expandCustomResource(raw interface{}) *ipam.CustomResource { } rawMap := raw.([]interface{})[0].(map[string]interface{}) + return &ipam.CustomResource{ MacAddress: rawMap["mac_address"].(string), Name: types.ExpandStringPtr(rawMap["name"].(string)), @@ -57,6 +59,7 @@ func flattenIPSource(source *ipam.Source, privateNetworkID string) interface{} { if source == nil { return nil } + return []map[string]interface{}{ { "zonal": types.FlattenStringPtr(source.Zonal), @@ -70,6 +73,7 @@ func flattenIPResource(resource *ipam.Resource) interface{} { if resource == nil { return nil } + return []map[string]interface{}{ { "type": resource.Type.String(), @@ -96,6 +100,7 @@ func flattenIPReverses(reverses []*ipam.Reverse) interface{} { for _, reverse := range reverses { rawReverses = append(rawReverses, flattenIPReverse(reverse)) } + return rawReverses } @@ -105,5 +110,6 @@ func checkSubnetIDInFlattenedSubnets(subnetID string, flattenedSubnets interface return true } } + return false } diff --git a/internal/services/jobs/definition.go b/internal/services/jobs/definition.go index f34bd229ba..f8dd6cfa7b 100644 --- a/internal/services/jobs/definition.go +++ b/internal/services/jobs/definition.go @@ -150,8 +150,10 @@ func ResourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/k8s/cluster.go b/internal/services/k8s/cluster.go index 8657bae3b4..446692d390 100644 --- a/internal/services/k8s/cluster.go +++ b/internal/services/k8s/cluster.go @@ -274,6 +274,7 @@ func ResourceCluster() *schema.Resource { } } } + return nil }, func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error { @@ -301,6 +302,7 @@ func ResourceCluster() *schema.Resource { return err } } + return nil }, ), @@ -524,8 +526,10 @@ func ResourceK8SClusterRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -885,6 +889,7 @@ func ResourceK8SClusterDelete(ctx context.Context, d *schema.ResourceData, m int if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } diff --git a/internal/services/k8s/cluster_data_source.go b/internal/services/k8s/cluster_data_source.go index 60a9c66a60..4a816ae24e 100644 --- a/internal/services/k8s/cluster_data_source.go +++ b/internal/services/k8s/cluster_data_source.go @@ -69,5 +69,6 @@ func DataSourceK8SClusterRead(ctx context.Context, d *schema.ResourceData, m int regionalizedID := datasource.NewRegionalID(clusterID, region) d.SetId(regionalizedID) _ = d.Set("cluster_id", regionalizedID) + return ResourceK8SClusterRead(ctx, d, m) } diff --git a/internal/services/k8s/cluster_test.go b/internal/services/k8s/cluster_test.go index d5af27058b..9c9006fd99 100644 --- a/internal/services/k8s/cluster_test.go +++ b/internal/services/k8s/cluster_test.go @@ -23,8 +23,10 @@ func testAccK8SClusterGetLatestK8SVersion(tt *acctest.TestTools) string { } if len(versions.Versions) > 1 { latestK8SVersion := versions.Versions[0].Name + return latestK8SVersion } + return "" } @@ -37,8 +39,10 @@ func testAccK8SClusterGetLatestK8SVersionMinor(tt *acctest.TestTools) string { if len(versions.Versions) > 1 { latestK8SVersion := versions.Versions[0].Name latestK8SVersionMinor, _ := k8s.GetMinorVersionFromFull(latestK8SVersion) + return latestK8SVersionMinor } + return "" } @@ -50,8 +54,10 @@ func testAccK8SClusterGetPreviousK8SVersion(tt *acctest.TestTools) string { } if len(versions.Versions) > 1 { previousK8SVersion := versions.Versions[1].Name + return previousK8SVersion } + return "" } @@ -64,8 +70,10 @@ func testAccK8SClusterGetPreviousK8SVersionMinor(tt *acctest.TestTools) string { if len(versions.Versions) > 1 { previousK8SVersion := versions.Versions[1].Name previousK8SVersionMinor, _ := k8s.GetMinorVersionFromFull(previousK8SVersion) + return previousK8SVersionMinor } + return "" } @@ -554,6 +562,7 @@ func testAccCheckK8SClusterDestroy(tt *acctest.TestTools) resource.TestCheckFunc return err } } + return nil } } diff --git a/internal/services/k8s/helpers_k8s.go b/internal/services/k8s/helpers_k8s.go index 84214bc05a..0ad008832b 100644 --- a/internal/services/k8s/helpers_k8s.go +++ b/internal/services/k8s/helpers_k8s.go @@ -28,6 +28,7 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*k8s.API, scw.Regi if err != nil { return nil, "", err } + return k8sAPI, region, nil } @@ -38,6 +39,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*k8s.API, scw.Region, stri if err != nil { return nil, "", "", err } + return k8sAPI, region, ID, nil } @@ -73,6 +75,7 @@ func k8sGetLatestVersionFromMinor(ctx context.Context, k8sAPI *k8s.API, region s return v.Name, nil } } + return "", fmt.Errorf("no available upstream version found for %s", version) } @@ -91,6 +94,7 @@ func convertNodes(res *k8s.ListNodesResponse) []map[string]interface{} { } result = append(result, n) } + return result } diff --git a/internal/services/k8s/pool.go b/internal/services/k8s/pool.go index c5b4510c71..0d32635db1 100644 --- a/internal/services/k8s/pool.go +++ b/internal/services/k8s/pool.go @@ -353,8 +353,10 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -509,5 +511,6 @@ func ResourceK8SPoolCustomDiff(_ context.Context, diff *schema.ResourceDiff, _ i return err } } + return nil } diff --git a/internal/services/k8s/pool_data_source.go b/internal/services/k8s/pool_data_source.go index f3b55fa874..1e97173ba8 100644 --- a/internal/services/k8s/pool_data_source.go +++ b/internal/services/k8s/pool_data_source.go @@ -72,5 +72,6 @@ func DataSourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interf regionalizedID := datasource.NewRegionalID(poolID, region) d.SetId(regionalizedID) _ = d.Set("pool_id", regionalizedID) + return ResourceK8SPoolRead(ctx, d, m) } diff --git a/internal/services/k8s/pool_test.go b/internal/services/k8s/pool_test.go index 1e93c5939e..2e446724db 100644 --- a/internal/services/k8s/pool_test.go +++ b/internal/services/k8s/pool_test.go @@ -988,6 +988,7 @@ func testAccCheckK8SPoolNodesOneOfIsDeleting(name string) resource.TestCheckFunc nodesZeroStatus == "deleting" && nodesOneStatus == "ready" { return nil } + return fmt.Errorf("nodes status were not as expected: got %q for nodes.0 and %q for nodes.1", nodesZeroStatus, nodesOneStatus) } } diff --git a/internal/services/k8s/waiters.go b/internal/services/k8s/waiters.go index ccb6e46ebe..b242c78d57 100644 --- a/internal/services/k8s/waiters.go +++ b/internal/services/k8s/waiters.go @@ -58,6 +58,7 @@ func waitClusterStatus(ctx context.Context, k8sAPI *k8s.API, cluster *k8s.Cluste if status == k8s.ClusterStatusDeleted && httperrors.Is404(err) { return cluster, nil } + return cluster, err } @@ -83,5 +84,6 @@ func waitPoolReady(ctx context.Context, k8sAPI *k8s.API, region scw.Region, pool if pool.Status != k8s.PoolStatusReady { return nil, fmt.Errorf("pool %s has state %s, wants %s", poolID, pool.Status, k8s.PoolStatusReady) } + return pool, nil } diff --git a/internal/services/lb/acl.go b/internal/services/lb/acl.go index d11aa1bccc..0203afcd13 100644 --- a/internal/services/lb/acl.go +++ b/internal/services/lb/acl.go @@ -197,8 +197,10 @@ func resourceLbACLRead(ctx context.Context, d *schema.ResourceData, m interface{ if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/lb/backend.go b/internal/services/lb/backend.go index 9faaa15685..08a68f331b 100644 --- a/internal/services/lb/backend.go +++ b/internal/services/lb/backend.go @@ -340,8 +340,10 @@ func resourceLbBackendCreate(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -431,8 +433,10 @@ func resourceLbBackendCreate(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -454,8 +458,10 @@ func resourceLbBackendRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -496,8 +502,10 @@ func resourceLbBackendRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -520,8 +528,10 @@ func resourceLbBackendUpdate(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -633,8 +643,10 @@ func resourceLbBackendUpdate(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -656,8 +668,10 @@ func resourceLbBackendDelete(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -674,8 +688,10 @@ func resourceLbBackendDelete(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/lb/backend_data_source.go b/internal/services/lb/backend_data_source.go index 1ace2c740f..e480dc8f98 100644 --- a/internal/services/lb/backend_data_source.go +++ b/internal/services/lb/backend_data_source.go @@ -70,5 +70,6 @@ func DataSourceLbBackendRead(ctx context.Context, d *schema.ResourceData, m inte if err != nil { return diag.FromErr(err) } + return resourceLbBackendRead(ctx, d, m) } diff --git a/internal/services/lb/certificate.go b/internal/services/lb/certificate.go index bbd9937a08..3ab154a9fe 100644 --- a/internal/services/lb/certificate.go +++ b/internal/services/lb/certificate.go @@ -156,8 +156,10 @@ func resourceLbCertificateCreate(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -172,8 +174,10 @@ func resourceLbCertificateCreate(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -193,8 +197,10 @@ func resourceLbCertificateRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -220,6 +226,7 @@ func resourceLbCertificateRead(ctx context.Context, d *schema.ResourceData, m in Detail: errDetails, }) } + return diags } @@ -248,8 +255,10 @@ func resourceLbCertificateUpdate(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } diff --git a/internal/services/lb/certificate_data_source.go b/internal/services/lb/certificate_data_source.go index 8c656af912..32400da1f5 100644 --- a/internal/services/lb/certificate_data_source.go +++ b/internal/services/lb/certificate_data_source.go @@ -70,5 +70,6 @@ func DataSourceLbCertificateRead(ctx context.Context, d *schema.ResourceData, m if err != nil { return diag.FromErr(err) } + return resourceLbCertificateRead(ctx, d, m) } diff --git a/internal/services/lb/data_source_lb_ip.go b/internal/services/lb/data_source_lb_ip.go index e810e57f4b..b259fef2c0 100644 --- a/internal/services/lb/data_source_lb_ip.go +++ b/internal/services/lb/data_source_lb_ip.go @@ -74,5 +74,6 @@ func DataSourceLbIPRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { return diag.FromErr(err) } + return resourceLbIPRead(ctx, d, m) } diff --git a/internal/services/lb/frontend.go b/internal/services/lb/frontend.go index c73334150f..3535622adc 100644 --- a/internal/services/lb/frontend.go +++ b/internal/services/lb/frontend.go @@ -252,8 +252,10 @@ func resourceLbFrontendCreate(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -304,8 +306,10 @@ func resourceLbFrontendRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -350,6 +354,7 @@ func flattenLBACLs(acls []*lbSDK.ACL) interface{} { for _, apiACL := range acls { rawACLs = append(rawACLs, flattenLbACL(apiACL)) } + return rawACLs } @@ -396,6 +401,7 @@ func resourceLbFrontendUpdateACL(ctx context.Context, d *schema.ResourceData, lb if err != nil { return diag.FromErr(err) } + continue } // old acl doesn't exist, create a new one @@ -421,6 +427,7 @@ func resourceLbFrontendUpdateACL(ctx context.Context, d *schema.ResourceData, lb return diag.FromErr(err) } } + return nil } @@ -430,6 +437,7 @@ func expandsLBACLs(raw interface{}) []*lbSDK.ACL { for _, rawACL := range d { newACL = append(newACL, expandLbACL(rawACL)) } + return newACL } @@ -449,8 +457,10 @@ func resourceLbFrontendUpdate(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -519,5 +529,6 @@ func ACLEquals(aclA, aclB *lbSDK.ACL) bool { if !cmp.Equal(aclA.Action, aclB.Action) { return false } + return true } diff --git a/internal/services/lb/frontend_data_source.go b/internal/services/lb/frontend_data_source.go index dd7b315de0..04212b7cb6 100644 --- a/internal/services/lb/frontend_data_source.go +++ b/internal/services/lb/frontend_data_source.go @@ -70,5 +70,6 @@ func DataSourceLbFrontendRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { return diag.FromErr(err) } + return resourceLbFrontendRead(ctx, d, m) } diff --git a/internal/services/lb/frontend_test.go b/internal/services/lb/frontend_test.go index 726a70bef7..77768f9a63 100644 --- a/internal/services/lb/frontend_test.go +++ b/internal/services/lb/frontend_test.go @@ -540,6 +540,7 @@ func isACLCorrect(tt *acctest.TestTools, frontendName string, expectedAcls []*lb if testAcl.Name == "" { testAcl.Name = apiAcl.Name } + return lb.ACLEquals(&testAcl, &apiAcl) } diff --git a/internal/services/lb/helpers_lb.go b/internal/services/lb/helpers_lb.go index aade7482f1..8db946fdda 100644 --- a/internal/services/lb/helpers_lb.go +++ b/internal/services/lb/helpers_lb.go @@ -35,6 +35,7 @@ func lbAPIWithZone(d *schema.ResourceData, m interface{}) (*lbSDK.ZonedAPI, scw. if err != nil { return nil, "", err } + return lbAPI, zone, nil } @@ -46,6 +47,7 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*lbSDK.ZonedAPI, scw.Zone, s if err != nil { return nil, "", "", err } + return lbAPI, zone, ID, nil } @@ -185,6 +187,7 @@ func normalizeIPSubnet(ip string) string { if strings.HasSuffix(ip, "/32") { return strings.TrimSuffix(ip, "/32") } + return ip } @@ -216,5 +219,6 @@ func customizeDiffAssignFlexibleIPv6(_ context.Context, diff *schema.ResourceDif if oldValue.(bool) && !newValue.(bool) { return diff.ForceNew("assign_flexible_ipv6") } + return nil } diff --git a/internal/services/lb/ip.go b/internal/services/lb/ip.go index 2174b20b57..d818ebbdb4 100644 --- a/internal/services/lb/ip.go +++ b/internal/services/lb/ip.go @@ -118,8 +118,10 @@ func resourceLbIPRead(ctx context.Context, d *schema.ResourceData, m interface{} if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -129,8 +131,10 @@ func resourceLbIPRead(ctx context.Context, d *schema.ResourceData, m interface{} if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } @@ -178,17 +182,21 @@ func resourceLbIPUpdate(ctx context.Context, d *schema.ResourceData, m interface if httperrors.Is403(errGet) { return retry.RetryableError(errGet) } + return retry.NonRetryableError(errGet) } ip = res + return nil }) if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -197,8 +205,10 @@ func resourceLbIPUpdate(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } @@ -232,8 +242,10 @@ func resourceLbIPUpdate(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } @@ -258,10 +270,12 @@ func resourceLbIPDelete(ctx context.Context, d *schema.ResourceData, m interface if httperrors.Is403(errGet) { return retry.RetryableError(errGet) } + return retry.NonRetryableError(errGet) } ip = res + return nil }) if err != nil { @@ -274,8 +288,10 @@ func resourceLbIPDelete(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } @@ -295,8 +311,10 @@ func resourceLbIPDelete(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } diff --git a/internal/services/lb/lb.go b/internal/services/lb/lb.go index d3cdecd750..dbf1c3bc12 100644 --- a/internal/services/lb/lb.go +++ b/internal/services/lb/lb.go @@ -277,8 +277,10 @@ func resourceLbRead(ctx context.Context, d *schema.ResourceData, m interface{}) if err != nil { if httperrors.Is404(err) || httperrors.Is403(err) { d.SetId("") + return nil } + return diag.FromErr(err) } // set the region from zone @@ -322,9 +324,11 @@ func resourceLbRead(ctx context.Context, d *schema.ResourceData, m interface{}) if httperrors.Is404(err) { return nil } + return diag.FromErr(err) } _ = d.Set("private_network", flattenPrivateNetworkConfigs(privateNetworks)) + return nil } @@ -400,6 +404,7 @@ func resourceLbUpdate(ctx context.Context, d *schema.ResourceData, m interface{} for id := range newIPIDsSet { if id != ipv4ID { ipv6ID = id + break } } @@ -532,6 +537,7 @@ func resourceLbUpdate(ctx context.Context, d *schema.ResourceData, m interface{} if err != nil && !httperrors.Is404(err) { return diag.FromErr(err) } + return diag.Errorf("attaching private network with id: %s on error state. please check your config", pn.PrivateNetworkID) } } diff --git a/internal/services/lb/lb_data_source.go b/internal/services/lb/lb_data_source.go index 5f4fc5dcef..b926dee16c 100644 --- a/internal/services/lb/lb_data_source.go +++ b/internal/services/lb/lb_data_source.go @@ -80,5 +80,6 @@ func DataSourceLbRead(ctx context.Context, d *schema.ResourceData, m interface{} if err != nil { return diag.FromErr(err) } + return resourceLbRead(ctx, d, m) } diff --git a/internal/services/lb/lb_test.go b/internal/services/lb/lb_test.go index c72e02d059..d69609a68f 100644 --- a/internal/services/lb/lb_test.go +++ b/internal/services/lb/lb_test.go @@ -281,6 +281,7 @@ func TestAccLB_Migrate(t *testing.T) { return fmt.Errorf("resource not found: %s", "scaleway_lb.main") } lbID = rs.Primary.ID + return nil }, resource.TestCheckResourceAttr("scaleway_lb.main", "type", "LB-S"), @@ -311,6 +312,7 @@ func TestAccLB_Migrate(t *testing.T) { if rs.Primary.ID != lbID { return errors.New("LB id has changed") } + return nil }, resource.TestCheckResourceAttr("scaleway_lb.main", "type", "LB-GP-M"), diff --git a/internal/services/lb/route.go b/internal/services/lb/route.go index 6519fe0b02..279efece13 100644 --- a/internal/services/lb/route.go +++ b/internal/services/lb/route.go @@ -122,8 +122,10 @@ func resourceLbRouteRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/lb/route_data_source.go b/internal/services/lb/route_data_source.go index ae18abedb5..b59708c123 100644 --- a/internal/services/lb/route_data_source.go +++ b/internal/services/lb/route_data_source.go @@ -40,5 +40,6 @@ func DataSourceLbRouteRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { return diag.FromErr(err) } + return resourceLbRouteRead(ctx, d, m) } diff --git a/internal/services/lb/types.go b/internal/services/lb/types.go index 454dbf365b..413992dbe5 100644 --- a/internal/services/lb/types.go +++ b/internal/services/lb/types.go @@ -43,6 +43,7 @@ func flattenPrivateNetworkConfigs(privateNetworks []*lb.PrivateNetwork) interfac "ipam_ids": regional.NewRegionalIDs(pnRegion, pn.IpamIDs), }) } + return pnI } @@ -87,6 +88,7 @@ func expandLbBackendMarkdownAction(raw interface{}) lb.OnMarkedDownAction { if raw == "none" { return lb.OnMarkedDownActionOnMarkedDownActionNone } + return lb.OnMarkedDownAction(raw.(string)) } @@ -118,6 +120,7 @@ func flattenLbHCTCP(config *lb.HealthCheckTCPConfig) interface{} { if config == nil { return nil } + return []map[string]interface{}{ {}, } @@ -127,6 +130,7 @@ func expandLbHCTCP(raw interface{}) *lb.HealthCheckTCPConfig { if raw == nil || len(raw.([]interface{})) != 1 { return nil } + return &lb.HealthCheckTCPConfig{} } @@ -134,6 +138,7 @@ func flattenLbHCHTTP(config *lb.HealthCheckHTTPConfig) interface{} { if config == nil { return nil } + return []map[string]interface{}{ { "uri": config.URI, @@ -149,6 +154,7 @@ func expandLbHCHTTP(raw interface{}) *lb.HealthCheckHTTPConfig { return nil } rawMap := raw.([]interface{})[0].(map[string]interface{}) + return &lb.HealthCheckHTTPConfig{ URI: rawMap["uri"].(string), Method: rawMap["method"].(string), @@ -161,6 +167,7 @@ func flattenLbHCHTTPS(config *lb.HealthCheckHTTPSConfig) interface{} { if config == nil { return nil } + return []map[string]interface{}{ { "uri": config.URI, @@ -178,6 +185,7 @@ func expandLbHCHTTPS(raw interface{}) *lb.HealthCheckHTTPSConfig { } rawMap := raw.([]interface{})[0].(map[string]interface{}) + return &lb.HealthCheckHTTPSConfig{ URI: rawMap["uri"].(string), Method: rawMap["method"].(string), @@ -200,6 +208,7 @@ func expandLbLetsEncrypt(raw interface{}) *lb.CreateCertificateRequestLetsencryp for _, alternativeName := range alternativeNames { config.SubjectAlternativeName = append(config.SubjectAlternativeName, alternativeName.(string)) } + return config } @@ -212,6 +221,7 @@ func expandLbCustomCertificate(raw interface{}) *lb.CreateCertificateRequestCust config := &lb.CreateCertificateRequestCustomCertificate{ CertificateChain: rawMap["certificate_chain"].(string), } + return config } @@ -227,6 +237,7 @@ func flattenLbBackendMarkdownAction(action lb.OnMarkedDownAction) interface{} { if action == lb.OnMarkedDownActionOnMarkedDownActionNone { return "none" } + return action.String() } @@ -236,6 +247,7 @@ func flattenLbACL(acl *lb.ACL) interface{} { "match": flattenLbACLMatch(acl.Match), "action": flattenLbACLAction(acl.Action), } + return res } @@ -277,6 +289,7 @@ func expandLbACLAction(raw interface{}) *lb.ACLAction { return nil } rawMap := raw.([]interface{})[0].(map[string]interface{}) + return &lb.ACLAction{ Type: lb.ACLActionType(rawMap["type"].(string)), Redirect: expandLbACLActionRedirect(rawMap["redirect"]), @@ -287,6 +300,7 @@ func flattenLbACLActionRedirect(redirect *lb.ACLActionRedirect) interface{} { if redirect == nil { return nil } + return []map[string]interface{}{ { "type": redirect.Type, @@ -301,6 +315,7 @@ func expandLbACLActionRedirect(raw interface{}) *lb.ACLActionRedirect { return nil } rawMap := raw.([]interface{})[0].(map[string]interface{}) + return &lb.ACLActionRedirect{ Type: lb.ACLActionRedirectRedirectType(rawMap["type"].(string)), Target: rawMap["target"].(string), @@ -328,6 +343,7 @@ func expandPrivateNetworks(data interface{}) ([]*lb.PrivateNetwork, error) { pns = append(pns, privateNetwork) } + return pns, nil } @@ -335,6 +351,7 @@ func expandLbPrivateNetworkStaticConfig(raw interface{}) *lb.PrivateNetworkStati if raw == nil || len(raw.([]interface{})) < 1 { return nil } + return &lb.PrivateNetworkStaticConfig{ IPAddress: types.ExpandStringsPtr(raw), } @@ -352,6 +369,7 @@ func expandLbPrivateNetworkDHCPConfig(raw interface{}) *lb.PrivateNetworkDHCPCon if raw == nil || !raw.(bool) { return nil } + return &lb.PrivateNetworkDHCPConfig{} } @@ -388,6 +406,7 @@ func attachLBPrivateNetworks(ctx context.Context, lbAPI *lb.ZonedAPI, zone scw.Z } tflog.Debug(ctx, fmt.Sprintf("DHCP config: %v", pn.DHCPConfig)) //nolint:staticcheck tflog.Debug(ctx, fmt.Sprintf("Static config: %v", pn.StaticConfig)) //nolint:staticcheck + return nil, fmt.Errorf("attaching private network with id: %s on error state. please check your config", pn.PrivateNetworkID) } } @@ -411,6 +430,7 @@ func flattenLbInstances(instances []*lb.Instance) interface{} { "zone": instance.Zone, }) } + return flattenedInstances } @@ -430,6 +450,7 @@ func flattenLbIPs(ips []*lb.IP) interface{} { "lb_id": types.FlattenStringPtr(ip.LBID), }) } + return flattenedIPs } @@ -441,5 +462,6 @@ func flattenLBIPIDs(zone scw.Zone, ips []*lb.IP) []string { for i, ip := range ips { flattenedIPs[i] = zonal.NewIDString(zone, ip.ID) } + return flattenedIPs } diff --git a/internal/services/marketplace/helpers.go b/internal/services/marketplace/helpers.go index 3d18c6682d..14244db7bd 100644 --- a/internal/services/marketplace/helpers.go +++ b/internal/services/marketplace/helpers.go @@ -15,5 +15,6 @@ func marketplaceAPIWithZone(d *schema.ResourceData, m interface{}) (*marketplace if err != nil { return nil, "", err } + return marketplaceAPI, zone, nil } diff --git a/internal/services/mnq/helpers_mnq.go b/internal/services/mnq/helpers_mnq.go index 5df1015d1c..7a455a0260 100644 --- a/internal/services/mnq/helpers_mnq.go +++ b/internal/services/mnq/helpers_mnq.go @@ -114,6 +114,7 @@ func (a ARN) String() string { if a.ExtraResourceID == "" { return fmt.Sprintf("arn:scw:%s:%s:project-%s:%s", a.Subject, a.Region, a.ProjectID, a.ResourceName) } + return fmt.Sprintf("arn:scw:%s:%s:project-%s:%s:%s", a.Subject, a.Region, a.ProjectID, a.ResourceName, a.ExtraResourceID) } @@ -177,6 +178,7 @@ func setResourceValue(values map[string]interface{}, resourcePath string, value } setResourceValue(values[parts[0]].([]interface{})[0].(map[string]interface{}), strings.Join(parts[2:], "."), value, resourceSchemas[parts[0]].Elem.(*schema.Resource).Schema) + return } @@ -222,6 +224,7 @@ func awsResourceDataToAttribute(awsAttributes map[string]string, awsAttribute st } awsAttributes[awsAttribute] = s + return nil } @@ -285,5 +288,6 @@ func IsAWSErrorCode(err error, code string) bool { if errors.As(err, &apiErr) && apiErr.Code == code { return true } + return false } diff --git a/internal/services/mnq/helpers_mnq_queue.go b/internal/services/mnq/helpers_mnq_queue.go index bcf8d6400d..8e0fa96a3b 100644 --- a/internal/services/mnq/helpers_mnq_queue.go +++ b/internal/services/mnq/helpers_mnq_queue.go @@ -80,6 +80,7 @@ func NewSQSClient(ctx context.Context, httpClient *http.Client, region string, e if err != nil { return nil, err } + return sqs.NewFromConfig(customConfig), nil } diff --git a/internal/services/mnq/helpers_mnq_sns.go b/internal/services/mnq/helpers_mnq_sns.go index 59c97b2e93..c358750010 100644 --- a/internal/services/mnq/helpers_mnq_sns.go +++ b/internal/services/mnq/helpers_mnq_sns.go @@ -79,6 +79,7 @@ func NewSNSClient(ctx context.Context, httpClient *http.Client, region string, e if err != nil { return nil, err } + return sns.NewFromConfig(customConfig), nil } diff --git a/internal/services/mnq/nats_account.go b/internal/services/mnq/nats_account.go index 42535a6743..d6111ff83c 100644 --- a/internal/services/mnq/nats_account.go +++ b/internal/services/mnq/nats_account.go @@ -74,8 +74,10 @@ func ResourceMNQNatsAccountRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/mnq/nats_credentials.go b/internal/services/mnq/nats_credentials.go index 8d88bf6690..51be2ed5b1 100644 --- a/internal/services/mnq/nats_credentials.go +++ b/internal/services/mnq/nats_credentials.go @@ -84,8 +84,10 @@ func ResourceMNQNatsCredentialsRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/mnq/sns.go b/internal/services/mnq/sns.go index 6986e8a083..ecb6cde9f3 100644 --- a/internal/services/mnq/sns.go +++ b/internal/services/mnq/sns.go @@ -88,6 +88,7 @@ func ResourceMNQSNSDelete(ctx context.Context, d *schema.ResourceData, m interfa if sns.Status == mnq.SnsInfoStatusDisabled { d.SetId("") + return nil } diff --git a/internal/services/mnq/sns_credentials.go b/internal/services/mnq/sns_credentials.go index 57b3289f66..bd1286f6ad 100644 --- a/internal/services/mnq/sns_credentials.go +++ b/internal/services/mnq/sns_credentials.go @@ -119,8 +119,10 @@ func ResourceMNQSNSCredentialsRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/mnq/sns_test.go b/internal/services/mnq/sns_test.go index 2dd06139e8..6164bd1278 100644 --- a/internal/services/mnq/sns_test.go +++ b/internal/services/mnq/sns_test.go @@ -90,6 +90,7 @@ func isSNSDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { if httperrors.Is404(err) { return nil } + return err } diff --git a/internal/services/mnq/sns_topic_subscription_test.go b/internal/services/mnq/sns_topic_subscription_test.go index f1676b6f86..a3207ad24b 100644 --- a/internal/services/mnq/sns_topic_subscription_test.go +++ b/internal/services/mnq/sns_topic_subscription_test.go @@ -139,6 +139,7 @@ func isSNSTopicSubscriptionDestroyed(ctx context.Context, tt *acctest.TestTools) return nil } } + return err } diff --git a/internal/services/mnq/sns_topic_test.go b/internal/services/mnq/sns_topic_test.go index ae5ec2ddb5..b1f8790cd7 100644 --- a/internal/services/mnq/sns_topic_test.go +++ b/internal/services/mnq/sns_topic_test.go @@ -195,6 +195,7 @@ func isSNSTopicDestroyed(ctx context.Context, tt *acctest.TestTools) resource.Te if errors.As(err, &apiErr) && apiErr.Code == "AccessDeniedException" { return nil } + return err } diff --git a/internal/services/mnq/sqs.go b/internal/services/mnq/sqs.go index d5471c4a2a..b0eeaf0ca4 100644 --- a/internal/services/mnq/sqs.go +++ b/internal/services/mnq/sqs.go @@ -88,6 +88,7 @@ func ResourceMNQSQSDelete(ctx context.Context, d *schema.ResourceData, m interfa if sqs.Status == mnq.SqsInfoStatusDisabled { d.SetId("") + return nil } diff --git a/internal/services/mnq/sqs_credentials.go b/internal/services/mnq/sqs_credentials.go index 99c520667e..7fb871b693 100644 --- a/internal/services/mnq/sqs_credentials.go +++ b/internal/services/mnq/sqs_credentials.go @@ -119,8 +119,10 @@ func ResourceMNQSQSCredentialsRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/mnq/sqs_queue.go b/internal/services/mnq/sqs_queue.go index fb56fc2c2b..3b0ab1f8b0 100644 --- a/internal/services/mnq/sqs_queue.go +++ b/internal/services/mnq/sqs_queue.go @@ -302,6 +302,7 @@ func ResourceMNQSQSQueueDelete(ctx context.Context, d *schema.ResourceData, m in if IsAWSErrorCode(err, AWSErrNonExistentQueue) { return nil } + return diag.Errorf("failed to delete SQS Queue (%s): %s", d.Id(), err) } diff --git a/internal/services/mnq/sqs_test.go b/internal/services/mnq/sqs_test.go index 192b7523a7..1b42469f07 100644 --- a/internal/services/mnq/sqs_test.go +++ b/internal/services/mnq/sqs_test.go @@ -130,6 +130,7 @@ func isSQSDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { if httperrors.Is404(err) { // Project may have been deleted return nil } + return err } diff --git a/internal/services/mnq/testfuncs/sweep.go b/internal/services/mnq/testfuncs/sweep.go index 7d7fa089f4..621e1df872 100644 --- a/internal/services/mnq/testfuncs/sweep.go +++ b/internal/services/mnq/testfuncs/sweep.go @@ -85,6 +85,7 @@ func testSweepSQS(_ string) error { }) if err != nil { logging.L.Debugf("sweeper: error (%s)", err) + return err } } @@ -143,6 +144,7 @@ func testSweepSNS(_ string) error { }) if err != nil { logging.L.Debugf("sweeper: error (%s)", err) + return err } } diff --git a/internal/services/mongodb/helpers.go b/internal/services/mongodb/helpers.go index 43fa3309a7..7bf386427c 100644 --- a/internal/services/mongodb/helpers.go +++ b/internal/services/mongodb/helpers.go @@ -32,6 +32,7 @@ func newAPIWithZone(d *schema.ResourceData, m interface{}) (*mongodb.API, scw.Zo if err != nil { return nil, "", err } + return newAPI(m), zone, nil } @@ -44,6 +45,7 @@ func newAPIWithZoneAndRegion(d *schema.ResourceData, m interface{}) (*mongodb.AP if err != nil { return nil, "", "", err } + return newAPI(m), zone, region, nil } @@ -52,6 +54,7 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*mongodb.API, scw. if err != nil { return nil, "", err } + return newAPI(m), region, nil } @@ -61,6 +64,7 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*mongodb.API, scw.Zone, stri if err != nil { return nil, "", "", err } + return newAPI(m), zone, ID, nil } @@ -73,6 +77,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*mongodb.API, scw.Region, if err != nil { return nil, "", "", err } + return newAPI(m), region, ID, nil } @@ -81,6 +86,7 @@ func waitForInstance(ctx context.Context, api *mongodb.API, region scw.Region, i if transport.DefaultWaitRetryInterval != nil { retryInterval = *transport.DefaultWaitRetryInterval } + return api.WaitForInstance(&mongodb.WaitForInstanceRequest{ Timeout: scw.TimeDurationPtr(timeout), InstanceID: id, diff --git a/internal/services/mongodb/instance.go b/internal/services/mongodb/instance.go index 093f6348d7..715f829bb6 100644 --- a/internal/services/mongodb/instance.go +++ b/internal/services/mongodb/instance.go @@ -250,8 +250,10 @@ func ResourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -393,6 +395,7 @@ func ResourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter if err != nil { return diag.FromErr(err) } + return append(diags, ResourceInstanceRead(ctx, d, m)...) } @@ -421,5 +424,6 @@ func ResourceInstanceDelete(ctx context.Context, d *schema.ResourceData, m inter } d.SetId("") + return nil } diff --git a/internal/services/mongodb/instance_test.go b/internal/services/mongodb/instance_test.go index 7f964233de..5d499bf046 100644 --- a/internal/services/mongodb/instance_test.go +++ b/internal/services/mongodb/instance_test.go @@ -247,6 +247,7 @@ func IsInstanceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/mongodb/snapshot.go b/internal/services/mongodb/snapshot.go index e429f0a6de..ac66d1c01c 100644 --- a/internal/services/mongodb/snapshot.go +++ b/internal/services/mongodb/snapshot.go @@ -208,5 +208,6 @@ func ResourceSnapshotDelete(_ context.Context, d *schema.ResourceData, m interfa } d.SetId("") + return nil } diff --git a/internal/services/mongodb/snapshot_test.go b/internal/services/mongodb/snapshot_test.go index 2520adf2b7..3459bf8d28 100644 --- a/internal/services/mongodb/snapshot_test.go +++ b/internal/services/mongodb/snapshot_test.go @@ -125,6 +125,7 @@ func isSnapshotDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } diff --git a/internal/services/mongodb/types.go b/internal/services/mongodb/types.go index 40f03e62a7..da968802fb 100644 --- a/internal/services/mongodb/types.go +++ b/internal/services/mongodb/types.go @@ -15,7 +15,9 @@ func flattenPublicNetwork(endpoints []*mongodb.Endpoint) (interface{}, bool) { "port": endpoint.Port, "dns_record": endpoint.DNSRecords[0], }) + break } + return publicFlat, len(publicFlat) != 0 } diff --git a/internal/services/object/bucket.go b/internal/services/object/bucket.go index b1003f7c0a..7798722240 100644 --- a/internal/services/object/bucket.go +++ b/internal/services/object/bucket.go @@ -286,6 +286,7 @@ func resourceObjectBucketUpdate(ctx context.Context, d *schema.ResourceData, m i }) if err != nil { tflog.Error(ctx, fmt.Sprintf("Couldn't update bucket ACL: %s", err)) + return diag.FromErr(fmt.Errorf("couldn't update bucket ACL: %s", err)) } } @@ -348,6 +349,7 @@ func resourceBucketLifecycleUpdate(ctx context.Context, conn *s3.Client, d *sche if err != nil { return fmt.Errorf("error removing S3 lifecycle for bucket %s: %w", bucket, err) } + return nil } @@ -485,6 +487,7 @@ func resourceObjectBucketRead(ctx context.Context, d *schema.ResourceData, m int bucketFound, objectLockFound := addReadBucketErrorDiagnostic(&diags, err, "object lock configuration", ErrCodeObjectLockConfigurationNotFoundError) if !bucketFound { d.SetId("") + return diags } if !objectLockFound { @@ -509,6 +512,7 @@ func resourceObjectBucketRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if bucketFound, _ := addReadBucketErrorDiagnostic(&diags, err, "objects", ""); !bucketFound { d.SetId("") + return diags } } @@ -521,6 +525,7 @@ func resourceObjectBucketRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if bucketFound, _ := addReadBucketErrorDiagnostic(&diags, err, "tags", ErrCodeNoSuchTagSet); !bucketFound { d.SetId("") + return diags } } else { @@ -550,6 +555,7 @@ func resourceObjectBucketRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if bucketFound, _ := addReadBucketErrorDiagnostic(&diags, err, "versioning", ""); !bucketFound { d.SetId("") + return diags } } @@ -562,6 +568,7 @@ func resourceObjectBucketRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if bucketFound, _ := addReadBucketErrorDiagnostic(&diags, err, "lifecycle configuration", ErrCodeNoSuchLifecycleConfiguration); !bucketFound { d.SetId("") + return diags } } diff --git a/internal/services/object/bucket_acl.go b/internal/services/object/bucket_acl.go index 31a8d8badd..f31b85727d 100644 --- a/internal/services/object/bucket_acl.go +++ b/internal/services/object/bucket_acl.go @@ -392,6 +392,7 @@ func resourceBucketACLRead(ctx context.Context, d *schema.ResourceData, m interf if !d.IsNewResource() && errors.As(err, new(*s3Types.NoSuchBucket)) { tflog.Warn(ctx, fmt.Sprintf("[WARN] Object Bucket ACL (%s) not found, removing from state", d.Id())) d.SetId("") + return nil } @@ -421,6 +422,7 @@ func BucketACLCreateResourceID(region scw.Region, bucket, acl string) string { if acl == "" { return regional.NewIDString(region, bucket) } + return regional.NewIDString(region, strings.Join([]string{bucket, acl}, BucketACLSeparator)) } diff --git a/internal/services/object/bucket_acl_test.go b/internal/services/object/bucket_acl_test.go index 0e9b7d048f..8833e92aa3 100644 --- a/internal/services/object/bucket_acl_test.go +++ b/internal/services/object/bucket_acl_test.go @@ -381,6 +381,7 @@ func testAccObjectBucketACLCheck(tt *acctest.TestTools, name string, expectedACL if len(errs) > 0 { return fmt.Errorf("unexpected result: %w", errors.Join(errs...)) } + return nil } } @@ -404,6 +405,7 @@ func s3ACLAreEqual(expected string, actual *s3.GetBucketAclOutput) (errs []error case "private": if len(grantsMap) != 1 { errs = append(errs, fmt.Errorf("expected 1 grant, but got %d", len(grantsMap))) + return errs } if grantsMap["FULL_CONTROL"] != ownerID { @@ -413,6 +415,7 @@ func s3ACLAreEqual(expected string, actual *s3.GetBucketAclOutput) (errs []error case "public-read": if len(grantsMap) != 2 { errs = append(errs, fmt.Errorf("expected 2 grants, but got %d", len(grantsMap))) + return errs } if grantsMap["FULL_CONTROL"] != ownerID { @@ -425,6 +428,7 @@ func s3ACLAreEqual(expected string, actual *s3.GetBucketAclOutput) (errs []error case "public-read-write": if len(grantsMap) != 3 { errs = append(errs, fmt.Errorf("expected 3 grants, but got %d", len(grantsMap))) + return errs } if grantsMap["FULL_CONTROL"] != ownerID { @@ -440,6 +444,7 @@ func s3ACLAreEqual(expected string, actual *s3.GetBucketAclOutput) (errs []error case "authenticated-read": if len(grantsMap) != 2 { errs = append(errs, fmt.Errorf("expected 2 grants, but got %d", len(grantsMap))) + return errs } if grantsMap["FULL_CONTROL"] != ownerID { @@ -449,5 +454,6 @@ func s3ACLAreEqual(expected string, actual *s3.GetBucketAclOutput) (errs []error errs = append(errs, fmt.Errorf("expected READ to be granted to %q, instead got %q", s3ACLGranteeAuthenticatedUsers, grantsMap["READ"])) } } + return errs } diff --git a/internal/services/object/bucket_lock_configuration.go b/internal/services/object/bucket_lock_configuration.go index dee60039c3..277a54eb82 100644 --- a/internal/services/object/bucket_lock_configuration.go +++ b/internal/services/object/bucket_lock_configuration.go @@ -131,6 +131,7 @@ func resourceObjectLockConfigurationRead(ctx context.Context, d *schema.Resource if !d.IsNewResource() && errors.As(err, new(*s3Types.NoSuchBucket)) { tflog.Warn(ctx, fmt.Sprintf("Object Bucket Lock Configuration (%s) not found, removing from state", d.Id())) d.SetId("") + return nil } @@ -141,6 +142,7 @@ func resourceObjectLockConfigurationRead(ctx context.Context, d *schema.Resource tflog.Warn(ctx, fmt.Sprintf("Object Bucket Lock Configuration (%s) not found, removing from state", d.Id())) d.SetId("") + return nil } diff --git a/internal/services/object/bucket_policy.go b/internal/services/object/bucket_policy.go index c415470f86..57c300fc9a 100644 --- a/internal/services/object/bucket_policy.go +++ b/internal/services/object/bucket_policy.go @@ -89,6 +89,7 @@ func resourceObjectBucketPolicyCreate(ctx context.Context, d *schema.ResourceDat if err != nil { return retry.NonRetryableError(err) } + return nil }) if TimedOut(err) { @@ -124,6 +125,7 @@ func resourceObjectBucketPolicyRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, ErrCodeNoSuchBucketPolicy, ErrCodeNoSuchBucket) { tflog.Warn(ctx, fmt.Sprintf("[WARN] SCW Bucket Policy (%s) not found, removing from state", d.Id())) d.SetId("") + return nil } diff --git a/internal/services/object/bucket_test.go b/internal/services/object/bucket_test.go index 8833ff6565..0df21d630a 100644 --- a/internal/services/object/bucket_test.go +++ b/internal/services/object/bucket_test.go @@ -595,6 +595,7 @@ func TestAccObjectBucket_Cors_Delete(t *testing.T) { if err != nil && !object.IsS3Err(err, object.ErrCodeNoSuchCORSConfiguration, "") { return err } + return nil } } @@ -735,6 +736,7 @@ func TestAccObjectBucket_DestroyForce(t *testing.T) { if err != nil { return fmt.Errorf("failed to put object in test bucket sub folder: %s", err) } + return nil } } @@ -804,6 +806,7 @@ func testAccCheckObjectBucketLifecycleConfigurationExists(tt *acctest.TestTools, if errors.Is(err, transport.ErrRetryWhenTimeout) { return fmt.Errorf("object Storage Bucket Replication Configuration for bucket (%s) not found", rs.Primary.ID) } + return err } diff --git a/internal/services/object/bucket_website_configuration.go b/internal/services/object/bucket_website_configuration.go index e8b6ee2551..2c0735ead4 100644 --- a/internal/services/object/bucket_website_configuration.go +++ b/internal/services/object/bucket_website_configuration.go @@ -148,8 +148,10 @@ func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.Resou if IsS3Err(err, ErrCodeNoSuchBucket, "") { tflog.Error(ctx, fmt.Sprintf("Bucket %q was not found - removing from state!", bucket)) d.SetId("") + return nil } + return diag.FromErr(fmt.Errorf("couldn't read bucket: %s", err)) } @@ -157,6 +159,7 @@ func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.Resou if !d.IsNewResource() && ErrCodeEquals(err, ErrCodeNoSuchBucket, ErrCodeNoSuchWebsiteConfiguration) { tflog.Debug(ctx, fmt.Sprintf("[WARN] Object Bucket Website Configuration (%s) not found, removing from state", d.Id())) d.SetId("") + return nil } @@ -166,6 +169,7 @@ func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.Resou } tflog.Info(ctx, fmt.Sprintf("[WARN] object Bucket Website Configuration (%s) not found, removing from state", d.Id())) d.SetId("") + return nil } diff --git a/internal/services/object/clients.go b/internal/services/object/clients.go index 668bea4746..a0e687edd8 100644 --- a/internal/services/object/clients.go +++ b/internal/services/object/clients.go @@ -18,5 +18,6 @@ func SharedS3ClientForRegion(region scw.Region) (*s3.Client, error) { if err != nil { return nil, err } + return NewS3ClientFromMeta(ctx, m, region.String()) } diff --git a/internal/services/object/data_source_object_bucket.go b/internal/services/object/data_source_object_bucket.go index f25b23d460..91a7a840cb 100644 --- a/internal/services/object/data_source_object_bucket.go +++ b/internal/services/object/data_source_object_bucket.go @@ -64,5 +64,6 @@ func DataSourceObjectStorageRead(ctx context.Context, d *schema.ResourceData, m bucketRegionalID := regional.NewIDString(region, bucket) d.SetId(bucketRegionalID) + return resourceObjectBucketRead(ctx, d, m) } diff --git a/internal/services/object/data_source_object_bucket_policy.go b/internal/services/object/data_source_object_bucket_policy.go index 9acd15b7f3..4272c46f90 100644 --- a/internal/services/object/data_source_object_bucket_policy.go +++ b/internal/services/object/data_source_object_bucket_policy.go @@ -81,5 +81,6 @@ func DataSourceObjectBucketPolicyRead(ctx context.Context, d *schema.ResourceDat _ = d.Set("project_id", NormalizeOwnerID(acl.Owner.ID)) d.SetId(regional.NewIDString(region, bucket)) + return nil } diff --git a/internal/services/object/errors.go b/internal/services/object/errors.go index be80d53057..f7a8821675 100644 --- a/internal/services/object/errors.go +++ b/internal/services/object/errors.go @@ -68,6 +68,7 @@ const ( func TimedOut(err error) bool { // This explicitly does *not* match wrapped TimeoutErrors timeoutErr, ok := err.(*retry.TimeoutError) //nolint:errorlint // Explicitly does *not* match wrapped TimeoutErrors + return ok && timeoutErr.LastError == nil } @@ -83,6 +84,7 @@ func ErrCodeEquals(err error, codes ...string) bool { } } } + return false } @@ -92,6 +94,7 @@ var serviceErrorCheckFunc map[string]ServiceErrorCheckFunc func ErrorCheck(t *testing.T, endpointIDs ...string) resource.ErrorCheckFunc { t.Helper() + return func(err error) error { if err == nil { return nil diff --git a/internal/services/object/helpers_object.go b/internal/services/object/helpers_object.go index a73cf4f35c..c6b4670c46 100644 --- a/internal/services/object/helpers_object.go +++ b/internal/services/object/helpers_object.go @@ -61,6 +61,7 @@ func newS3Client(ctx context.Context, region, accessKey, secretKey string, httpC o.BaseEndpoint = aws.String(endpoint) o.EndpointResolverV2 = &scalewayResolver{region: region} }) + return client, nil } @@ -171,6 +172,7 @@ func s3ClientWithRegionWithNameACL(ctx context.Context, d *schema.ResourceData, if err != nil { return nil, "", "", "", err } + return s3Client, scw.Region(region), name, outerID, err } @@ -240,12 +242,14 @@ func IsS3Err(err error, code string, message string) bool { if errors.As(err, &awsErr) { return awsErr.ErrorCode() == code && strings.Contains(awsErr.ErrorMessage(), message) } + return false } func flattenObjectBucketVersioning(versioningResponse *s3.GetBucketVersioningOutput) []map[string]interface{} { vcl := []map[string]interface{}{{}} vcl[0]["enabled"] = versioningResponse.Status == s3Types.BucketVersioningStatusEnabled + return vcl } @@ -257,6 +261,7 @@ func expandObjectBucketVersioning(v []interface{}) *s3Types.VersioningConfigurat vc.Status = s3Types.BucketVersioningStatusEnabled } } + return vc } @@ -285,14 +290,17 @@ func flattenBucketCORS(corsResponse interface{}) []interface{} { } corsRules = append(corsRules, rule) } + return corsRules } + return nil } func expandBucketCORS(ctx context.Context, rawCors []interface{}, bucket string) []s3Types.CORSRule { if len(rawCors) == 0 { tflog.Warn(ctx, "No CORS configuration provided for bucket: "+bucket) + return nil } @@ -303,6 +311,7 @@ func expandBucketCORS(ctx context.Context, rawCors []interface{}, bucket string) corsMap, ok := raw.(map[string]interface{}) if !ok { tflog.Warn(ctx, fmt.Sprintf("Invalid CORS entry for bucket %s: %#v", bucket, raw)) + continue } @@ -349,6 +358,7 @@ func toStringSlice(ctx context.Context, input interface{}) []string { default: tflog.Warn(ctx, fmt.Sprintf("Unexpected type for toStringSlice: %T", input)) } + return result } @@ -362,6 +372,7 @@ func deleteS3ObjectVersion(ctx context.Context, conn *s3.Client, bucketName stri } _, err := conn.DeleteObject(ctx, input) + return err } @@ -375,6 +386,7 @@ func removeS3ObjectVersionLegalHold(ctx context.Context, conn *s3.Client, bucket }) if err != nil { err = fmt.Errorf("failed to get S3 object meta data: %s", err) + return false, err } if objectHead.ObjectLockLegalHoldStatus != s3Types.ObjectLockLegalHoldStatusOn { @@ -390,8 +402,10 @@ func removeS3ObjectVersionLegalHold(ctx context.Context, conn *s3.Client, bucket }) if err != nil { err = fmt.Errorf("failed to put S3 object legal hold: %s", err) + return false, err } + return true, nil } @@ -441,6 +455,7 @@ func processAllPagesObject(ctx context.Context, bucketName string, conn *s3.Clie if errs := pool.CloseAndWait(); errs != nil { globalErr = multierror.Append(nil, errs...) + return nObject, globalErr } @@ -458,9 +473,11 @@ func deleteMarkerBucket(ctx context.Context, conn *s3.Client, bucketName string, return fmt.Errorf("failed to delete S3 object delete marker: %s", err) } nObject++ + return nil }) } + return nObject, nil } @@ -490,6 +507,7 @@ func deleteVersionBucket(ctx context.Context, conn *s3.Client, bucketName string return nil }) } + return nObject, nil } @@ -498,6 +516,7 @@ func findDeletionWorkerCapacity() int { if deletionWorkers > maxObjectVersionDeletionWorkers { deletionWorkers = maxObjectVersionDeletionWorkers } + return deletionWorkers } @@ -515,6 +534,7 @@ func transitionHash(v interface{}) int { if v, ok := m["storage_class"]; ok { buf.WriteString(v.(string) + "-") } + return types.StringHashcode(buf.String()) } @@ -598,6 +618,7 @@ type S3Website struct { func WebsiteEndpoint(bucket string, region scw.Region) *S3Website { domain := WebsiteDomainURL(region.String()) + return &S3Website{Endpoint: fmt.Sprintf("%s.%s", bucket, domain), Domain: domain} } @@ -610,6 +631,7 @@ func WebsiteDomainURL(region string) string { func buildBucketOwnerID(id *string) *string { s := fmt.Sprintf("%[1]s:%[1]s", *id) + return &s } @@ -630,6 +652,7 @@ func addReadBucketErrorDiagnostic(diags *diag.Diagnostics, err error, resource s Summary: "Bucket not found", Detail: "Got 404 error while reading bucket, removing from state", }) + return false, false case IsS3Err(err, awsResourceNotFoundCode, ""): @@ -656,6 +679,7 @@ func addReadBucketErrorDiagnostic(diags *diag.Diagnostics, err error, resource s } *diags = append(*diags, d) + return true, true default: @@ -663,6 +687,7 @@ func addReadBucketErrorDiagnostic(diags *diag.Diagnostics, err error, resource s Severity: diag.Error, Summary: fmt.Errorf("couldn't read bucket %s: %w", resource, err).Error(), }) + return true, true } } diff --git a/internal/services/object/object.go b/internal/services/object/object.go index f46750b5d9..753aebe852 100644 --- a/internal/services/object/object.go +++ b/internal/services/object/object.go @@ -221,6 +221,7 @@ func EncryptCustomerKey(encryptionKeyStr string) (string, *string, error) { digest := h.Sum(nil) digestMD5 := base64.StdEncoding.EncodeToString(digest) encryption := aws.String(base64.StdEncoding.EncodeToString(encryptionKey)) + return digestMD5, encryption, nil } @@ -412,6 +413,7 @@ func objectIsPublic(acl *s3.GetObjectAclOutput) bool { return true } } + return false } @@ -428,6 +430,7 @@ func validateMapKeyLowerCase() schema.SchemaValidateDiagFunc { }} } } + return nil } } diff --git a/internal/services/object/object_test.go b/internal/services/object/object_test.go index bed4be6374..96df7314a9 100644 --- a/internal/services/object/object_test.go +++ b/internal/services/object/object_test.go @@ -831,8 +831,10 @@ func testAccCheckObjectExists(tt *acctest.TestTools, n string) resource.TestChec if object.IsS3Err(err, object.ErrCodeNoSuchBucket, "") { return errors.New("s3 object not found") } + return err } + return nil } } diff --git a/internal/services/object/testfuncs/checks.go b/internal/services/object/testfuncs/checks.go index fb13950010..db4b38eb2e 100644 --- a/internal/services/object/testfuncs/checks.go +++ b/internal/services/object/testfuncs/checks.go @@ -45,8 +45,10 @@ func CheckBucketExists(tt *acctest.TestTools, n string, shouldBeAllowed bool) re if errors.As(err, new(*types.NoSuchBucket)) { return errors.New("s3 bucket not found") } + return err } + return nil } } @@ -76,11 +78,13 @@ func IsBucketDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { // Bucket doesn't exist continue } + return fmt.Errorf("couldn't get bucket to verify if it still exists: %s", err) } return errors.New("bucket should be deleted") } + return nil } } @@ -111,11 +115,13 @@ func IsObjectDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { if object.IsS3Err(err, object.ErrCodeNoSuchBucket, "The specified bucket does not exist") { continue } + return fmt.Errorf("couldn't get object to verify if it still exists: %s", err) } return errors.New("object should be deleted") } + return nil } } diff --git a/internal/services/rdb/acl.go b/internal/services/rdb/acl.go index 798cdcfd1f..2f000ce40e 100644 --- a/internal/services/rdb/acl.go +++ b/internal/services/rdb/acl.go @@ -124,8 +124,10 @@ func ResourceRdbACLRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -268,12 +270,14 @@ func rdbACLRulesFlattenFromSchema(rules []*rdb.ACLRule, dataFromSchema []interfa ip, err := types.ExpandIPNet(currentRule["ip"].(string)) if err != nil { errors = append(errors, err) + continue } aclRule, aclRuleExists := ruleMap[ip.String()] if !aclRuleExists { errors = append(errors, fmt.Errorf("acl from state does not exist on server (%s)", ip.String())) + continue } ruleMapFromSchema[ip.String()] = struct{}{} @@ -318,7 +322,9 @@ func rdbACLRulesFlatten(rules []*rdb.ACLRule) []map[string]interface{} { sort.Slice(res, func(i, j int) bool { ipI, _, _ := net.ParseCIDR(res[i]["ip"].(string)) ipJ, _, _ := net.ParseCIDR(res[j]["ip"].(string)) + return bytes.Compare(ipI, ipJ) < 0 }) + return res } diff --git a/internal/services/rdb/acl_data_source.go b/internal/services/rdb/acl_data_source.go index 7589db666a..e6385b8914 100644 --- a/internal/services/rdb/acl_data_source.go +++ b/internal/services/rdb/acl_data_source.go @@ -18,6 +18,7 @@ func DataSourceACL() *schema.Resource { // Set 'Optional' schema elements datasource.AddOptionalFieldsToSchema(dsSchema, "region") + return &schema.Resource{ ReadContext: DataSourceRDBACLRead, Schema: dsSchema, @@ -42,5 +43,6 @@ func DataSourceRDBACLRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { return diag.FromErr(err) } + return ResourceRdbACLRead(ctx, d, m) } diff --git a/internal/services/rdb/data_source_rdb_instance.go b/internal/services/rdb/data_source_rdb_instance.go index acef6fde14..6363828671 100644 --- a/internal/services/rdb/data_source_rdb_instance.go +++ b/internal/services/rdb/data_source_rdb_instance.go @@ -69,5 +69,6 @@ func DataSourceRDBInstanceRead(ctx context.Context, d *schema.ResourceData, m in if err != nil { return diag.FromErr(err) } + return ResourceRdbInstanceRead(ctx, d, m) } diff --git a/internal/services/rdb/database.go b/internal/services/rdb/database.go index 4029ba3bdb..d5eed5f4b9 100644 --- a/internal/services/rdb/database.go +++ b/internal/services/rdb/database.go @@ -109,10 +109,12 @@ func ResourceRdbDatabaseCreate(ctx context.Context, d *schema.ResourceData, m in if httperrors.Is409(errCreateDB) { return retry.RetryableError(errCreateDB) } + return retry.NonRetryableError(errCreateDB) } // set database information db = currentDB + return nil }) if err != nil { @@ -158,8 +160,10 @@ func ResourceRdbDatabaseRead(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -216,5 +220,6 @@ func ResourceRdbDatabaseParseID(resourceID string) (region scw.Region, instanceI if len(idParts) != 3 { return "", "", "", fmt.Errorf("can't parse user resource id: %s", resourceID) } + return scw.Region(idParts[0]), idParts[1], idParts[2], nil } diff --git a/internal/services/rdb/database_backup.go b/internal/services/rdb/database_backup.go index 06841f7873..216fe27a79 100644 --- a/internal/services/rdb/database_backup.go +++ b/internal/services/rdb/database_backup.go @@ -127,8 +127,10 @@ func ResourceRdbDatabaseBackupRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/rdb/database_data_source.go b/internal/services/rdb/database_data_source.go index 961ff786e4..698527d2ac 100644 --- a/internal/services/rdb/database_data_source.go +++ b/internal/services/rdb/database_data_source.go @@ -18,6 +18,7 @@ func DataSourceDatabase() *schema.Resource { // Set 'Optional' schema elements datasource.AddOptionalFieldsToSchema(dsSchema, "region") + return &schema.Resource{ ReadContext: DataSourceDatabaseRead, Schema: dsSchema, @@ -42,5 +43,6 @@ func DataSourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { return diag.FromErr(err) } + return ResourceRdbDatabaseRead(ctx, d, m) } diff --git a/internal/services/rdb/helpers.go b/internal/services/rdb/helpers.go index ec55aa7d58..370c06b04c 100644 --- a/internal/services/rdb/helpers.go +++ b/internal/services/rdb/helpers.go @@ -31,6 +31,7 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*rdb.API, scw.Regi if err != nil { return nil, "", err } + return newAPI(m), region, nil } @@ -40,6 +41,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*rdb.API, scw.Region, stri if err != nil { return nil, "", "", err } + return newAPI(m), region, ID, nil } @@ -87,6 +89,7 @@ func getIPConfigCreate(d *schema.ResourceData, ipFieldName string) (ipamConfig * if customIPSet { staticConfig = types.ExpandStringPtr(customIP) } + return ipamConfig, staticConfig } @@ -98,5 +101,6 @@ func getIPConfigUpdate(d *schema.ResourceData, ipFieldName string) (ipamConfig * if staticConfigI, _ := meta.GetRawConfigForKey(d, "private_network.#."+ipFieldName, cty.String); staticConfigI != nil { staticConfig = types.ExpandStringPtr(staticConfigI) } + return ipamConfig, staticConfig } diff --git a/internal/services/rdb/instance.go b/internal/services/rdb/instance.go index 28d672d1d4..5347a79809 100644 --- a/internal/services/rdb/instance.go +++ b/internal/services/rdb/instance.go @@ -445,8 +445,10 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _ = d.Set("name", res.Name) @@ -464,6 +466,7 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte for _, endpoint := range res.Endpoints { if endpoint.LoadBalancer != nil { loadBalancerEndpoint = endpoint + break } } @@ -509,6 +512,7 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte for _, u := range users.Users { if u.IsAdmin { _ = d.Set("user_name", u.Name) + break } } @@ -543,6 +547,7 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte if lbI, lbExists := flattenLoadBalancer(res.Endpoints); lbExists { _ = d.Set("load_balancer", lbI) } + return nil } diff --git a/internal/services/rdb/privilege.go b/internal/services/rdb/privilege.go index d59bc418ba..7c39565845 100644 --- a/internal/services/rdb/privilege.go +++ b/internal/services/rdb/privilege.go @@ -99,10 +99,13 @@ func ResourceRdbPrivilegeCreate(ctx context.Context, d *schema.ResourceData, m i if errWait != nil { return retry.NonRetryableError(errWait) } + return retry.RetryableError(errSetPrivilege) } + return retry.NonRetryableError(errSetPrivilege) } + return nil }) if err != nil { @@ -131,8 +134,10 @@ func ResourceRdbPrivilegeRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -144,13 +149,16 @@ func ResourceRdbPrivilegeRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } if listUsers == nil || len(listUsers.Users) == 0 { d.SetId("") + return nil } @@ -163,8 +171,10 @@ func ResourceRdbPrivilegeRead(ctx context.Context, d *schema.ResourceData, m int if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -200,13 +210,16 @@ func ResourceRdbPrivilegeUpdate(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } if listUsers == nil || len(listUsers.Users) == 0 { d.SetId("") + return nil } @@ -227,10 +240,13 @@ func ResourceRdbPrivilegeUpdate(ctx context.Context, d *schema.ResourceData, m i if errWait != nil { return retry.NonRetryableError(errWait) } + return retry.RetryableError(errSet) } + return retry.NonRetryableError(errSet) } + return nil }) if err != nil { @@ -267,13 +283,16 @@ func ResourceRdbPrivilegeDelete(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } if listUsers != nil && len(listUsers.Users) == 0 { d.SetId("") + return nil } @@ -296,13 +315,16 @@ func ResourceRdbPrivilegeDelete(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return retry.NonRetryableError(errUserExist) } if listUsers != nil && len(listUsers.Users) == 0 { d.SetId("") + return nil } _, errSet := rdbAPI.SetPrivilege(updateReq, scw.WithContext(ctx)) @@ -312,10 +334,13 @@ func ResourceRdbPrivilegeDelete(ctx context.Context, d *schema.ResourceData, m i if errWait != nil { return retry.NonRetryableError(errWait) } + return retry.RetryableError(errSet) } + return retry.NonRetryableError(errSet) } + return nil }) if err != nil { @@ -342,5 +367,6 @@ func ResourceRdbUserPrivilegeParseID(resourceID string) (region scw.Region, inst if len(idParts) != 4 { return "", "", "", "", fmt.Errorf("can't parse user privilege resource id: %s", resourceID) } + return scw.Region(idParts[0]), idParts[1], idParts[2], idParts[3], nil } diff --git a/internal/services/rdb/privilege_data_source.go b/internal/services/rdb/privilege_data_source.go index 1cc914e5a3..cf80b2c15c 100644 --- a/internal/services/rdb/privilege_data_source.go +++ b/internal/services/rdb/privilege_data_source.go @@ -17,6 +17,7 @@ func DataSourcePrivilege() *schema.Resource { // Set 'Optional' schema elements datasource.AddOptionalFieldsToSchema(dsSchema, "region") + return &schema.Resource{ ReadContext: DataSourceRDBPrivilegeRead, Schema: dsSchema, @@ -35,5 +36,6 @@ func DataSourceRDBPrivilegeRead(ctx context.Context, d *schema.ResourceData, m i databaseName, _ := d.Get("database_name").(string) d.SetId(ResourceRdbUserPrivilegeID(region, instanceID, databaseName, userName)) + return ResourceRdbPrivilegeRead(ctx, d, m) } diff --git a/internal/services/rdb/read_replica.go b/internal/services/rdb/read_replica.go index 421a6ba028..3eb366bbb9 100644 --- a/internal/services/rdb/read_replica.go +++ b/internal/services/rdb/read_replica.go @@ -207,8 +207,10 @@ func ResourceRdbReadReplicaRead(ctx context.Context, d *schema.ResourceData, m i if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -236,8 +238,10 @@ func ResourceRdbReadReplicaUpdate(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/rdb/testfuncs/checks.go b/internal/services/rdb/testfuncs/checks.go index af6000650b..99b9f52ed4 100644 --- a/internal/services/rdb/testfuncs/checks.go +++ b/internal/services/rdb/testfuncs/checks.go @@ -55,9 +55,11 @@ func GetLatestEngineVersion(tt *acctest.TestTools, engineName string) string { if engine.Name == engineName { if len(engine.Versions) > 0 { latestEngineVersion = engine.Versions[0].Name + break } } } + return latestEngineVersion } diff --git a/internal/services/rdb/types.go b/internal/services/rdb/types.go index e891ed57af..3e0a2912ca 100644 --- a/internal/services/rdb/types.go +++ b/internal/services/rdb/types.go @@ -105,6 +105,7 @@ func flattenPrivateNetwork(endpoints []*rdb.Endpoint) (interface{}, bool) { "hostname": types.FlattenStringPtr(endpoint.Hostname), "enable_ipam": enableIpam, }) + return pnI, true } } @@ -123,6 +124,7 @@ func flattenLoadBalancer(endpoints []*rdb.Endpoint) (interface{}, bool) { "name": endpoint.Name, "hostname": types.FlattenStringPtr(endpoint.Hostname), }) + return flat, true } } @@ -225,11 +227,13 @@ func expandInstanceLogsPolicy(i interface{}) *rdb.LogsPolicy { policyConfigRaw := i.([]interface{}) for _, policyRaw := range policyConfigRaw { policy := policyRaw.(map[string]interface{}) + return &rdb.LogsPolicy{ MaxAgeRetention: types.ExpandUint32Ptr(policy["max_age_retention"]), TotalDiskRetention: types.ExpandSize(policy["total_disk_retention"]), } } + return nil } @@ -243,5 +247,6 @@ func flattenInstanceLogsPolicy(policy *rdb.LogsPolicy) interface{} { } else { return nil } + return p } diff --git a/internal/services/rdb/user.go b/internal/services/rdb/user.go index 6c05b602f7..73888ef995 100644 --- a/internal/services/rdb/user.go +++ b/internal/services/rdb/user.go @@ -100,12 +100,15 @@ func ResourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface if errWait != nil { return retry.NonRetryableError(errWait) } + return retry.RetryableError(errCreateUser) } + return retry.NonRetryableError(errCreateUser) } // set database information user = currentUser + return nil }) if err != nil { @@ -128,8 +131,10 @@ func ResourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{} if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -141,13 +146,16 @@ func ResourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{} if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } if len(res.Users) == 0 { tflog.Warn(ctx, fmt.Sprintf("couldn'd find user with name: [%s]", userName)) d.SetId("") + return nil } @@ -221,8 +229,10 @@ func ResourceUserDelete(ctx context.Context, d *schema.ResourceData, m interface if errWait != nil { return retry.NonRetryableError(errWait) } + return retry.RetryableError(errDeleteUser) } + return retry.NonRetryableError(errDeleteUser) } // set database information @@ -249,5 +259,6 @@ func ResourceUserParseID(resourceID string) (region scw.Region, instanceID strin if len(idParts) != 3 { return "", "", "", fmt.Errorf("can't parse user resource id: %s", resourceID) } + return scw.Region(idParts[0]), idParts[1], idParts[2], nil } diff --git a/internal/services/redis/cluster.go b/internal/services/redis/cluster.go index e932a34e3e..d4ae102313 100644 --- a/internal/services/redis/cluster.go +++ b/internal/services/redis/cluster.go @@ -228,6 +228,7 @@ func customizeDiffMigrateClusterSize() schema.CustomizeDiffFunc { if oldSize == 1 && newSize != 1 || newSize < oldSize { return diff.ForceNew("cluster_size") } + return nil } } @@ -311,8 +312,10 @@ func ResourceClusterRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/redis/cluster_test.go b/internal/services/redis/cluster_test.go index eb25338fea..166c835e2c 100644 --- a/internal/services/redis/cluster_test.go +++ b/internal/services/redis/cluster_test.go @@ -762,6 +762,7 @@ func isClusterDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { return err } } + return nil } } @@ -785,6 +786,7 @@ func isClusterPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc { if err != nil { return err } + return nil } } @@ -811,6 +813,7 @@ func privateNetworksIpsAreEither(name string, possibilities ...string) resource. return fmt.Errorf("no attribute private_network.*.service_ips.0 was found with value %v", p) } } + return nil } } @@ -845,6 +848,7 @@ func privateNetworksIDsAreEither(name string, possibilities ...string) resource. return fmt.Errorf("no attribute private_network.*.id was found with value %v", p) } } + return nil } } @@ -864,6 +868,7 @@ func isCertificateValid(name string) resource.TestCheckFunc { if err != nil { return fmt.Errorf("failed to parse certificate: %w", err) } + return nil } } @@ -877,7 +882,9 @@ func getLatestVersion(tt *acctest.TestTools) string { } if len(versions.Versions) > 0 { latestRedisVersion := versions.Versions[0].Version + return latestRedisVersion } + return "" } diff --git a/internal/services/redis/helpers.go b/internal/services/redis/helpers.go index 07dface263..632b5c0f3a 100644 --- a/internal/services/redis/helpers.go +++ b/internal/services/redis/helpers.go @@ -33,6 +33,7 @@ func newAPIWithZone(d *schema.ResourceData, m interface{}) (*redis.API, scw.Zone if err != nil { return nil, "", err } + return newAPI(m), zone, nil } @@ -42,6 +43,7 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*redis.API, scw.Zone, string if err != nil { return nil, "", "", err } + return newAPI(m), zone, ID, nil } diff --git a/internal/services/redis/types.go b/internal/services/redis/types.go index 5ecb84c498..d67474fe12 100644 --- a/internal/services/redis/types.go +++ b/internal/services/redis/types.go @@ -41,6 +41,7 @@ func expandPrivateNetwork(data []interface{}) ([]*redis.EndpointSpec, error) { epSpecs = append(epSpecs, &redis.EndpointSpec{PrivateNetwork: spec}) } + return epSpecs, nil } @@ -73,6 +74,7 @@ func flattenACLs(aclRules []*redis.ACLRule) interface{} { "description": types.FlattenStringPtr(acl.Description), }) } + return flat } @@ -85,6 +87,7 @@ func expandSettings(i interface{}) []*redis.ClusterSetting { Value: value.(string), }) } + return settings } @@ -93,6 +96,7 @@ func flattenSettings(settings []*redis.ClusterSetting) interface{} { for _, setting := range settings { rawSettings[setting.Name] = setting.Value } + return rawSettings } @@ -119,6 +123,7 @@ func flattenPrivateNetwork(endpoints []*redis.Endpoint) (interface{}, bool) { "service_ips": serviceIps, }) } + return pnFlat, len(pnFlat) != 0 } @@ -137,7 +142,9 @@ func flattenPublicNetwork(endpoints []*redis.Endpoint) interface{} { "port": int(endpoint.Port), "ips": ipsFlat, }) + break } + return pnFlat } diff --git a/internal/services/registry/helpers.go b/internal/services/registry/helpers.go index ef79968e5d..3ebb0bd77f 100644 --- a/internal/services/registry/helpers.go +++ b/internal/services/registry/helpers.go @@ -27,6 +27,7 @@ func NewAPIWithRegion(d *schema.ResourceData, m interface{}) (*registry.API, scw if err != nil { return nil, "", err } + return api, region, nil } @@ -38,5 +39,6 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*registry.API, scw.Region, if err != nil { return nil, "", "", err } + return api, region, id, nil } diff --git a/internal/services/registry/namespace.go b/internal/services/registry/namespace.go index 9cac51de4d..e297ffae88 100644 --- a/internal/services/registry/namespace.go +++ b/internal/services/registry/namespace.go @@ -96,8 +96,10 @@ func ResourceNamespaceRead(ctx context.Context, d *schema.ResourceData, m interf if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -122,8 +124,10 @@ func ResourceNamespaceUpdate(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -151,8 +155,10 @@ func ResourceNamespaceDelete(ctx context.Context, d *schema.ResourceData, m inte if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/scwconfig/scw_config_data_source_test.go b/internal/services/scwconfig/scw_config_data_source_test.go index 1056fba019..9832d15fa2 100644 --- a/internal/services/scwconfig/scw_config_data_source_test.go +++ b/internal/services/scwconfig/scw_config_data_source_test.go @@ -35,6 +35,7 @@ func TestAccDataSourceConfig_ActiveProfile(t *testing.T) { HTTPClient: tt.Meta.HTTPClient(), }) require.NoError(t, err) + return map[string]func() (*schema.Provider, error){ "default": func() (*schema.Provider, error) { return provider.Provider(&provider.Config{Meta: metaDefault})(), nil @@ -86,6 +87,7 @@ func TestAccDataSourceConfig_OtherProfile(t *testing.T) { HTTPClient: tt.Meta.HTTPClient(), }) require.NoError(t, err) + return map[string]func() (*schema.Provider, error){ "other": func() (*schema.Provider, error) { return provider.Provider(&provider.Config{Meta: metaOther})(), nil @@ -138,6 +140,7 @@ func TestAccDataSourceConfig_MixedProfile(t *testing.T) { HTTPClient: tt.Meta.HTTPClient(), }) require.NoError(t, err) + return map[string]func() (*schema.Provider, error){ "mixed": func() (*schema.Provider, error) { return provider.Provider(&provider.Config{Meta: metaMixed})(), nil diff --git a/internal/services/sdb/database.go b/internal/services/sdb/database.go index 85a8fe68d6..89ce5ac49d 100644 --- a/internal/services/sdb/database.go +++ b/internal/services/sdb/database.go @@ -98,8 +98,10 @@ func ResourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -123,8 +125,10 @@ func ResourceDatabaseUpdate(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/secret/helpers.go b/internal/services/secret/helpers.go index af3a65966b..fcfdf200c2 100644 --- a/internal/services/secret/helpers.go +++ b/internal/services/secret/helpers.go @@ -29,6 +29,7 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*secret.API, scw.R if err != nil { return nil, "", err } + return api, region, nil } @@ -76,6 +77,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*secret.API, scw.Region, s if err != nil { return nil, "", "", err } + return api, region, id, nil } @@ -86,11 +88,13 @@ func NewVersionAPIWithRegionAndID(m interface{}, id string) (*secret.API, scw.Re return nil, "", "", "", err } api := secret.NewAPI(meta.ExtractScwClient(m)) + return api, scw.Region(region), id, revision, nil } func isBase64Encoded(data []byte) bool { _, err := base64.StdEncoding.DecodeString(string(data)) + return err == nil } @@ -98,6 +102,7 @@ func Base64Encoded(data []byte) string { if isBase64Encoded(data) { return string(data) } + return base64.StdEncoding.EncodeToString(data) } diff --git a/internal/services/secret/secret.go b/internal/services/secret/secret.go index a2d6e312ec..9aa9f47c6c 100644 --- a/internal/services/secret/secret.go +++ b/internal/services/secret/secret.go @@ -181,8 +181,10 @@ func ResourceSecretRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/secret/version.go b/internal/services/secret/version.go index a8b17b1f19..4e7df0fd0e 100644 --- a/internal/services/secret/version.go +++ b/internal/services/secret/version.go @@ -117,8 +117,10 @@ func ResourceVersionRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/tem/domain.go b/internal/services/tem/domain.go index b4fc033299..13c44f6a79 100644 --- a/internal/services/tem/domain.go +++ b/internal/services/tem/domain.go @@ -45,6 +45,7 @@ func ResourceDomain() *schema.Resource { v := i.(bool) if !v { errs = append(errs, errors.New("you must accept the Scaleway Terms of Service to use this service")) + return warnings, errs } @@ -223,8 +224,10 @@ func ResourceDomainRead(ctx context.Context, d *schema.ResourceData, m interface if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -252,6 +255,7 @@ func ResourceDomainRead(ctx context.Context, d *schema.ResourceData, m interface _ = d.Set("region", string(region)) _ = d.Set("project_id", domain.ProjectID) _ = d.Set("smtps_auth_user", domain.ProjectID) + return nil } @@ -287,6 +291,7 @@ func ResourceDomainDelete(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } diff --git a/internal/services/tem/domain_validation.go b/internal/services/tem/domain_validation.go index 5c32941f05..eeabeeb795 100644 --- a/internal/services/tem/domain_validation.go +++ b/internal/services/tem/domain_validation.go @@ -66,8 +66,10 @@ func ResourceDomainValidationCreate(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } duration := d.Get("timeout").(int) @@ -80,6 +82,7 @@ func ResourceDomainValidationCreate(ctx context.Context, d *schema.ResourceData, if domainCheck == nil || domainCheck.Status == "pending" || domainCheck.Status == "unchecked" || domainCheck.Status == "autoconfiguring" { return retry.RetryableError(errors.New("retry")) } + return nil }) @@ -101,8 +104,10 @@ func ResourceDomainValidationRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -113,6 +118,7 @@ func ResourceDomainValidationRead(ctx context.Context, d *schema.ResourceData, m func ResourceDomainValidationDelete(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics { d.SetId("") + return nil } @@ -121,5 +127,6 @@ func extractAfterSlash(s string) string { if lastIndex == -1 { return s } + return s[lastIndex+1:] } diff --git a/internal/services/tem/helpers.go b/internal/services/tem/helpers.go index 68cb773edf..a9af6c3402 100644 --- a/internal/services/tem/helpers.go +++ b/internal/services/tem/helpers.go @@ -24,6 +24,7 @@ func temAPIWithRegion(d *schema.ResourceData, m interface{}) (*tem.API, scw.Regi if err != nil { return nil, "", err } + return api, region, nil } @@ -35,5 +36,6 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*tem.API, scw.Region, stri if err != nil { return nil, "", "", err } + return api, region, id, nil } diff --git a/internal/services/tem/testfuncs/sweep.go b/internal/services/tem/testfuncs/sweep.go index 40fe0670e0..2dbf4f3ee6 100644 --- a/internal/services/tem/testfuncs/sweep.go +++ b/internal/services/tem/testfuncs/sweep.go @@ -30,6 +30,7 @@ func testSweepDomain(_ string) error { for _, ns := range listDomains.Domains { if ns.Name == "test.scaleway-terraform.com" { logging.L.Debugf("sweeper: skipping deletion of domain %s", ns.Name) + continue } _, err := temAPI.RevokeDomain(&temSDK.RevokeDomainRequest{ diff --git a/internal/services/tem/types.go b/internal/services/tem/types.go index dd753b052a..0cf490ac07 100644 --- a/internal/services/tem/types.go +++ b/internal/services/tem/types.go @@ -9,6 +9,7 @@ func flattenDomainReputation(reputation *tem.DomainReputation) interface{} { if reputation == nil { return nil } + return []map[string]interface{}{ { "status": reputation.Status.String(), @@ -25,5 +26,6 @@ func expandWebhookEventTypes(eventTypesInterface []interface{}) []tem.WebhookEve for i, v := range eventTypesInterface { eventTypes[i] = tem.WebhookEventType(v.(string)) } + return eventTypes } diff --git a/internal/services/tem/webhook.go b/internal/services/tem/webhook.go index 3b37e89de9..564cfaa4a5 100644 --- a/internal/services/tem/webhook.go +++ b/internal/services/tem/webhook.go @@ -108,8 +108,10 @@ func ResourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpc/helpers.go b/internal/services/vpc/helpers.go index c2899d86d6..85ea979160 100644 --- a/internal/services/vpc/helpers.go +++ b/internal/services/vpc/helpers.go @@ -27,6 +27,7 @@ func vpcAPIWithRegion(d *schema.ResourceData, m interface{}) (*vpc.API, scw.Regi if err != nil { return nil, "", err } + return vpcAPI, region, err } @@ -38,6 +39,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*vpc.API, scw.Region, stri if err != nil { return nil, "", "", err } + return vpcAPI, region, ID, err } @@ -53,6 +55,7 @@ func routesAPIWithRegion(d *schema.ResourceData, m interface{}) (*vpc.RoutesWith if err != nil { return nil, "", err } + return routesAPI, region, err } @@ -108,6 +111,7 @@ func vpcRouteExpandResourceID(id string) (string, error) { if err != nil { return "", fmt.Errorf("failed to parse localized ID: %w", err) } + return ID, nil case 3: // Parse as a nested ID and return the outerID @@ -115,6 +119,7 @@ func vpcRouteExpandResourceID(id string) (string, error) { if err != nil { return "", fmt.Errorf("failed to parse nested ID: %w", err) } + return ID, nil default: return "", fmt.Errorf("unrecognized ID format: %s", id) diff --git a/internal/services/vpc/private_network.go b/internal/services/vpc/private_network.go index 1c24a249a3..b4b3e7dfe9 100644 --- a/internal/services/vpc/private_network.go +++ b/internal/services/vpc/private_network.go @@ -239,8 +239,10 @@ func ResourceVPCPrivateNetworkRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpc/route.go b/internal/services/vpc/route.go index 70246d557a..325ced90bc 100644 --- a/internal/services/vpc/route.go +++ b/internal/services/vpc/route.go @@ -127,8 +127,10 @@ func ResourceRouteRead(ctx context.Context, d *schema.ResourceData, m interface{ if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpc/types.go b/internal/services/vpc/types.go index e349ab4228..89918826fc 100644 --- a/internal/services/vpc/types.go +++ b/internal/services/vpc/types.go @@ -33,6 +33,7 @@ func expandSubnets(d *schema.ResourceData) (ipv4Subnets []scw.IPNet, ipv6Subnets ipv6Subnets = append(ipv6Subnets, ipNet) } } + return } @@ -138,10 +139,12 @@ func maskHexToDottedDecimal(mask net.IPMask) string { for i, part := range mask { parts[i] = strconv.Itoa(int(part)) } + return strings.Join(parts, ".") } func getPrefixLength(mask net.IPMask) int { ones, _ := mask.Size() + return ones } diff --git a/internal/services/vpc/vpc.go b/internal/services/vpc/vpc.go index a33575128a..2b98fdb89f 100644 --- a/internal/services/vpc/vpc.go +++ b/internal/services/vpc/vpc.go @@ -111,8 +111,10 @@ func ResourceVPCRead(ctx context.Context, d *schema.ResourceData, m interface{}) if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpcgw/dhcp.go b/internal/services/vpcgw/dhcp.go index 8d24574726..72834de7a6 100644 --- a/internal/services/vpcgw/dhcp.go +++ b/internal/services/vpcgw/dhcp.go @@ -209,8 +209,10 @@ func ResourceVPCPublicGatewayDHCPRead(ctx context.Context, d *schema.ResourceDat if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpcgw/dhcp_data_source.go b/internal/services/vpcgw/dhcp_data_source.go index 356aff43c5..73f34178fe 100644 --- a/internal/services/vpcgw/dhcp_data_source.go +++ b/internal/services/vpcgw/dhcp_data_source.go @@ -37,5 +37,6 @@ func DataSourceVPCPublicGatewayDHCPRead(ctx context.Context, d *schema.ResourceD zonedID := datasource.NewZonedID(dhcpID, zone) d.SetId(zonedID) _ = d.Set("dhcp_id", zonedID) + return ResourceVPCPublicGatewayDHCPRead(ctx, d, m) } diff --git a/internal/services/vpcgw/dhcp_reservation.go b/internal/services/vpcgw/dhcp_reservation.go index 57cbd07b42..d0d51ee254 100644 --- a/internal/services/vpcgw/dhcp_reservation.go +++ b/internal/services/vpcgw/dhcp_reservation.go @@ -133,8 +133,10 @@ func ResourceVPCPublicGatewayDHCPReservationRead(ctx context.Context, d *schema. if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpcgw/dhcp_reservation_test.go b/internal/services/vpcgw/dhcp_reservation_test.go index a2473552c4..4ab3432dfb 100644 --- a/internal/services/vpcgw/dhcp_reservation_test.go +++ b/internal/services/vpcgw/dhcp_reservation_test.go @@ -159,6 +159,7 @@ func testAccCheckVPCPublicGatewayDHCPReservationExists(tt *acctest.TestTools, n } logging.L.Debugf("reservation: ID: (%s) exist", entry.ID) + return nil } } diff --git a/internal/services/vpcgw/helpers.go b/internal/services/vpcgw/helpers.go index 374e1bb704..7c0be57c04 100644 --- a/internal/services/vpcgw/helpers.go +++ b/internal/services/vpcgw/helpers.go @@ -27,6 +27,7 @@ func newAPIWithZone(d *schema.ResourceData, m interface{}) (*vpcgw.API, scw.Zone if err != nil { return nil, "", err } + return api, zone, nil } @@ -37,6 +38,7 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*vpcgw.API, scw.Zone, string if err != nil { return nil, "", "", err } + return api, zone, ID, nil } @@ -50,9 +52,11 @@ func retryUpdateGatewayReverseDNS(ctx context.Context, api *vpcgw.API, req *vpcg if err != nil && instance.IsIPReverseDNSResolveError(err) { continue } + return err case <-timeoutChannel: _, err := api.UpdateIP(req, scw.WithContext(ctx)) + return err } } @@ -96,6 +100,7 @@ func flattenIpamConfig(config *vpcgw.IpamConfig) interface{} { if config == nil { return nil } + return []map[string]interface{}{ { "push_default_route": config.PushDefaultRoute, diff --git a/internal/services/vpcgw/ip.go b/internal/services/vpcgw/ip.go index ebf07eaeac..287693628b 100644 --- a/internal/services/vpcgw/ip.go +++ b/internal/services/vpcgw/ip.go @@ -111,8 +111,10 @@ func ResourceIPRead(ctx context.Context, d *schema.ResourceData, m interface{}) if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -179,6 +181,7 @@ func ResourceVPCPublicGatewayIPDelete(ctx context.Context, d *schema.ResourceDat Summary: err.Error(), }) } + return diag.FromErr(err) } diff --git a/internal/services/vpcgw/ip_data_source.go b/internal/services/vpcgw/ip_data_source.go index 06154db90d..814b7d7c1d 100644 --- a/internal/services/vpcgw/ip_data_source.go +++ b/internal/services/vpcgw/ip_data_source.go @@ -37,5 +37,6 @@ func DataSourceVPCPublicGatewayIPRead(ctx context.Context, d *schema.ResourceDat zonedID := datasource.NewZonedID(ipID, zone) d.SetId(zonedID) _ = d.Set("ip_id", zonedID) + return ResourceIPRead(ctx, d, m) } diff --git a/internal/services/vpcgw/ip_reverse.go b/internal/services/vpcgw/ip_reverse.go index 71fb53aa9c..2af8216fa3 100644 --- a/internal/services/vpcgw/ip_reverse.go +++ b/internal/services/vpcgw/ip_reverse.go @@ -96,8 +96,10 @@ func ResourceVPCPublicGatewayIPReverseDNSRead(ctx context.Context, d *schema.Res if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -153,5 +155,6 @@ func ResourceVPCPublicGatewayIPReverseDNSDelete(ctx context.Context, d *schema.R } d.SetId("") + return nil } diff --git a/internal/services/vpcgw/network.go b/internal/services/vpcgw/network.go index bfffdcd157..b8f253b92a 100644 --- a/internal/services/vpcgw/network.go +++ b/internal/services/vpcgw/network.go @@ -177,6 +177,7 @@ func ResourceVPCGatewayNetworkCreate(ctx context.Context, d *schema.ResourceData return api.CreateGatewayNetwork(req, scw.WithContext(ctx)) }, func() (*vpcgw.Gateway, error) { tflog.Warn(ctx, "Public gateway is in transient state after waiting, retrying...") + return waitForVPCPublicGateway(ctx, api, zone, gatewayID, d.Timeout(schema.TimeoutCreate)) }) if err != nil { @@ -208,8 +209,10 @@ func ResourceVPCGatewayNetworkRead(ctx context.Context, d *schema.ResourceData, if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } _, err = waitForVPCPublicGateway(ctx, api, zone, gatewayNetwork.GatewayID, d.Timeout(schema.TimeoutRead)) diff --git a/internal/services/vpcgw/pat_rule.go b/internal/services/vpcgw/pat_rule.go index 2f96e03a88..7f5bfb3b35 100644 --- a/internal/services/vpcgw/pat_rule.go +++ b/internal/services/vpcgw/pat_rule.go @@ -141,8 +141,10 @@ func ResourceVPCPublicGatewayPATRuleRead(ctx context.Context, d *schema.Resource if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } @@ -217,8 +219,10 @@ func ResourceVPCPublicGatewayPATRuleUpdate(ctx context.Context, d *schema.Resour if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } } @@ -245,8 +249,10 @@ func ResourceVPCPublicGatewayPATRuleDelete(ctx context.Context, d *schema.Resour if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpcgw/public_gateway.go b/internal/services/vpcgw/public_gateway.go index abb0d96252..d2b0c7cf7c 100644 --- a/internal/services/vpcgw/public_gateway.go +++ b/internal/services/vpcgw/public_gateway.go @@ -165,8 +165,10 @@ func ResourceVPCPublicGatewayRead(ctx context.Context, d *schema.ResourceData, m if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/services/vpcgw/public_gateway_data_source.go b/internal/services/vpcgw/public_gateway_data_source.go index 9355c283be..8d09cc216a 100644 --- a/internal/services/vpcgw/public_gateway_data_source.go +++ b/internal/services/vpcgw/public_gateway_data_source.go @@ -72,5 +72,6 @@ func DataSourceVPCPublicGatewayRead(ctx context.Context, d *schema.ResourceData, zonedID := datasource.NewZonedID(publicGatewayID, zone) d.SetId(zonedID) _ = d.Set("public_gateway_id", zonedID) + return ResourceVPCPublicGatewayRead(ctx, d, m) } diff --git a/internal/services/vpcgw/testfuncs/sweep.go b/internal/services/vpcgw/testfuncs/sweep.go index 48f9807b71..53ec49dd8d 100644 --- a/internal/services/vpcgw/testfuncs/sweep.go +++ b/internal/services/vpcgw/testfuncs/sweep.go @@ -50,6 +50,7 @@ func testSweepVPCPublicGateway(_ string) error { return fmt.Errorf("error deleting public gateway in sweeper: %w", err) } } + return nil }) } @@ -77,6 +78,7 @@ func testSweepVPCGatewayNetwork(_ string) error { return fmt.Errorf("error deleting gateway network in sweeper: %s", err) } } + return nil }) } @@ -102,6 +104,7 @@ func testSweepVPCPublicGatewayIP(_ string) error { return fmt.Errorf("error deleting public gateway ip in sweeper: %s", err) } } + return nil }) } diff --git a/internal/services/vpcgw/waiters.go b/internal/services/vpcgw/waiters.go index 5b90197604..dc16b19379 100644 --- a/internal/services/vpcgw/waiters.go +++ b/internal/services/vpcgw/waiters.go @@ -59,5 +59,6 @@ func waitForDHCPEntries(ctx context.Context, api *vpcgw.API, zone scw.Zone, gate } dhcpEntries, err := api.WaitForDHCPEntries(req, scw.WithContext(ctx)) + return dhcpEntries, err } diff --git a/internal/services/webhosting/helpers.go b/internal/services/webhosting/helpers.go index b5d5aff8a4..233231c629 100644 --- a/internal/services/webhosting/helpers.go +++ b/internal/services/webhosting/helpers.go @@ -25,6 +25,7 @@ func newAPIWithRegion(d *schema.ResourceData, m interface{}) (*webhosting.API, s if err != nil { return nil, "", err } + return api, region, nil } @@ -36,6 +37,7 @@ func NewAPIWithRegionAndID(m interface{}, id string) (*webhosting.API, scw.Regio if err != nil { return nil, "", "", err } + return api, region, id, nil } diff --git a/internal/services/webhosting/types.go b/internal/services/webhosting/types.go index 6281b98f35..63c858c15b 100644 --- a/internal/services/webhosting/types.go +++ b/internal/services/webhosting/types.go @@ -45,5 +45,6 @@ func flattenHostingOptions(options []*webhosting.HostingOption) []map[string]int "name": option.Name, }) } + return flattenedOptions } diff --git a/internal/services/webhosting/webhosting.go b/internal/services/webhosting/webhosting.go index 452eab8238..10058ca711 100644 --- a/internal/services/webhosting/webhosting.go +++ b/internal/services/webhosting/webhosting.go @@ -156,6 +156,7 @@ func ResourceWebhosting() *schema.Resource { } } } + return nil }, } @@ -220,8 +221,10 @@ func resourceWebhostingRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { if httperrors.Is404(err) { d.SetId("") + return nil } + return diag.FromErr(err) } diff --git a/internal/transport/retry.go b/internal/transport/retry.go index 2e7dae86bf..76704e3545 100644 --- a/internal/transport/retry.go +++ b/internal/transport/retry.go @@ -35,6 +35,7 @@ func NewRetryableTransportWithOptions(defaultTransport http.RoundTripper, option if resp == nil || resp.StatusCode == http.StatusTooManyRequests { return true, err } + return retryablehttp.DefaultRetryPolicy(ctx, resp, err) } @@ -46,6 +47,7 @@ func NewRetryableTransportWithOptions(defaultTransport http.RoundTripper, option if err != nil { return resp, err } + return resp, nil } @@ -95,8 +97,10 @@ func (c *RetryableTransport) RoundTrip(r *http.Request) (*http.Response, error) if err != nil { return nil, err } + return io.NopCloser(bytes.NewReader(b)), err } + return c.Client.Do(req) } @@ -108,7 +112,9 @@ func RetryOnTransientStateError[T any, U any](action func() (T, error), waiter f if err != nil { return t, err } + return RetryOnTransientStateError(action, waiter) } + return t, err } diff --git a/internal/transport/retry_aws.go b/internal/transport/retry_aws.go index 18ce6bd755..c724cf55c3 100644 --- a/internal/transport/retry_aws.go +++ b/internal/transport/retry_aws.go @@ -46,6 +46,7 @@ func retryWhen[T any](ctx context.Context, config *RetryWhenConfig[T], shouldRet return result, ctx.Err() default: time.Sleep(retryInterval) // lintignore:R018 + continue } } diff --git a/internal/types/bool.go b/internal/types/bool.go index ac00a4f3d4..d8087a2ecc 100644 --- a/internal/types/bool.go +++ b/internal/types/bool.go @@ -9,6 +9,7 @@ func FlattenBoolPtr(b *bool) interface{} { if b == nil { return nil } + return *b } @@ -16,6 +17,7 @@ func ExpandBoolPtr(data interface{}) *bool { if data == nil { return nil } + return scw.BoolPtr(data.(bool)) } @@ -24,5 +26,6 @@ func GetBool(d *schema.ResourceData, key string) interface{} { if !ok { return nil } + return val } diff --git a/internal/types/ip.go b/internal/types/ip.go index 9e7ac70ecd..7c03df6714 100644 --- a/internal/types/ip.go +++ b/internal/types/ip.go @@ -29,6 +29,7 @@ func FlattenIPPtr(ip *net.IP) interface{} { if ip == nil { return "" } + return ip.String() } @@ -37,5 +38,6 @@ func FlattenIPNet(ipNet scw.IPNet) (string, error) { if err != nil { return "", err } + return string(raw[1 : len(raw)-1]), nil // remove quotes } diff --git a/internal/types/map.go b/internal/types/map.go index 79a9fdc761..b747f86608 100644 --- a/internal/types/map.go +++ b/internal/types/map.go @@ -8,6 +8,7 @@ func FlattenMap(m map[string]string) interface{} { for k, v := range m { flattenedMap[k] = v } + return flattenedMap } @@ -23,6 +24,7 @@ func FlattenMapStringStringPtr(m map[string]*string) interface{} { flattenedMap[k] = "" } } + return flattenedMap } @@ -34,6 +36,7 @@ func ExpandMapPtrStringString(data interface{}) *map[string]string { for k, v := range data.(map[string]interface{}) { m[k] = v.(string) } + return &m } @@ -45,6 +48,7 @@ func ExpandMapStringStringPtr(data interface{}) map[string]*string { for k, v := range data.(map[string]interface{}) { m[k] = ExpandStringPtr(v) } + return m } @@ -56,6 +60,7 @@ func ExpandMapStringString(data any) map[string]string { for k, v := range data.(map[string]interface{}) { m[k] = v.(string) } + return m } @@ -70,5 +75,6 @@ func GetMapValue[T any]( //nolint:ireturn if exists { val = valI.(T) } + return val } diff --git a/internal/types/number.go b/internal/types/number.go index fb300f42f2..0b68174db0 100644 --- a/internal/types/number.go +++ b/internal/types/number.go @@ -6,6 +6,7 @@ func FlattenInt32Ptr(i *int32) interface{} { if i == nil { return 0 } + return *i } @@ -13,6 +14,7 @@ func FlattenUint32Ptr(i *uint32) interface{} { if i == nil { return 0 } + return *i } @@ -20,6 +22,7 @@ func ExpandInt32Ptr(data interface{}) *int32 { if data == nil || data == "" { return nil } + return scw.Int32Ptr(int32(data.(int))) } @@ -27,5 +30,6 @@ func ExpandUint32Ptr(data interface{}) *uint32 { if data == nil || data == "" { return nil } + return scw.Uint32Ptr(uint32(data.(int))) } diff --git a/internal/types/scw.go b/internal/types/scw.go index 686b0404b6..ea7e5451e7 100644 --- a/internal/types/scw.go +++ b/internal/types/scw.go @@ -6,6 +6,7 @@ func FlattenSize(size *scw.Size) interface{} { if size == nil { return 0 } + return *size } @@ -15,5 +16,6 @@ func ExpandSize(data interface{}) *scw.Size { } size := scw.Size(data.(int)) + return &size } diff --git a/internal/types/string.go b/internal/types/string.go index 37fbd41187..e49f3af0f7 100644 --- a/internal/types/string.go +++ b/internal/types/string.go @@ -15,6 +15,7 @@ func FlattenStringPtr(s *string) interface{} { if s == nil { return "" } + return *s } @@ -22,6 +23,7 @@ func ExpandStringPtr(data interface{}) *string { if data == nil || data == "" { return nil } + return scw.StringPtr(data.(string)) } @@ -34,6 +36,7 @@ func ExpandOrGenerateString(data interface{}, prefix string) string { if data == nil || data == "" { return NewRandomName(prefix) } + return data.(string) } @@ -41,6 +44,7 @@ func ExpandStringWithDefault(data interface{}, defaultValue string) string { if data == nil || data.(string) == "" { return defaultValue } + return data.(string) } @@ -52,6 +56,7 @@ func ExpandSliceStringPtr(data interface{}) []*string { for _, s := range data.([]interface{}) { stringSlice = append(stringSlice, ExpandStringPtr(s)) } + return stringSlice } @@ -60,6 +65,7 @@ func FlattenSliceStringPtr(s []*string) interface{} { for _, strPtr := range s { res = append(res, FlattenStringPtr(strPtr)) } + return res } @@ -68,6 +74,7 @@ func FlattenSliceString(s []string) interface{} { for _, strPtr := range s { res = append(res, strPtr) } + return res } @@ -76,6 +83,7 @@ func ExpandUpdatedStringPtr(data interface{}) *string { if data != nil { str = data.(string) } + return &str } @@ -88,6 +96,7 @@ func ExpandStrings(data interface{}) []string { } stringSlice = append(stringSlice, s.(string)) } + return stringSlice } @@ -124,6 +133,7 @@ func ExpandUpdatedStringsPtr(data interface{}) *[]string { } stringSlice = append(stringSlice, s.(string)) } + return &stringSlice } @@ -135,6 +145,7 @@ func ExpandSliceIDs(rawIDs interface{}) []string { for _, s := range rawIDs.([]interface{}) { stringSlice = append(stringSlice, locality.ExpandID(s.(string))) } + return stringSlice } @@ -146,6 +157,7 @@ func ExpandSliceIDsPtr(rawIDs interface{}) *[]string { for _, s := range rawIDs.([]interface{}) { stringSlice = append(stringSlice, locality.ExpandID(s.(string))) } + return &stringSlice } @@ -157,6 +169,7 @@ func ExpandStringsOrEmpty(data interface{}) []string { for _, s := range data.([]interface{}) { stringSlice = append(stringSlice, s.(string)) } + return stringSlice } @@ -192,6 +205,7 @@ func SliceContainsString(slice []string, str string) bool { return true } } + return false } diff --git a/internal/types/time.go b/internal/types/time.go index b92b6e9809..7d47b4c9fe 100644 --- a/internal/types/time.go +++ b/internal/types/time.go @@ -6,6 +6,7 @@ func FlattenDuration(duration *time.Duration) interface{} { if duration != nil { return duration.String() } + return "" } @@ -17,6 +18,7 @@ func ExpandDuration(data interface{}) (*time.Duration, error) { if err != nil { return nil, err } + return &d, nil } @@ -24,6 +26,7 @@ func FlattenTime(date *time.Time) interface{} { if date != nil { return date.Format(time.RFC3339) } + return "" } @@ -38,5 +41,6 @@ func ExpandTimePtr(i interface{}) *time.Time { if err != nil { return nil } + return &parsedTime } diff --git a/internal/verify/enum.go b/internal/verify/enum.go index 0ee2900ea2..463168a9d5 100644 --- a/internal/verify/enum.go +++ b/internal/verify/enum.go @@ -15,12 +15,14 @@ type EnumValues[T ~string] interface { // ValidateEnum creates a schema validation function for the provided enum type func ValidateEnum[T EnumValues[T]]() schema.SchemaValidateDiagFunc { values := filterUnknownValues(getValues[T]()) + return validation.ToDiagFunc(validation.StringInSlice(values, false)) } // ValidateEnumIgnoreCase creates a schema validation function for the provided enum type with case-insensitive validation func ValidateEnumIgnoreCase[T EnumValues[T]]() schema.SchemaValidateDiagFunc { values := filterUnknownValues(getValues[T]()) + return validation.ToDiagFunc(validation.StringInSlice(values, true)) } @@ -31,6 +33,7 @@ func getValues[T EnumValues[T]]() []string { for i, v := range values { result[i] = string(v) } + return result } @@ -43,5 +46,6 @@ func filterUnknownValues(values []string) []string { } filtered = append(filtered, v) } + return filtered } diff --git a/internal/workerpool/workerpool.go b/internal/workerpool/workerpool.go index ffd76c1729..ea26eca145 100644 --- a/internal/workerpool/workerpool.go +++ b/internal/workerpool/workerpool.go @@ -47,6 +47,7 @@ func (p *WorkerPool) dispatcher() { } close(p.tasksToRun) + return } diff --git a/internal/workerpool/workerpool_test.go b/internal/workerpool/workerpool_test.go index 2d018d754d..9460c75846 100644 --- a/internal/workerpool/workerpool_test.go +++ b/internal/workerpool/workerpool_test.go @@ -36,16 +36,19 @@ func TestWorkerPoolWaitTime(t *testing.T) { pool.AddTask(func() error { time.Sleep(50 * time.Millisecond) // lintignore: R018 + return nil }) pool.AddTask(func() error { time.Sleep(50 * time.Millisecond) // lintignore: R018 + return errors.New("error") }) pool.AddTask(func() error { time.Sleep(50 * time.Millisecond) // lintignore: R018 + return nil }) @@ -83,6 +86,7 @@ func TestWorkerPoolWaitTimeMultiple(t *testing.T) { for _, err := range errs { if err.Error() == fmt.Sprintf("error %d", i) { found = true + break } }