|
| 1 | +package tke |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 8 | + tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" |
| 9 | + |
| 10 | + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" |
| 11 | +) |
| 12 | + |
| 13 | +func resourceTencentCloudKubernetesBackupStorageLocationCreatePostHandleResponse0(ctx context.Context, resp *tke.CreateBackupStorageLocationResponse) error { |
| 14 | + d := tccommon.ResourceDataFromContext(ctx) |
| 15 | + if d == nil { |
| 16 | + return fmt.Errorf("resource data can not be nil") |
| 17 | + } |
| 18 | + |
| 19 | + meta := tccommon.ProviderMetaFromContext(ctx) |
| 20 | + if meta == nil { |
| 21 | + return fmt.Errorf("provider meta can not be nil") |
| 22 | + } |
| 23 | + service := TkeService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} |
| 24 | + |
| 25 | + // wait for status ok |
| 26 | + return resource.Retry(3*tccommon.ReadRetryTimeout, func() *resource.RetryError { |
| 27 | + locations, errRet := service.DescribeBackupStorageLocations(ctx, []string{d.Get("name").(string)}) |
| 28 | + if errRet != nil { |
| 29 | + return tccommon.RetryError(errRet, tccommon.InternalError) |
| 30 | + } |
| 31 | + if len(locations) != 1 { |
| 32 | + resource.RetryableError(fmt.Errorf("more than 1 location returnen in api response, expected 1 but got %d", len(locations))) |
| 33 | + } |
| 34 | + if locations[0].State == nil { |
| 35 | + return resource.RetryableError(fmt.Errorf("location %s is still in state nil", d.Get("name").(string))) |
| 36 | + } |
| 37 | + if len(locations) == 1 && *locations[0].State == backupStorageLocationStateAvailable { |
| 38 | + return nil |
| 39 | + } |
| 40 | + return resource.RetryableError(fmt.Errorf("location %s is still in state %s", d.Get("name").(string), *locations[0].State)) |
| 41 | + }) |
| 42 | +} |
| 43 | + |
| 44 | +func resourceTencentCloudKubernetesBackupStorageLocationDeletePostHandleResponse0(ctx context.Context, resp *tke.DeleteBackupStorageLocationResponse) error { |
| 45 | + d := tccommon.ResourceDataFromContext(ctx) |
| 46 | + if d == nil { |
| 47 | + return fmt.Errorf("resource data can not be nil") |
| 48 | + } |
| 49 | + meta := tccommon.ProviderMetaFromContext(ctx) |
| 50 | + if meta == nil { |
| 51 | + return fmt.Errorf("provider meta can not be nil") |
| 52 | + } |
| 53 | + service := TkeService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} |
| 54 | + |
| 55 | + // wait until location is deleted |
| 56 | + return resource.Retry(3*tccommon.ReadRetryTimeout, func() *resource.RetryError { |
| 57 | + locations, errRet := service.DescribeBackupStorageLocations(ctx, []string{d.Id()}) |
| 58 | + if errRet != nil { |
| 59 | + return tccommon.RetryError(errRet, tccommon.InternalError) |
| 60 | + } |
| 61 | + if len(locations) == 0 { |
| 62 | + return nil |
| 63 | + } |
| 64 | + return resource.RetryableError(fmt.Errorf("location %s is still not deleted", d.Id())) |
| 65 | + }) |
| 66 | +} |
0 commit comments