Skip to content

Commit 84ef4f8

Browse files
committed
Added condition for all the node_info cases
1 parent 19c47ce commit 84ef4f8

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

internal/service/grid/member_resource.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,17 +556,37 @@ func (r *MemberResource) ValidateConfig(ctx context.Context, req resource.Valida
556556
mgmtCheckComplete = true
557557
}
558558
}
559+
// enableHaFalse: true when enable_ha is null (defaults to false) or explicitly false.
560+
// Skipped when enable_ha is unknown (value not yet determined at plan time).
561+
enableHaFalse := data.EnableHa.IsNull() || (!data.EnableHa.IsUnknown() && !data.EnableHa.ValueBool())
562+
// enableHaTrue: true only when enable_ha is explicitly set to true.
563+
enableHaTrue := !data.EnableHa.IsNull() && !data.EnableHa.IsUnknown() && data.EnableHa.ValueBool()
559564

560-
if len(nodeInfo) == 2 {
561-
if data.EnableHa.IsNull() || data.EnableHa.IsUnknown() || !data.EnableHa.ValueBool() {
562-
resp.Diagnostics.AddError("Validation Error", "node_info contains 2 nodes but enable_ha is not set to true. Either set enable_ha = true to enable HA mode, or configure only a single node in node_info when enable_ha is false")
563-
}
564-
} else if len(nodeInfo) > 2 {
565-
if !data.EnableHa.IsNull() && !data.EnableHa.IsUnknown() && data.EnableHa.ValueBool() {
566-
resp.Diagnostics.AddError("Validation Error", "node_info must contain exactly 2 nodes when enable_ha is true")
567-
} else {
568-
resp.Diagnostics.AddError("Validation Error", "node_info must contain 1 node when enable_ha is false")
569-
}
565+
nodeCount := len(nodeInfo)
566+
567+
// Condition 1: len(nodeInfo) == 2 requires enable_ha to be true
568+
if nodeCount == 2 && enableHaFalse {
569+
resp.Diagnostics.AddError("Validation Error", "enable_ha must be true when node_info has 2 nodes")
570+
}
571+
572+
// Condition 2: enable_ha true requires exactly 2 nodes (not more)
573+
if enableHaTrue && nodeCount > 2 {
574+
resp.Diagnostics.AddError("Validation Error", "node_info must have exactly 2 nodes when enable_ha is true")
575+
}
576+
577+
// Condition 3a: len(nodeInfo) > 2 with enable_ha false (or not set) is not allowed
578+
if nodeCount > 2 && enableHaFalse {
579+
resp.Diagnostics.AddError("Validation Error", "node_info cannot have more than 2 nodes when enable_ha is false")
580+
}
581+
582+
// Condition 3b: len(nodeInfo) == 1 with enable_ha false (or not set) is not allowed
583+
if nodeCount == 1 && enableHaFalse {
584+
resp.Diagnostics.AddError("Validation Error", "node_info with a single node is not valid when enable_ha is false; provide exactly 2 nodes with enable_ha set to true, or omit node_info")
585+
}
586+
587+
// Condition 3c: len(nodeInfo) == 1 with enable_ha true is not allowed
588+
if nodeCount == 1 && enableHaTrue {
589+
resp.Diagnostics.AddError("Validation Error", "node_info must have exactly 2 nodes when enable_ha is true; a single node_info entry is not valid")
570590
}
571591
}
572592

0 commit comments

Comments
 (0)