Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ resource "zillizcloud_cluster" "enterprise_plan_cluster" {
- `desired_status` (String) The desired status of the cluster. Possible values are RUNNING and SUSPENDED. Defaults to RUNNING.
- `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.
- `load_balancer_security_groups` (Set of String, Deprecated) A set of security group IDs to associate with the load balancer of the cluster.
- `plan` (String) The plan tier of the Zilliz Cloud service. Available options are Serverless, Standard and Enterprise.
- `plan` (String, Deprecated) The plan tier of the Zilliz Cloud service. Available options are Serverless, Standard and Enterprise.
- `region_id` (String) The ID of the region where the cluster exists.
- `replica` (Number) The number of replicas for the cluster. Defaults to 1.
- `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))
Expand Down
10 changes: 9 additions & 1 deletion internal/cluster/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
zilliz "github.com/zilliztech/terraform-provider-zillizcloud/client"
util "github.com/zilliztech/terraform-provider-zillizcloud/client/retry"
customplanmodifier "github.com/zilliztech/terraform-provider-zillizcloud/internal/planmodifier"
customvalidator "github.com/zilliztech/terraform-provider-zillizcloud/internal/validator"
)

Expand Down Expand Up @@ -100,6 +101,10 @@ func (r *ClusterResource) Schema(ctx context.Context, req resource.SchemaRequest
MarkdownDescription: "The plan tier of the Zilliz Cloud service. Available options are Serverless, Standard and Enterprise.",
Optional: true,
Computed: true,
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.",
PlanModifiers: []planmodifier.String{
customplanmodifier.IgnoreChangesString(),
},
Validators: []validator.String{
stringvalidator.OneOf(FreePlan, ServerlessPlan, StandardPlan, EnterprisePlan, BusinessCriticalPlan),
},
Expand Down Expand Up @@ -534,7 +539,10 @@ func (r *ClusterResource) Read(ctx context.Context, req resource.ReadRequest, re
state.ConnectAddress = cluster.ConnectAddress
state.PrivateLinkAddress = cluster.PrivateLinkAddress
state.CreateTime = cluster.CreateTime
state.Plan = cluster.Plan
// plan field is deprecated - only set from API if state is empty (first read after import)
if state.Plan.IsNull() || state.Plan.IsUnknown() {
state.Plan = cluster.Plan
}
state.Replica = cluster.Replica
state.CuSize = cluster.CuSize
state.CuType = cluster.CuType
Expand Down
38 changes: 38 additions & 0 deletions internal/planmodifier/ignore_changes_string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package planmodifier

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
)

// ignoreChangesString implements a PlanModifier that suppresses all diffs
// for deprecated fields by keeping the prior state value.
type ignoreChangesString struct{}

func (m ignoreChangesString) Description(ctx context.Context) string {
return "Ignore any configuration changes by keeping the prior state value."
}

func (m ignoreChangesString) MarkdownDescription(ctx context.Context) string {
return m.Description(ctx)
}

func (m ignoreChangesString) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
// If the resource already exists (state is not null/unknown), keep the state value
// This completely suppresses any diff for this field
if !req.StateValue.IsNull() && !req.StateValue.IsUnknown() {
resp.PlanValue = req.StateValue
return
}

// For new resources: use the config value (or null if not set)
// This allows the first apply to write a value to state, which is then preserved
resp.PlanValue = req.ConfigValue
}

// IgnoreChangesString returns a PlanModifier that suppresses all diffs
// by keeping the prior state value. Use this for deprecated fields.
func IgnoreChangesString() planmodifier.String {
return ignoreChangesString{}
}
Loading