From 7d7f88ed2d8938b9c647458f7c33e91d4fbfcef7 Mon Sep 17 00:00:00 2001 From: shiyuhang <1136742008@qq.com> Date: Mon, 15 Apr 2024 22:39:16 +0800 Subject: [PATCH] fix resume --- go.mod | 2 +- go.sum | 6 ++---- internal/provider/backup_resource.go | 3 ++- internal/provider/cluster_resource.go | 20 +++++++++++++------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 78521e2..020527a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/tidbcloud/terraform-provider-tidbcloud go 1.21 require ( - github.com/c4pt0r/go-tidbcloud-sdk-v1 v0.0.0-20221102224337-3b1c2179c517 + github.com/c4pt0r/go-tidbcloud-sdk-v1 v0.0.0-20240415110020-a27efb454da5 github.com/go-openapi/errors v0.21.0 github.com/go-openapi/runtime v0.25.0 github.com/go-openapi/strfmt v0.22.0 diff --git a/go.sum b/go.sum index 153a183..ec1fc52 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= -github.com/c4pt0r/go-tidbcloud-sdk-v1 v0.0.0-20221102224337-3b1c2179c517 h1:R1+EN+EkZV4fPGB6+1bTe267fnBc6JBq+qTJaQU2rRY= -github.com/c4pt0r/go-tidbcloud-sdk-v1 v0.0.0-20221102224337-3b1c2179c517/go.mod h1:mCYM+u/09SNW15Ed+qn+JeuxkK9dr+Fq0DZk+kUkB74= +github.com/c4pt0r/go-tidbcloud-sdk-v1 v0.0.0-20240415110020-a27efb454da5 h1:QdHeP1q1E2dv5fWuIkQNNmHr5vm/+jlYPK10TR3iV1M= +github.com/c4pt0r/go-tidbcloud-sdk-v1 v0.0.0-20240415110020-a27efb454da5/go.mod h1:mCYM+u/09SNW15Ed+qn+JeuxkK9dr+Fq0DZk+kUkB74= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -429,8 +429,6 @@ google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/provider/backup_resource.go b/internal/provider/backup_resource.go index c03aea9..d12e0a0 100644 --- a/internal/provider/backup_resource.go +++ b/internal/provider/backup_resource.go @@ -128,7 +128,8 @@ func (r *backupResource) Create(ctx context.Context, req resource.CreateRequest, Name: &data.Name, } if !data.Description.IsUnknown() && !data.Description.IsNull() { - createBackupBody.Description = data.Description.ValueString() + description := data.Description.ValueString() + createBackupBody.Description = &description } createBackupOK, err := r.provider.client.CreateBackup(backupApi.NewCreateBackupParams().WithProjectID(data.ProjectId).WithClusterID(data.ClusterId).WithBody(createBackupBody)) if err != nil { diff --git a/internal/provider/cluster_resource.go b/internal/provider/cluster_resource.go index 4192440..9401c63 100644 --- a/internal/provider/cluster_resource.go +++ b/internal/provider/cluster_resource.go @@ -236,6 +236,7 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re " - The cluster can be paused only when the cluster_status is \"AVAILABLE\"." + " - The cluster can be resumed only when the cluster_status is \"PAUSED\".", Optional: true, + Computed: true, }, "components": schema.SingleNestedAttribute{ MarkdownDescription: "The components of the cluster.\n" + @@ -567,6 +568,11 @@ func refreshClusterResourceData(resp *clusterApi.GetClusterOKBody, data *cluster VpcPeering: &vpcPeering, }, } + paused := false + if resp.Status.ClusterStatus == "PAUSED" || resp.Status.ClusterStatus == "PAUSING" { + paused = true + } + data.Config.Paused = &paused // may return tiflash := resp.Config.Components.Tiflash if tiflash != nil { @@ -578,7 +584,7 @@ func refreshClusterResourceData(resp *clusterApi.GetClusterOKBody, data *cluster } // not return - // IPAccessList, password and pause will not update for it will not return by read api + // IPAccessList, and password and pause will not update for it will not return by read api } @@ -716,7 +722,7 @@ func (r clusterResource) Update(ctx context.Context, req resource.UpdateRequest, // build paused if data.Config.Paused != nil { if state.Config.Paused == nil || *data.Config.Paused != *state.Config.Paused { - updateClusterBody.Config.Paused = *data.Config.Paused + updateClusterBody.Config.Paused = data.Config.Paused } } // build components @@ -730,15 +736,15 @@ func (r clusterResource) Update(ctx context.Context, req resource.UpdateRequest, if tiflashState == nil { isComponentsChanged = true componentTiFlash = &clusterApi.UpdateClusterParamsBodyConfigComponentsTiflash{ - NodeQuantity: tiflash.NodeQuantity, - NodeSize: tiflash.NodeSize, - StorageSizeGib: tiflash.StorageSizeGib, + NodeQuantity: &tiflash.NodeQuantity, + NodeSize: &tiflash.NodeSize, + StorageSizeGib: &tiflash.StorageSizeGib, } } else if tiflash.NodeQuantity != tiflashState.NodeQuantity { isComponentsChanged = true // NodeSize can't be changed componentTiFlash = &clusterApi.UpdateClusterParamsBodyConfigComponentsTiflash{ - NodeQuantity: tiflash.NodeQuantity, + NodeQuantity: &tiflash.NodeQuantity, } } } @@ -749,7 +755,7 @@ func (r clusterResource) Update(ctx context.Context, req resource.UpdateRequest, NodeQuantity: &tidb.NodeQuantity, }, Tikv: &clusterApi.UpdateClusterParamsBodyConfigComponentsTikv{ - NodeQuantity: tikv.NodeQuantity, + NodeQuantity: &tikv.NodeQuantity, }, Tiflash: componentTiFlash, }