From 28c8af9499af035e34bc1834d18e264d330f08de Mon Sep 17 00:00:00 2001 From: Christopher Fitzner Date: Fri, 6 Dec 2024 12:25:09 -0800 Subject: [PATCH] [CC-30766] disallow 0 as a value for disk_iops 0 is a valid value to pass into the api for disk_iops. That, along with omitting the value in the api call results in the default iops value. However, the api returns the actual value for the iops that was chosen. This results in a configuration conflict with the set value of 0 and the actual value that was returned from the server. For this reason we now disallow 0 from being set and we clarify in the docs that omitting the value is the correct way to ask for the default. --- CHANGELOG.md | 3 +++ docs/resources/cluster.md | 2 +- internal/provider/cluster_resource.go | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82cc8b04..49b11c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Disallow 0 from being passed for disk_iops and update the docs to indicate + that omitting the attribute is the correct way to get the default behavior. + - Validate that `node_count` is not passed in with serverless cluster regions. Also, clear up in the documentation that this is not allowed. diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 6d748bc9..1da2a01a 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -139,7 +139,7 @@ Optional: Optional: - `cidr_range` (String) The IPv4 range in CIDR format that will be used by the cluster. This is supported only on GCP, and must have a subnet mask no larger than /19. Defaults to "172.28.0.0/14". This cannot be changed after cluster creation. -- `disk_iops` (Number) Number of disk I/O operations per second that are permitted on each node in the cluster. Zero indicates the cloud provider-specific default. +- `disk_iops` (Number) Number of disk I/O operations per second that are permitted on each node in the cluster. Omitting this attribute will result in the cloud provider-specific default. - `machine_type` (String) Machine type identifier within the given cloud provider, e.g., m6.xlarge, n2-standard-4. - `num_virtual_cpus` (Number) Number of virtual CPUs per node in the cluster. - `private_network_visibility` (Boolean) Set to true to assign private IP addresses to nodes. Required for CMEK and other advanced networking features. Clusters created with this flag will have advanced security features enabled. This cannot be changed after cluster creation and incurs additional charges. See [Create an Advanced Cluster](https://www.cockroachlabs.com/docs/cockroachcloud/create-an-advanced-cluster.html#step-6-configure-advanced-security-features) and [Pricing](https://www.cockroachlabs.com/pricing/) for more information. diff --git a/internal/provider/cluster_resource.go b/internal/provider/cluster_resource.go index 83d5d54c..6d5b028b 100644 --- a/internal/provider/cluster_resource.go +++ b/internal/provider/cluster_resource.go @@ -27,6 +27,7 @@ import ( "github.com/cockroachdb/cockroach-cloud-sdk-go/v5/pkg/client" "github.com/cockroachdb/terraform-provider-cockroach/internal/validators" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -218,7 +219,13 @@ func (r *clusterResource) Schema( "disk_iops": schema.Int64Attribute{ Optional: true, Computed: true, - Description: "Number of disk I/O operations per second that are permitted on each node in the cluster. Zero indicates the cloud provider-specific default.", + Validators: []validator.Int64{ + // If supplied this value must be non-zero. 0 is a + // valid api value indicating the default being + // returned but it causes a provider inconsistency. + int64validator.AtLeast(1), + }, + Description: "Number of disk I/O operations per second that are permitted on each node in the cluster. Omitting this attribute will result in the cloud provider-specific default.", }, "memory_gib": schema.Float64Attribute{ Computed: true,