Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merges the contents of the long running cloud-20 branch into main #238

Merged
merged 11 commits into from
Sep 19, 2024
Merged
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.8.0] - 2024-09-18

### Added

- `upgrade_type` was added as an attribute for serverless clusters.
- New `STANDARD` clusters with provisioned serverless capacity.
- Ability to upgrade from `BASIC` plan to `STANDARD` plan.

### Changed

- Renamed `SERVERLESS` plan type to `BASIC`.
- Renamed `DEDICATED` plan type to `ADVANCED`.

### Fixed

- Fixed error when the primary attribute was specified in multiple regions,
even when false in all but one region.

### Deprecated

- Deprecated support for `spend_limit` attribute in `serverless` config. Users
can instead enforce resource limits with `usage_limits`.

## Fixed

- Updated to version 2.0.1 of cockroach-cloud-sdk-go
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ NAMESPACE=cockroachdb
NAME=cockroach
BINARY=terraform-provider-${NAME}
VERSION=1.6.0
OS_ARCH=darwin_amd64
OS := $(shell uname | tr A-Z a-z)
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
OS_ARCH := $(OS)_$(ARCH)

default: install

Expand All @@ -16,7 +18,7 @@ generate:
go generate

update-sdk:
go get github.com/cockroachdb/cockroach-cloud-sdk-go/v2
go get github.com/cockroachdb/cockroach-cloud-sdk-go/v3
go generate ./mock

release:
Expand All @@ -33,10 +35,17 @@ release:
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64

# Use this to install a development binary to your local machine, in the TF
# provider cache. Note that if this directory is present, using an "official"
# version of the provider is disabled. Use "make clean" to reset.
install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

clean:
rm -rf ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/
go clean -testcache -i -x

test:
go test ./... -v $(TESTARGS) -timeout 5m

