Skip to content

Commit c567cdd

Browse files
committed
fix(cluster): add min_nodes validation to v1 schema and improve error messages
- Add ValidateDiagFunc to min_nodes in cluster_v1 schema to match the validation in the current schema (>= 3 and divisible by 3) - Improve multi-datacenter error messages to be more descriptive by including context about what was found These changes ensure consistent validation during state migration and provide clearer error messages for users.
1 parent a3ad3b4 commit c567cdd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/provider/cluster/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
360360
}
361361

362362
if n := len(cluster.Datacenters); n > 1 {
363-
return diag.Errorf("multi-datacenter clusters are not currently supported: %d", n)
363+
return diag.Errorf("multi-datacenter clusters are not currently supported (found %d datacenters)", n)
364364
}
365365

366366
var instanceExternalID string
@@ -488,7 +488,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
488488
}
489489

490490
if n := len(cluster.Datacenters); n > 1 {
491-
return diag.Errorf("multi-datacenter clusters are not currently supported: %d", n)
491+
return diag.Errorf("multi-datacenter clusters are not currently supported (found %d datacenters)", n)
492492
}
493493

494494
// Resize will fail if there is any ongoing cluster request.

internal/provider/cluster/cluster_v1.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/hashicorp/go-cty/cty"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
810
)
911

@@ -113,6 +115,16 @@ func resourceClusterV1() *schema.Resource {
113115
"min_nodes": {
114116
Required: true,
115117
Type: schema.TypeInt,
118+
ValidateDiagFunc: func(v interface{}, path cty.Path) diag.Diagnostics {
119+
value := v.(int)
120+
if value < 3 {
121+
return diag.Errorf("min_nodes must be at least 3, got %d", value)
122+
}
123+
if value%3 != 0 {
124+
return diag.Errorf("min_nodes must be divisible by 3, got %d", value)
125+
}
126+
return nil
127+
},
116128
},
117129
},
118130
}

0 commit comments

Comments
 (0)