diff --git a/CHANGELOG.md b/CHANGELOG.md index 913cd7ce..f7d79219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue where changing `num_virtual_cpus` on a `cockroach_cluster` resource would fail to scale the cluster and would result in an inconsistent state error. +- Added validation to prevent multiple serverless regions from being marked as "primary", which could result in an + inconsistent state error. ## [0.7.0] - 2023-07-13 diff --git a/internal/provider/cluster_resource.go b/internal/provider/cluster_resource.go index 68aa8643..73b3a725 100644 --- a/internal/provider/cluster_resource.go +++ b/internal/provider/cluster_resource.go @@ -83,9 +83,6 @@ var regionSchema = schema.NestedAttributeObject{ Optional: true, Computed: true, Description: "Set to true to mark this region as the primary for a Serverless cluster. Exactly one region must be primary. Dedicated clusters expect to have no primary region.", - PlanModifiers: []planmodifier.Bool{ - boolplanmodifier.UseStateForUnknown(), - }, }, }, } @@ -308,6 +305,11 @@ func (r *clusterResource) Create( var primaryRegion string for _, region := range plan.Regions { if region.Primary.ValueBool() { + if primaryRegion != "" { + resp.Diagnostics.AddError("Too many primary regions", + "Only one region may be marked primary when creating a multi-region Serverless cluster.") + return + } primaryRegion = region.Name.ValueString() } regions = append(regions, region.Name.ValueString()) @@ -630,6 +632,11 @@ func (r *clusterResource) Update( var primaryRegion string for _, region := range plan.Regions { if region.Primary.ValueBool() { + if primaryRegion != "" { + resp.Diagnostics.AddError("Too many primary regions", + "Only one region may be marked primary when creating a multi-region Serverless cluster.") + return + } primaryRegion = region.Name.ValueString() } regions = append(regions, region.Name.ValueString())