Expand Down
6 changes: 4 additions & 2 deletions docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data "cockroach_cluster" "cockroach" {
- `name` (String) Name of the cluster.
- `operation_status` (String) Describes the current long-running operation, if any.
- `parent_id` (String) The ID of the cluster's parent folder. 'root' is used for a cluster at the root level.
- `plan` (String) Denotes cluster deployment type: 'DEDICATED' or 'SERVERLESS'.
- `plan` (String) Denotes cluster plan type: 'BASIC' or 'STANDARD' or 'ADVANCED'.
- `regions` (Attributes List) (see [below for nested schema](#nestedatt--regions))
- `serverless` (Attributes) (see [below for nested schema](#nestedatt--serverless))
- `state` (String) Describes whether the cluster is being created, updated, deleted, etc.
Expand Down Expand Up @@ -78,13 +78,15 @@ Read-Only:
Read-Only:

- `routing_id` (String) Cluster identifier in a connection string.
- `spend_limit` (Number) Spend limit in US cents.
- `spend_limit` (Number, Deprecated) Spend limit in US cents.
- `upgrade_type` (String) Dictates the behavior of cockroach major version upgrades.
- `usage_limits` (Attributes) (see [below for nested schema](#nestedatt--serverless--usage_limits))

<a id="nestedatt--serverless--usage_limits"></a>
### Nested Schema for `serverless.usage_limits`

Read-Only:

- `provisioned_virtual_cpus` (Number) Maximum number of vCPUs that the cluster can use.
- `request_unit_limit` (Number) Maximum number of Request Units that the cluster can consume during the month.
- `storage_mib_limit` (Number) Maximum amount of storage (in MiB) that the cluster can have at any time during the month.
46 changes: 34 additions & 12 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
page_title: "cockroach_cluster Resource - terraform-provider-cockroach"
subcategory: ""
description: |-
CockroachDB Cloud cluster. Can be Dedicated or Serverless.
CockroachDB Cloud cluster.
---

# cockroach_cluster (Resource)

CockroachDB Cloud cluster. Can be Dedicated or Serverless.
CockroachDB Cloud cluster.

## Example Usage

```terraform
resource "cockroach_cluster" "dedicated" {
name = "cockroach-dedicated"
resource "cockroach_cluster" "advanced" {
name = "cockroach-advanced"
cloud_provider = "GCP"
plan = "ADVANCED"
dedicated = {
storage_gib = 15
machine_type = "n1-standard-4"
machine_type = "n2-standard-4"
}
regions = [
{
Expand All @@ -29,11 +30,15 @@ resource "cockroach_cluster" "dedicated" {
delete_protection = true
}

resource "cockroach_cluster" "serverless" {
name = "cockroach-serverless"
resource "cockroach_cluster" "standard" {
name = "cockroach-standard"
cloud_provider = "GCP"
plan = "STANDARD"
serverless = {
spend_limit = 1
usage_limits = {
provisioned_virtual_cpus = 2
}
upgrade_type = "AUTOMATIC"
}
regions = [
{
Expand All @@ -42,6 +47,19 @@ resource "cockroach_cluster" "serverless" {
]
delete_protection = false
}

resource "cockroach_cluster" "basic" {
name = "cockroach-basic"
cloud_provider = "GCP"
plan = "BASIC"
serverless = {}
regions = [
{
name = "us-east1"
}
]
delete_protection = false
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -62,6 +80,7 @@ resource "cockroach_cluster" "serverless" {
- `dedicated` (Attributes) (see [below for nested schema](#nestedatt--dedicated))
- `delete_protection` (Boolean) Set to true to enable delete protection on the cluster. If unset, the server chooses the value on cluster creation, and preserves the value on cluster update.
- `parent_id` (String) The ID of the cluster's parent folder. 'root' is used for a cluster at the root level.
- `plan` (String) Denotes cluster plan type: 'BASIC' or 'STANDARD' or 'ADVANCED'.
- `serverless` (Attributes) (see [below for nested schema](#nestedatt--serverless))

### Read-Only
Expand All @@ -70,7 +89,6 @@ resource "cockroach_cluster" "serverless" {
- `creator_id` (String) ID of the user who created the cluster.
- `id` (String) The ID of this resource.
- `operation_status` (String) Describes the current long-running operation, if any.
- `plan` (String) Denotes cluster deployment type: 'DEDICATED' or 'SERVERLESS'.
- `state` (String) Describes whether the cluster is being created, updated, deleted, etc.
- `upgrade_status` (String) Describes the status of any in-progress CockroachDB upgrade or rollback.

Expand All @@ -84,7 +102,7 @@ Required:
Optional:

- `node_count` (Number) Number of nodes in the region. Will always be 0 for serverless clusters.
- `primary` (Boolean) 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.
- `primary` (Boolean) 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.

Read-Only:

Expand Down Expand Up @@ -114,7 +132,10 @@ Read-Only:

Optional:

- `spend_limit` (Number) Spend limit in US cents.
- `spend_limit` (Number, Deprecated) Spend limit in US cents.
- `upgrade_type` (String) Dictates the behavior of cockroach major version upgrades. If plan type is 'BASIC', this attribute must be left empty or set to 'AUTOMATIC'. Allowed values are:
* MANUAL
* AUTOMATIC
- `usage_limits` (Attributes) (see [below for nested schema](#nestedatt--serverless--usage_limits))

Read-Only:
Expand All @@ -124,7 +145,8 @@ Read-Only:
<a id="nestedatt--serverless--usage_limits"></a>
### Nested Schema for `serverless.usage_limits`

Required:
Optional:

- `provisioned_virtual_cpus` (Number) Maximum number of vCPUs that the cluster can use.
- `request_unit_limit` (Number) Maximum number of Request Units that the cluster can consume during the month.
- `storage_mib_limit` (Number) Maximum amount of storage (in MiB) that the cluster can have at any time during the month.
2 changes: 1 addition & 1 deletion docs/resources/cmek.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Required:
Optional:

- `node_count` (Number) Number of nodes in the region. Will always be 0 for serverless clusters.
- `primary` (Boolean) 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.
- `primary` (Boolean) 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.

Read-Only:

Expand Down
30 changes: 24 additions & 6 deletions examples/resources/cockroach_cluster/resource.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
resource "cockroach_cluster" "dedicated" {
name = "cockroach-dedicated"
resource "cockroach_cluster" "advanced" {
name = "cockroach-advanced"
cloud_provider = "GCP"
plan = "ADVANCED"
dedicated = {
storage_gib = 15
machine_type = "n1-standard-4"
machine_type = "n2-standard-4"
}
regions = [
{
Expand All @@ -14,11 +15,15 @@ resource "cockroach_cluster" "dedicated" {
delete_protection = true
}

resource "cockroach_cluster" "serverless" {
name = "cockroach-serverless"
resource "cockroach_cluster" "standard" {
name = "cockroach-standard"
cloud_provider = "GCP"
plan = "STANDARD"
serverless = {
spend_limit = 1
usage_limits = {
provisioned_virtual_cpus = 2
}
upgrade_type = "AUTOMATIC"
}
regions = [
{
Expand All @@ -27,3 +32,16 @@ resource "cockroach_cluster" "serverless" {
]
delete_protection = false
}

resource "cockroach_cluster" "basic" {
name = "cockroach-basic"
cloud_provider = "GCP"
plan = "BASIC"
serverless = {}
regions = [
{
name = "us-east1"
}
]
delete_protection = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ provider "cockroach" {
resource "cockroach_cluster" "example" {
name = var.cluster_name
cloud_provider = var.cloud_provider
plan = "ADVANCED"
dedicated = {
storage_gib = var.storage_gib
num_virtual_cpus = var.num_virtual_cpus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ variable "sql_user_password" {
sensitive = true
}

variable "serverless_spend_limit" {
type = number
nullable = false
default = 0
}

variable "cloud_provider" {
type = string
nullable = false
Expand All @@ -51,10 +45,9 @@ provider "cockroach" {
resource "cockroach_cluster" "example" {
name = var.cluster_name
cloud_provider = var.cloud_provider
serverless = {
spend_limit = var.serverless_spend_limit
}
regions = [for r in var.cloud_provider_regions : { name = r }]
plan = "BASIC"
serverless = {}
regions = [for r in var.cloud_provider_regions : { name = r }]
}

resource "cockroach_sql_user" "example" {
Expand Down
2 changes: 1 addition & 1 deletion examples/workflows/cockroach_client_ca_cert/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable "storage_gib" {
variable "machine_type" {
type = string
nullable = false
default = "n1-standard-2"
default = "n2-standard-2"
}

terraform {
Expand Down
9 changes: 6 additions & 3 deletions examples/workflows/cockroach_folder/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ variable "cluster_name" {
nullable = false
}

variable "serverless_spend_limit" {
variable "provisioned_virtual_cpus" {
type = number
nullable = false
default = 0
default = 2
}

variable "cloud_provider" {
Expand Down Expand Up @@ -73,8 +73,11 @@ resource "cockroach_user_role_grant" "cluster_creator_grant" {
resource "cockroach_cluster" "example" {
name = var.cluster_name
cloud_provider = var.cloud_provider
plan = "STANDARD"
serverless = {
spend_limit = var.serverless_spend_limit
usage_limits = {
provisioned_virtual_cpus = var.provisioned_virtual_cpus
}
}
regions = [for r in var.cloud_provider_regions : { name = r }]
parent_id = cockroach_folder.example_folder_parent.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ variable "storage_gib" {
variable "machine_type" {
type = string
nullable = false
default = "n1-standard-2"
default = "n2-standard-2"
}

variable "iam_role_id" {
Expand Down
2 changes: 1 addition & 1 deletion examples/workflows/cockroach_metric_export/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ variable "storage_gib" {
variable "machine_type" {
type = string
nullable = false
default = "n1-standard-2"
default = "n2-standard-2"
}

variable "gcp_region" {
Expand Down
Loading
Loading