Skip to content

Commit 4db963e

Browse files
yellow-shineclaude
andcommitted
refactor: deprecate plan field in cluster resource
- Add IgnoreChangesString PlanModifier to suppress all diffs for deprecated fields - Add DeprecationMessage to plan field in schema - Modify Read() to preserve state value instead of overwriting from API This ensures existing resources won't trigger unexpected diffs when the plan field value changes, and users will see deprecation warnings. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 059c30f commit 4db963e

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

docs/resources/cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ resource "zillizcloud_cluster" "enterprise_plan_cluster" {
7979
- `desired_status` (String) The desired status of the cluster. Possible values are RUNNING and SUSPENDED. Defaults to RUNNING.
8080
- `labels` (Map of String) A map of labels to assign to the cluster. Labels are key-value pairs that can be used to organize and categorize clusters.
8181
- `load_balancer_security_groups` (Set of String, Deprecated) A set of security group IDs to associate with the load balancer of the cluster.
82-
- `plan` (String) The plan tier of the Zilliz Cloud service. Available options are Serverless, Standard and Enterprise.
82+
- `plan` (String, Deprecated) The plan tier of the Zilliz Cloud service. Available options are Serverless, Standard and Enterprise.
8383
- `region_id` (String) The ID of the region where the cluster exists.
8484
- `replica` (Number) The number of replicas for the cluster. Defaults to 1.
8585
- `replica_settings` (Attributes) Query compute unit configuration for the cluster. The cu_settings and cu_size cannot be set simultaneously. (see [below for nested schema](#nestedatt--replica_settings))

internal/cluster/cluster_resource.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/hashicorp/terraform-plugin-log/tflog"
2828
zilliz "github.com/zilliztech/terraform-provider-zillizcloud/client"
2929
util "github.com/zilliztech/terraform-provider-zillizcloud/client/retry"
30+
customplanmodifier "github.com/zilliztech/terraform-provider-zillizcloud/internal/planmodifier"
3031
customvalidator "github.com/zilliztech/terraform-provider-zillizcloud/internal/validator"
3132
)
3233

@@ -100,6 +101,10 @@ func (r *ClusterResource) Schema(ctx context.Context, req resource.SchemaRequest
100101
MarkdownDescription: "The plan tier of the Zilliz Cloud service. Available options are Serverless, Standard and Enterprise.",
101102
Optional: true,
102103
Computed: true,
104+
DeprecationMessage: "The plan field is deprecated and will be removed in a future major version. The plan is determined automatically based on cu_size and cu_type.",
105+
PlanModifiers: []planmodifier.String{
106+
customplanmodifier.IgnoreChangesString(),
107+
},
103108
Validators: []validator.String{
104109
stringvalidator.OneOf(FreePlan, ServerlessPlan, StandardPlan, EnterprisePlan, BusinessCriticalPlan),
105110
},
@@ -534,7 +539,10 @@ func (r *ClusterResource) Read(ctx context.Context, req resource.ReadRequest, re
534539
state.ConnectAddress = cluster.ConnectAddress
535540
state.PrivateLinkAddress = cluster.PrivateLinkAddress
536541
state.CreateTime = cluster.CreateTime
537-
state.Plan = cluster.Plan
542+
// plan field is deprecated - only set from API if state is empty (first read after import)
543+
if state.Plan.IsNull() || state.Plan.IsUnknown() {
544+
state.Plan = cluster.Plan
545+
}
538546
state.Replica = cluster.Replica
539547
state.CuSize = cluster.CuSize
540548
state.CuType = cluster.CuType
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package planmodifier
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
7+
)
8+
9+
// ignoreChangesString implements a PlanModifier that suppresses all diffs
10+
// for deprecated fields by keeping the prior state value.
11+
type ignoreChangesString struct{}
12+
13+
func (m ignoreChangesString) Description(ctx context.Context) string {
14+
return "Ignore any configuration changes by keeping the prior state value."
15+
}
16+
17+
func (m ignoreChangesString) MarkdownDescription(ctx context.Context) string {
18+
return m.Description(ctx)
19+
}
20+
21+
func (m ignoreChangesString) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
22+
// If the resource already exists (state is not null/unknown), keep the state value
23+
// This completely suppresses any diff for this field
24+
if !req.StateValue.IsNull() && !req.StateValue.IsUnknown() {
25+
resp.PlanValue = req.StateValue
26+
return
27+
}
28+
29+
// For new resources: use the config value (or null if not set)
30+
// This allows the first apply to write a value to state, which is then preserved
31+
resp.PlanValue = req.ConfigValue
32+
}
33+
34+
// IgnoreChangesString returns a PlanModifier that suppresses all diffs
35+
// by keeping the prior state value. Use this for deprecated fields.
36+
func IgnoreChangesString() planmodifier.String {
37+
return ignoreChangesString{}
38+
}

0 commit comments

Comments
 (0)