Skip to content

Commit

Permalink
fix (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 authored Apr 28, 2024
1 parent 28b3750 commit fe07f98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 4 additions & 10 deletions internal/provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ 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 @@ -420,7 +419,7 @@ func (r clusterResource) Create(ctx context.Context, req resource.CreateRequest,
resp.Diagnostics.AddError("Create Error", fmt.Sprintf("Unable to call GetCluster, got error: %s", err))
return
}
refreshClusterResourceData(getClusterResp.Payload, &data)
refreshClusterResourceData(ctx, getClusterResp.Payload, &data)

// save into the Terraform state.
diags = resp.State.Set(ctx, &data)
Expand Down Expand Up @@ -518,14 +517,14 @@ func (r clusterResource) Read(ctx context.Context, req resource.ReadRequest, res
data.Config.IPAccessList = iPAccessList
data.Config.Paused = paused

refreshClusterResourceData(getClusterResp.Payload, &data)
refreshClusterResourceData(ctx, getClusterResp.Payload, &data)

// save into the Terraform state
diags := resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
}

func refreshClusterResourceData(resp *clusterApi.GetClusterOKBody, data *clusterResourceData) {
func refreshClusterResourceData(ctx context.Context, resp *clusterApi.GetClusterOKBody, data *clusterResourceData) {
// must return
data.Name = resp.Name
data.ClusterId = types.StringValue(*resp.ID)
Expand Down Expand Up @@ -568,11 +567,6 @@ 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 Down Expand Up @@ -776,7 +770,7 @@ func (r clusterResource) Update(ctx context.Context, req resource.UpdateRequest,
resp.Diagnostics.AddError("Update Error", fmt.Sprintf("Unable to call GetClusterById, got error: %s", err))
return
}
refreshClusterResourceData(getClusterResp.Payload, &data)
refreshClusterResourceData(ctx, getClusterResp.Payload, &data)

// save into the Terraform state.
diags = resp.State.Set(ctx, &data)
Expand Down
11 changes: 10 additions & 1 deletion internal/provider/plan_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ func (m clusterResourceStatusModifier) PlanModifyObject(ctx context.Context, req
if req.ConfigValue.IsUnknown() {
return
}
// Does not apply to cluster_status attribute

// Apply state value if cluster is a serverless cluster
var data clusterResourceData
req.State.Get(ctx, &data)
if data.ClusterType == dev {
resp.PlanValue = req.StateValue
return
}

// Does not apply to cluster_status attribute for dedicated
attributes := req.StateValue.Attributes()
attributes["cluster_status"] = types.StringUnknown()
newStateValue, diag := basetypes.NewObjectValue(req.StateValue.AttributeTypes(ctx), attributes)
Expand Down

0 comments on commit fe07f98

Please sign in to comment.