Skip to content

Commit

Permalink
Fix TestAccMultiRegionServerlessClusterResource (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
erademacher committed Aug 8, 2023
1 parent 9f491da commit 6562186
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions internal/provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
},
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 6562186

Please sign in to comment.