Skip to content

Commit 1dd681e

Browse files
authored
Hydra (#213)
1 parent 18b187e commit 1dd681e

File tree

12 files changed

+279
-54
lines changed

12 files changed

+279
-54
lines changed

docs/resources/service.md

+10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ page_title: "clickhouse_service Resource - clickhouse"
44
subcategory: ""
55
description: |-
66
You can use the clickhouse_service resource to deploy ClickHouse cloud instances on supported cloud providers.
7+
Known limitations:
8+
If you create a service with warehouse_id set and then remove warehouse_id attribute completely, the provider won't detect the change. If you want to make a secondary service become primary, remove the warehouse_id and taint it before applying.If you create a service with readonly flag set to true and then remove readonly flag completely, the provider won't detect the change. If you want to make a secondary service read write, explicitly set the readonly flag to false.
79
---
810

911
# clickhouse_service (Resource)
1012

1113
You can use the *clickhouse_service* resource to deploy ClickHouse cloud instances on supported cloud providers.
1214

15+
Known limitations:
16+
17+
- If you create a service with `warehouse_id` set and then remove `warehouse_id` attribute completely, the provider won't detect the change. If you want to make a secondary service become primary, remove the `warehouse_id` and taint it before applying.
18+
- If you create a service with `readonly` flag set to true and then remove `readonly` flag completely, the provider won't detect the change. If you want to make a secondary service read write, explicitly set the `readonly` flag to false.
19+
1320
## Example Usage
1421

1522
```terraform
@@ -62,13 +69,16 @@ resource "clickhouse_service" "service" {
6269
- `num_replicas` (Number) Number of replicas for the service. Available only for 'production' services. Must be between 3 and 20. Contact support to enable this feature.
6370
- `password` (String, Sensitive) Password for the default user. One of either `password` or `password_hash` must be specified.
6471
- `password_hash` (String, Sensitive) SHA256 hash of password for the default user. One of either `password` or `password_hash` must be specified.
72+
- `readonly` (Boolean) Indicates if this service should be read only. Only allowed for secondary services, those which share data with another service (i.e. when `warehouse_id` field is set).
6573
- `release_channel` (String) Release channel to use for this service. Either 'default' or 'fast'. Only supported on 'production' services. Switching from 'fast' to 'default' release channel is not supported.
74+
- `warehouse_id` (String) ID of the warehouse to share the data with. Must be in the same cloud and region.
6675

6776
### Read-Only
6877

6978
- `endpoints` (Attributes List) List of public endpoints. (see [below for nested schema](#nestedatt--endpoints))
7079
- `iam_role` (String) IAM role used for accessing objects in s3.
7180
- `id` (String) ID of the created service. Generated by ClickHouse Cloud.
81+
- `is_primary` (Boolean) If true, it indicates this is a primary service using its own data. If false it means this service is a secondary service, thus using data from a warehouse.
7282
- `private_endpoint_config` (Attributes) Service config for private endpoints (see [below for nested schema](#nestedatt--private_endpoint_config))
7383

7484
<a id="nestedatt--ip_access"></a>

examples/full/warehouse/aws/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## AWS Compute-Compute separation example
2+
3+
The Terraform code deploys following resources:
4+
- 1 ClickHouse service on AWS meant to be the primary service of a data warehouse
5+
- 1 ClickHouse service on AWS meant to be the secondary service in the same data warehouse
6+
7+
The ClickHouse services will be reachable from anywhere on the internet.
8+
9+
## How to run
10+
11+
- Rename `variables.tfvars.sample` to `variables.tfvars` and fill in all needed data.
12+
- Run `terraform init`
13+
- Run `terraform <plan|apply> -var-file=variables.tfvars`

examples/full/warehouse/aws/main.tf

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
variable "organization_id" {
2+
type = string
3+
}
4+
5+
variable "token_key" {
6+
type = string
7+
}
8+
9+
variable "token_secret" {
10+
type = string
11+
}
12+
13+
variable "service_name" {
14+
type = string
15+
default = "My Data Warehouse"
16+
}
17+
18+
variable "region" {
19+
type = string
20+
default = "us-east-2"
21+
}
22+
23+
resource "clickhouse_service" "primary" {
24+
name = "${var.service_name}-primary"
25+
cloud_provider = "aws"
26+
region = var.region
27+
tier = "production"
28+
num_replicas = 3
29+
idle_scaling = false
30+
idle_timeout_minutes = null
31+
password_hash = "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=" # base64 encoded sha256 hash of "test"
32+
33+
ip_access = [
34+
{
35+
source = "0.0.0.0"
36+
description = "Anywhere"
37+
}
38+
]
39+
40+
min_replica_memory_gb = 8
41+
max_replica_memory_gb = 120
42+
43+
backup_configuration = {
44+
backup_period_in_hours = 24
45+
backup_retention_period_in_hours = 24
46+
backup_start_time = null
47+
}
48+
}
49+
50+
resource "clickhouse_service" "secondary" {
51+
warehouse_id = clickhouse_service.primary.warehouse_id
52+
readonly = true
53+
name = "${var.service_name}-secondary"
54+
cloud_provider = "aws"
55+
region = var.region
56+
tier = "production"
57+
num_replicas = 1
58+
idle_scaling = true
59+
idle_timeout_minutes = 5
60+
61+
ip_access = [
62+
{
63+
source = "0.0.0.0"
64+
description = "Anywhere"
65+
}
66+
]
67+
68+
min_replica_memory_gb = 8
69+
max_replica_memory_gb = 120
70+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file is generated automatically please do not edit
2+
terraform {
3+
required_providers {
4+
clickhouse = {
5+
version = "1.4.0"
6+
source = "ClickHouse/clickhouse"
7+
}
8+
}
9+
}
10+
11+
provider "clickhouse" {
12+
organization_id = var.organization_id
13+
token_key = var.token_key
14+
token_secret = var.token_secret
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
clickhouse = {
4+
version = "${CLICKHOUSE_TERRAFORM_PROVIDER_VERSION}"
5+
source = "ClickHouse/clickhouse"
6+
}
7+
}
8+
}
9+
10+
provider "clickhouse" {
11+
organization_id = var.organization_id
12+
token_key = var.token_key
13+
token_secret = var.token_secret
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# these keys are for example only and won't work when pointed to a deployed ClickHouse OpenAPI server
2+
organization_id = "aee076c1-3f83-4637-95b1-ad5a0a825b71"
3+
token_key = "avhj1U5QCdWAE9CA9"
4+
token_secret = "4b1dROiHQEuSXJHlV8zHFd0S7WQj7CGxz5kGJeJnca"

pkg/internal/api/models.go

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type ServiceManagedEncryption struct {
3333
type Service struct {
3434
Id string `json:"id,omitempty"`
3535
BYOCId *string `json:"byocId,omitempty"`
36+
DataWarehouseId *string `json:"dataWarehouseId,omitempty"`
37+
IsPrimary *bool `json:"isPrimary,omitempty"`
38+
ReadOnly bool `json:"isReadonly"`
3639
Name string `json:"name"`
3740
Provider string `json:"provider"`
3841
Region string `json:"region"`

pkg/resource/descriptions/service.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
You can use the *clickhouse_service* resource to deploy ClickHouse cloud instances on supported cloud providers.
2+
3+
Known limitations:
4+
5+
- If you create a service with `warehouse_id` set and then remove `warehouse_id` attribute completely, the provider won't detect the change. If you want to make a secondary service become primary, remove the `warehouse_id` and taint it before applying.
6+
- If you create a service with `readonly` flag set to true and then remove `readonly` flag completely, the provider won't detect the change. If you want to make a secondary service read write, explicitly set the `readonly` flag to false.

pkg/resource/models/service_resource.go

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func (b BackupConfiguration) ObjectValue() basetypes.ObjectValue {
9999
type ServiceResourceModel struct {
100100
ID types.String `tfsdk:"id"`
101101
BYOCID types.String `tfsdk:"byoc_id"`
102+
DataWarehouseID types.String `tfsdk:"warehouse_id"`
103+
IsPrimary types.Bool `tfsdk:"is_primary"`
104+
ReadOnly types.Bool `tfsdk:"readonly"`
102105
Name types.String `tfsdk:"name"`
103106
Password types.String `tfsdk:"password"`
104107
PasswordHash types.String `tfsdk:"password_hash"`
@@ -126,6 +129,9 @@ type ServiceResourceModel struct {
126129
func (m *ServiceResourceModel) Equals(b ServiceResourceModel) bool {
127130
if !m.ID.Equal(b.ID) ||
128131
!m.BYOCID.Equal(b.BYOCID) ||
132+
!m.DataWarehouseID.Equal(b.DataWarehouseID) ||
133+
!m.ReadOnly.Equal(b.ReadOnly) ||
134+
!m.IsPrimary.Equal(b.IsPrimary) ||
129135
!m.Name.Equal(b.Name) ||
130136
!m.Password.Equal(b.Password) ||
131137
!m.PasswordHash.Equal(b.PasswordHash) ||

pkg/resource/models/service_resource_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ func TestServiceResource_Equals(t *testing.T) {
4343
}).Get(),
4444
want: false,
4545
},
46+
{
47+
name: "Data Warehouse ID changed",
48+
a: base,
49+
b: test.NewUpdater(base).Update(func(src *ServiceResourceModel) {
50+
src.DataWarehouseID = types.StringValue("changed")
51+
}).Get(),
52+
want: false,
53+
},
54+
{
55+
name: "Readonly changed",
56+
a: base,
57+
b: test.NewUpdater(base).Update(func(src *ServiceResourceModel) {
58+
src.ReadOnly = types.BoolValue(true)
59+
}).Get(),
60+
want: false,
61+
},
62+
{
63+
name: "Is primary changed",
64+
a: base,
65+
b: test.NewUpdater(base).Update(func(src *ServiceResourceModel) {
66+
src.IsPrimary = types.BoolValue(true)
67+
}).Get(),
68+
want: false,
69+
},
4670
{
4771
name: "Name changed",
4872
a: base,
@@ -246,6 +270,9 @@ func getBaseModel() ServiceResourceModel {
246270
state := ServiceResourceModel{
247271
ID: types.StringValue(uuid),
248272
BYOCID: types.StringNull(),
273+
DataWarehouseID: types.StringNull(),
274+
ReadOnly: types.BoolValue(false),
275+
IsPrimary: types.BoolValue(false),
249276
Name: types.StringValue(""),
250277
Password: types.String{},
251278
PasswordHash: types.String{},

0 commit comments

Comments
 (0)