@@ -10,7 +10,6 @@ import (
10
10
11
11
"github.com/dustin/go-humanize"
12
12
"github.com/hashicorp/terraform-plugin-log/tflog"
13
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
14
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
15
14
blockSDK "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
16
15
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -34,7 +33,7 @@ const (
34
33
// InstanceServerStateStandby transient state of the instance event waiting third action or rescue mode
35
34
InstanceServerStateStandby = "standby"
36
35
37
- DefaultInstanceServerWaitTimeout = 15 * time .Minute
36
+ DefaultInstanceServerWaitTimeout = 20 * time .Minute
38
37
defaultInstancePrivateNICWaitTimeout = 10 * time .Minute
39
38
defaultInstanceVolumeDeleteTimeout = 10 * time .Minute
40
39
defaultInstanceSecurityGroupTimeout = 1 * time .Minute
@@ -554,7 +553,7 @@ func getServerProjectID(ctx context.Context, api *instance.API, zone scw.Zone, s
554
553
return server .Server .Project , nil
555
554
}
556
555
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 {
558
557
for id := range newIDs {
559
558
if _ , alreadyAttached := oldIDs [id ]; ! alreadyAttached {
560
559
_ , err := api .AttachServerFileSystem (& instance.AttachServerFileSystemRequest {
@@ -563,15 +562,19 @@ func attachNewFileSystem(newIDs map[string]struct{}, oldIDs map[string]struct{},
563
562
FilesystemID : locality .ExpandID (id ),
564
563
})
565
564
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
567
570
}
568
571
}
569
572
}
570
573
571
- return nil , false
574
+ return nil
572
575
}
573
576
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 {
575
578
for id := range oldIDs {
576
579
if _ , stillPresent := newIDs [id ]; ! stillPresent {
577
580
_ , err := api .DetachServerFileSystem (& instance.DetachServerFileSystemRequest {
@@ -580,12 +583,16 @@ func detachOldFileSystem(oldIDs map[string]struct{}, newIDs map[string]struct{},
580
583
FilesystemID : locality .ExpandID (id ),
581
584
})
582
585
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
584
591
}
585
592
}
586
593
}
587
594
588
- return nil , false
595
+ return nil
589
596
}
590
597
591
598
func collectFilesystemIDs (fsList []any , target map [string ]struct {}) {
0 commit comments