Skip to content

Commit

Permalink
Update sdk to 4.2.0 and add support for cidr_range
Browse files Browse the repository at this point in the history
Add support for setting the cidr_range value for GCP clusters.
  • Loading branch information
fantapop committed Nov 12, 2024
1 parent b15409f commit e05b068
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Setting and fetching of `cidr_range` is now available for GCP Advanced tier
clusters.

- Management of cluster backup settings is now supported using the
`backup_config` attribute on the `cockroach_cluster` resource. For more
information, refer to
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Read-Only:

Read-Only:

- `cidr_range` (String) The IPv4 range in CIDR format that will be used by the cluster. It is only set on GCP clusters and is otherwise empty.
- `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.
- `machine_type` (String) Machine type identifier within the given cloud provider, ex. m6.xlarge, n2-standard-4.
- `memory_gib` (Number) Memory per node in GiB.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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.
- `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.
Expand Down
1 change: 1 addition & 0 deletions examples/workflows/cockroach_advanced_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ resource "cockroach_cluster" "example" {
dedicated = {
storage_gib = var.storage_gib
num_virtual_cpus = var.num_virtual_cpus
cidr_range = "172.28.0.0/14"
}
regions = [
for r in var.cloud_provider_regions : {
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (d *clusterDataSource) Schema(
Computed: true,
Description: "Indicates whether private IP addresses are assigned to nodes. Required for CMEK and other advanced networking features.",
},
"cidr_range": schema.StringAttribute{
Computed: true,
Description: "The IPv4 range in CIDR format that is in use by the cluster. It is only set on GCP clusters and is otherwise empty.",
},
},
},
"regions": schema.ListNestedAttribute{
Expand Down
18 changes: 18 additions & 0 deletions internal/provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ func (r *clusterResource) Schema(
boolplanmodifier.UseStateForUnknown(),
},
},
"cidr_range": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "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.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
},
"regions": schema.ListNestedAttribute{
Expand Down Expand Up @@ -472,6 +480,9 @@ func (r *clusterResource) Create(
visibilityPrivate := client.NETWORKVISIBILITYTYPE_PRIVATE
dedicated.NetworkVisibility = &visibilityPrivate
}
if cfg.CidrRange.ValueString() != "" {
dedicated.CidrRange = ptr(cfg.CidrRange.ValueString())
}
}
clusterSpec.SetDedicated(dedicated)
}
Expand Down Expand Up @@ -700,6 +711,12 @@ func (r *clusterResource) ModifyPlan(
"visibility isn't allowed. Please explicitly destroy this cluster before changing "+
"network visibility.")
}
if dedicated := plan.DedicatedConfig; dedicated != nil && dedicated.CidrRange != state.DedicatedConfig.CidrRange {
resp.Diagnostics.AddError("Cannot update cidr range",
"To prevent accidental deletion of data, changing a cluster's cidr range "+
"isn't allowed. Please explicitly destroy this cluster before changing "+
"cidr range.")
}
}

if req.Plan.Raw.IsNull() {
Expand Down Expand Up @@ -1238,6 +1255,7 @@ func loadClusterToTerraformState(
MemoryGib: types.Float64Value(float64(clusterObj.Config.Dedicated.MemoryGib)),
DiskIops: types.Int64Value(int64(clusterObj.Config.Dedicated.DiskIops)),
PrivateNetworkVisibility: types.BoolValue(clusterObj.GetNetworkVisibility() == client.NETWORKVISIBILITYTYPE_PRIVATE),
CidrRange: types.StringValue(*clusterObj.CidrRange),
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DedicatedClusterConfig struct {
MemoryGib types.Float64 `tfsdk:"memory_gib"`
DiskIops types.Int64 `tfsdk:"disk_iops"`
PrivateNetworkVisibility types.Bool `tfsdk:"private_network_visibility"`
CidrRange types.String `tfsdk:"cidr_range"`
}

type ServerlessClusterConfig struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e05b068

Please sign in to comment.