Skip to content

Commit

Permalink
update examples for Cloud 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-kimball authored and fantapop committed Sep 4, 2024
1 parent c6b9b49 commit a8e4a4e
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 13 deletions.
24 changes: 19 additions & 5 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ 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,8 +30,8 @@ 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 = {
Expand All @@ -45,6 +46,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 Down
24 changes: 19 additions & 5 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,8 +15,8 @@ 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 = {
Expand All @@ -30,3 +31,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
87 changes: 87 additions & 0 deletions examples/workflows/cockroach_basic_cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
variable "cluster_name" {
type = string
nullable = false
}

variable "sql_user_name" {
type = string
nullable = false
default = "maxroach"
}

# Remember that even variables marked sensitive will show up
# in the Terraform state file. Always follow best practices
# when managing sensitive info.
# https://developer.hashicorp.com/terraform/tutorials/configuration-language/sensitive-variables#sensitive-values-in-state
variable "sql_user_password" {
type = string
nullable = false
sensitive = true
}

variable "cloud_provider" {
type = string
nullable = false
default = "GCP"
}

variable "cloud_provider_regions" {
type = list(string)
nullable = false
default = ["us-central1"]
}

terraform {
required_providers {
cockroach = {
source = "cockroachdb/cockroach"
}
}
}
provider "cockroach" {
# export COCKROACH_API_KEY with the cockroach cloud API Key
}

resource "cockroach_cluster" "example" {
name = var.cluster_name
cloud_provider = var.cloud_provider
plan = "BASIC"
serverless = {}
regions = [for r in var.cloud_provider_regions : { name = r }]
}

resource "cockroach_sql_user" "example" {
name = var.sql_user_name
password = var.sql_user_password
cluster_id = cockroach_cluster.example.id
}

resource "cockroach_database" "example" {
name = "example-database"
cluster_id = cockroach_cluster.example.id
}

resource "cockroach_service_account" "example_scoped_sa" {
name = "example-scoped-service-account"
description = "A service account providing limited read access to single cluster."
}

resource "cockroach_user_role_grant" "example_limited_access_scoped_grant" {
user_id = cockroach_service_account.example_scoped_sa.id
role = {
role_name = "CLUSTER_OPERATOR_WRITER",
resource_type = "CLUSTER",
resource_id = cockroach_cluster.example.id
}
}

resource "cockroach_api_key" "example_cluster_op_key_v1" {
name = "example-cluster-operator-key-v1"
service_account_id = cockroach_service_account.example_scoped_sa.id
}

output "example_cluster_op_key_v1_secret" {
value = cockroach_api_key.example_cluster_op_key_v1.secret
description = "The api key for example_cluster_op_key_v1_secret"
sensitive = true
}
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
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

0 comments on commit a8e4a4e

Please sign in to comment.