@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/dustin/go-humanize"
1212 "github.com/hashicorp/terraform-plugin-log/tflog"
13- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1413 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1514 blockSDK "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
1615 "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -34,7 +33,7 @@ const (
3433 // InstanceServerStateStandby transient state of the instance event waiting third action or rescue mode
3534 InstanceServerStateStandby = "standby"
3635
37- DefaultInstanceServerWaitTimeout = 15 * time .Minute
36+ DefaultInstanceServerWaitTimeout = 20 * time .Minute
3837 defaultInstancePrivateNICWaitTimeout = 10 * time .Minute
3938 defaultInstanceVolumeDeleteTimeout = 10 * time .Minute
4039 defaultInstanceSecurityGroupTimeout = 1 * time .Minute
@@ -554,7 +553,7 @@ func getServerProjectID(ctx context.Context, api *instance.API, zone scw.Zone, s
554553 return server .Server .Project , nil
555554}
556555
557- func attachNewFileSystem (newIDs map [string ]struct {}, oldIDs map [string ]struct {}, api * instancehelpers. BlockAndInstanceAPI , zone scw.Zone , server * instance.Server ) (diag. Diagnostics , bool ) {
556+ func attachNewFileSystem (ctx context. Context , newIDs map [string ]struct {}, oldIDs map [string ]struct {}, api * instance. API , zone scw.Zone , server * instance.Server ) error {
558557 for id := range newIDs {
559558 if _ , alreadyAttached := oldIDs [id ]; ! alreadyAttached {
560559 _ , err := api .AttachServerFileSystem (& instance.AttachServerFileSystemRequest {
@@ -563,15 +562,19 @@ func attachNewFileSystem(newIDs map[string]struct{}, oldIDs map[string]struct{},
563562 FilesystemID : locality .ExpandID (id ),
564563 })
565564 if err != nil {
566- return diag .FromErr (fmt .Errorf ("error attaching filesystem %s: %w" , id , err )), true
565+ return fmt .Errorf ("error attaching filesystem %s: %w" , id , err )
566+ }
567+ _ , err = waitForFilesystems (ctx , api , zone , server .ID , * scw .TimeDurationPtr (DefaultInstanceServerWaitTimeout ))
568+ if err != nil {
569+ return err
567570 }
568571 }
569572 }
570573
571- return nil , false
574+ return nil
572575}
573576
574- func detachOldFileSystem (oldIDs map [string ]struct {}, newIDs map [string ]struct {}, api * instancehelpers. BlockAndInstanceAPI , zone scw.Zone , server * instance.Server ) (diag. Diagnostics , bool ) {
577+ func detachOldFileSystem (ctx context. Context , oldIDs map [string ]struct {}, newIDs map [string ]struct {}, api * instance. API , zone scw.Zone , server * instance.Server ) error {
575578 for id := range oldIDs {
576579 if _ , stillPresent := newIDs [id ]; ! stillPresent {
577580 _ , err := api .DetachServerFileSystem (& instance.DetachServerFileSystemRequest {
@@ -580,12 +583,16 @@ func detachOldFileSystem(oldIDs map[string]struct{}, newIDs map[string]struct{},
580583 FilesystemID : locality .ExpandID (id ),
581584 })
582585 if err != nil {
583- return diag .FromErr (fmt .Errorf ("error detaching filesystem %s: %w" , id , err )), true
586+ return fmt .Errorf ("error detaching filesystem %s: %w" , id , err )
587+ }
588+ _ , err = waitForFilesystems (ctx , api , zone , server .ID , * scw .TimeDurationPtr (DefaultInstanceServerWaitTimeout ))
589+ if err != nil && ! httperrors .Is404 (err ) {
590+ return err
584591 }
585592 }
586593 }
587594
588- return nil , false
595+ return nil
589596}
590597
591598func collectFilesystemIDs (fsList []any , target map [string ]struct {}) {
0 commit comments