|
1 | 1 | package redis_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "crypto/x509" |
5 | 6 | "encoding/pem" |
6 | 7 | "errors" |
7 | 8 | "fmt" |
8 | 9 | "testing" |
| 10 | + "time" |
9 | 11 |
|
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" |
10 | 13 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
11 | 14 | "github.com/hashicorp/terraform-plugin-testing/terraform" |
12 | 15 | redisSDK "github.com/scaleway/scaleway-sdk-go/api/redis/v1" |
@@ -760,31 +763,36 @@ func TestAccCluster_MigrateToHAMode(t *testing.T) { |
760 | 763 |
|
761 | 764 | func isClusterDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { |
762 | 765 | return func(state *terraform.State) error { |
763 | | - for _, rs := range state.RootModule().Resources { |
764 | | - if rs.Type != "scaleway_redis_cluster" { |
765 | | - continue |
766 | | - } |
767 | | - |
768 | | - redisAPI, zone, ID, err := redis.NewAPIWithZoneAndID(tt.Meta, rs.Primary.ID) |
769 | | - if err != nil { |
770 | | - return err |
771 | | - } |
| 766 | + ctx := context.Background() |
772 | 767 |
|
773 | | - _, err = redisAPI.GetCluster(&redisSDK.GetClusterRequest{ |
774 | | - ClusterID: ID, |
775 | | - Zone: zone, |
776 | | - }) |
| 768 | + return retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError { |
| 769 | + for _, rs := range state.RootModule().Resources { |
| 770 | + if rs.Type != "scaleway_redis_cluster" { |
| 771 | + continue |
| 772 | + } |
777 | 773 |
|
778 | | - if err == nil { |
779 | | - return fmt.Errorf("cluster (%s) still exists", rs.Primary.ID) |
780 | | - } |
| 774 | + api, zone, id, err := redis.NewAPIWithZoneAndID(tt.Meta, rs.Primary.ID) |
| 775 | + if err != nil { |
| 776 | + return retry.NonRetryableError(err) |
| 777 | + } |
781 | 778 |
|
782 | | - if !httperrors.Is404(err) { |
783 | | - return err |
| 779 | + _, err = api.GetCluster(&redisSDK.GetClusterRequest{ |
| 780 | + ClusterID: id, |
| 781 | + Zone: zone, |
| 782 | + }) |
| 783 | + |
| 784 | + switch { |
| 785 | + case err == nil: |
| 786 | + return retry.RetryableError(fmt.Errorf("redis cluster (%s) still exists", rs.Primary.ID)) |
| 787 | + case httperrors.Is404(err): |
| 788 | + continue |
| 789 | + default: |
| 790 | + return retry.NonRetryableError(err) |
| 791 | + } |
784 | 792 | } |
785 | | - } |
786 | 793 |
|
787 | | - return nil |
| 794 | + return nil |
| 795 | + }) |
788 | 796 | } |
789 | 797 | } |
790 | 798 |
|
|
0 commit comments