Skip to content

Commit

Permalink
fix resume
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Apr 15, 2024
1 parent 5d176bd commit 7d7f88e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/backup_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 13 additions & 7 deletions internal/provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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 {
Expand All @@ -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

}

Expand Down Expand Up @@ -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
Expand All @@ -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,
}
}
}
Expand All @@ -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,
}
Expand Down

0 comments on commit 7d7f88e

Please sign in to comment.