Skip to content

Commit 54aaeef

Browse files
committed
CHINA-495: Add custom TLS certificate for clickhouse
1 parent 78ad5b8 commit 54aaeef

File tree

8 files changed

+290
-9
lines changed

8 files changed

+290
-9
lines changed

docs/data-sources/clickhouse.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Clickhouse data source
2828

2929
- `cloud_type` (String) Cloud provider (`aws`, `gcp`, or `azure`)
3030
- `connection_info` (Attributes) Public connection info (see [below for nested schema](#nestedatt--connection_info))
31+
- `custom_certificate` (Attributes) Custom TLS certificate (see [below for nested schema](#nestedatt--custom_certificate))
3132
- `description` (String) Cluster description
3233
- `private_connection_info` (Attributes) Private connection info (see [below for nested schema](#nestedatt--private_connection_info))
3334
- `region_id` (String) Region where the cluster is located
@@ -49,6 +50,16 @@ Read-Only:
4950
- `user` (String) ClickHouse user
5051

5152

53+
<a id="nestedatt--custom_certificate"></a>
54+
### Nested Schema for `custom_certificate`
55+
56+
Read-Only:
57+
58+
- `certificate` (String) Public certificate
59+
- `key` (String) Private certificate key
60+
- `root_ca` (String) Root certificate
61+
62+
5263
<a id="nestedatt--private_connection_info"></a>
5364
### Nested Schema for `private_connection_info`
5465

docs/resources/clickhouse_cluster.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ resource "doublecloud_clickhouse_cluster" "example-clickhouse" {
6060

6161
- `access` (Block, Optional) Access control configuration (see [below for nested schema](#nestedblock--access))
6262
- `config` (Block, Optional) (see [below for nested schema](#nestedblock--config))
63+
- `custom_certificate` (Block, Optional) Custom TLS certificate (see [below for nested schema](#nestedblock--custom_certificate))
6364
- `description` (String) Cluster description
6465
- `id` (String) Cluster ID
6566
- `resources` (Block, Optional) Cluster resources (see [below for nested schema](#nestedblock--resources))
@@ -179,6 +180,16 @@ Optional:
179180

180181

181182

183+
<a id="nestedblock--custom_certificate"></a>
184+
### Nested Schema for `custom_certificate`
185+
186+
Optional:
187+
188+
- `certificate` (String) Public certificate
189+
- `key` (String) Private certificate key
190+
- `root_ca` (String) Root certificate
191+
192+
182193
<a id="nestedblock--resources"></a>
183194
### Nested Schema for `resources`
184195

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
github.com/cloudflare/circl v1.3.7 // indirect
3636
github.com/davecgh/go-spew v1.1.1 // indirect
3737
github.com/fatih/color v1.16.0 // indirect
38+
github.com/gogo/protobuf v1.3.2 // indirect
3839
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
3940
github.com/google/go-cmp v0.6.0 // indirect
4041
github.com/hashicorp/cli v1.1.6 // indirect

go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZt
6565
github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
6666
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
6767
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
68+
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
69+
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
6870
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
6971
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
7072
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
@@ -146,6 +148,8 @@ github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgf
146148
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
147149
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
148150
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
151+
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
152+
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
149153
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
150154
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
151155
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
@@ -214,6 +218,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
214218
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
215219
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
216220
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
221+
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
222+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
217223
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
218224
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
219225
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
@@ -224,30 +230,40 @@ github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgr
224230
go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw=
225231
go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU=
226232
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
233+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
234+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
227235
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
228236
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
229237
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
230238
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
231239
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
232240
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
241+
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
242+
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
233243
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
234244
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
235245
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
236246
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
237247
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
248+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
249+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
238250
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
239251
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
240252
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
241253
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
242254
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
243255
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
244256
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
257+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
258+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
245259
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
246260
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
247261
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
248262
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
263+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
249264
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
250265
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
266+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
251267
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
252268
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
253269
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -273,11 +289,15 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
273289
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
274290
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
275291
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
292+
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
293+
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
276294
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
277295
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
278296
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
279297
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
298+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
280299
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
300+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
281301
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
282302
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
283303
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=

internal/provider/clickhouse_cluster_resource.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"time"
88

9+
"github.com/golang/protobuf/ptypes/wrappers"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
1011
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
1112

@@ -49,6 +50,8 @@ type clickhouseClusterModel struct {
4950
// TODO: support mw
5051
// https://github.com/doublecloud/api/blob/main/doublecloud/v1/maintenance.proto
5152
// MaintenanceWindow *maintenanceWindow `tfsdk:"maintenance_window"`
53+
54+
CustomCertificate types.Object `tfsdk:"custom_certificate"`
5255
}
5356

5457
type clickhouseClusterResources struct {
@@ -350,6 +353,26 @@ func clickhouseConenctionInfoSchema() map[string]schema.Attribute {
350353
}
351354
}
352355

356+
func clickhouseCustomCertificateSchema() map[string]schema.Attribute {
357+
return map[string]schema.Attribute{
358+
"certificate": schema.StringAttribute{
359+
Optional: true,
360+
MarkdownDescription: "Public certificate",
361+
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
362+
},
363+
"key": schema.StringAttribute{
364+
Optional: true,
365+
MarkdownDescription: "Private certificate key",
366+
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
367+
},
368+
"root_ca": schema.StringAttribute{
369+
Optional: true,
370+
MarkdownDescription: "Root certificate",
371+
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
372+
},
373+
}
374+
}
375+
353376
func (r *ClickhouseClusterResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
354377
resp.Schema = schema.Schema{
355378
// This description is used by the documentation generator and the language server.
@@ -493,6 +516,12 @@ func (r *ClickhouseClusterResource) Schema(ctx context.Context, req resource.Sch
493516
"access": AccessSchemaBlock(),
494517
"config": clickhouseConfigSchemaBlock(),
495518
// maintenance window
519+
"custom_certificate": schema.SingleNestedBlock{
520+
Attributes: clickhouseCustomCertificateSchema(),
521+
PlanModifiers: []planmodifier.Object{objectplanmodifier.UseStateForUnknown()},
522+
MarkdownDescription: "Custom TLS certificate",
523+
Validators: []validator.Object{&clickhouseCustomCertificateValidator{}},
524+
},
496525
},
497526
}
498527
}
@@ -643,6 +672,21 @@ func updateClickhouseCluster(m *clickhouseClusterModel) (*clickhouse.UpdateClust
643672
rq.Access = access
644673
}
645674

675+
cc := m.CustomCertificate.Attributes()
676+
rq.CustomCertificate = &clickhouse.CustomCertificate{
677+
Enabled: false,
678+
}
679+
certificate, certOk := cc["certificate"]
680+
key, keyOk := cc["key"]
681+
rq.CustomCertificate.Enabled = certOk && keyOk
682+
if rq.CustomCertificate.Enabled {
683+
rq.CustomCertificate.Certificate = &wrappers.BytesValue{Value: []byte(certificate.(types.String).ValueString())}
684+
rq.CustomCertificate.Key = &wrappers.BytesValue{Value: []byte(key.(types.String).ValueString())}
685+
if rootCa, ok := cc["root_ca"]; ok {
686+
rq.CustomCertificate.RootCa = &wrappers.BytesValue{Value: []byte(rootCa.(types.String).ValueString())}
687+
}
688+
}
689+
646690
return rq, diags
647691
}
648692

@@ -734,6 +778,12 @@ func (m *clickhouseClusterModel) parse(rs *clickhouse.Cluster) diag.Diagnostics
734778
diags.Append(m.Access.parse(access)...)
735779
}
736780

781+
oldKey := ""
782+
if key, ok := m.CustomCertificate.Attributes()["key"]; ok {
783+
oldKey = key.String()
784+
}
785+
m.CustomCertificate = parseClickhouseCustomCertificate(rs.GetCustomCertificate(), oldKey).convert(diags)
786+
737787
// parse MW
738788
return diags
739789
}

internal/provider/clickhouse_cluster_resource_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,48 @@ import (
1010
"text/template"
1111

1212
"github.com/doublecloud/go-genproto/doublecloud/clickhouse/v1"
13+
"github.com/hashicorp/terraform-plugin-framework/attr"
1314
"github.com/hashicorp/terraform-plugin-framework/types"
1415
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1516
)
1617

1718
var (
1819
testAccClickhouseName string = fmt.Sprintf("%v-clickhouse", testPrefix)
1920
testAccClickhouseId string = fmt.Sprintf("doublecloud_clickhouse_cluster.%v", testAccClickhouseName)
21+
22+
testAccClickhouseTLSCert string = `
23+
-----BEGIN PUBLIC KEY-----
24+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEcKT/wmDt+qLwEVOfU0UbJO5f77+0
25+
nuYermx15MOZh4jg4H/r98b/tD2dNxdLAW/VJ4VTF3vD0AGY2+xN7J8aTA==
26+
-----END PUBLIC KEY-----
27+
`
28+
29+
testAccClickhouseTLSKey string = `
30+
-----BEGIN CERTIFICATE-----
31+
MIICoTCCAkegAwIBAgIUWdVSBHIWp+w6Gtmt4Ps+RNgky00wCgYIKoZIzj0EAwIw
32+
gacxCzAJBgNVBAYTAkRFMRIwEAYDVQQIDAlGcmFua2Z1cnQxEjAQBgNVBAcMCUZy
33+
YW5rZnVydDEVMBMGA1UECgwMZG91YmxlLmNsb3VkMSAwHgYDVQQLDBdUZXJyYWZv
34+
cm0gcHJvdmlkZXIgdGVzdDEVMBMGA1UEAwwMZG91YmxlLmNsb3VkMSAwHgYJKoZI
35+
hvcNAQkBFhFpbmZvQGRvdWJsZS5jbG91ZDAeFw0yNDA5MTkxNjE5MDNaFw0yNTA5
36+
MTkxNjE5MDNaMIG0MQswCQYDVQQGEwJERTESMBAGA1UECAwJRnJhbmtmdXJ0MRIw
37+
EAYDVQQHDAlGcmFua2Z1cnQxFTATBgNVBAoMDGRvdWJsZS5jbG91ZDElMCMGA1UE
38+
CwwcVGVycmFmb3JtIHByb3ZpZGVyIHRlc3QgaW1wbDEdMBsGA1UEAwwUdGVzdC5h
39+
dC5kb3VibGUuY2xvdWQxIDAeBgkqhkiG9w0BCQEWEWluZm9AZG91YmxlLmNsb3Vk
40+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEcKT/wmDt+qLwEVOfU0UbJO5f77+0
41+
nuYermx15MOZh4jg4H/r98b/tD2dNxdLAW/VJ4VTF3vD0AGY2+xN7J8aTKNCMEAw
42+
HQYDVR0OBBYEFElk8x4Sw1IYKahZDqAKrbPrMQvaMB8GA1UdIwQYMBaAFC/+xZgT
43+
4U3lxhcG2wdT5/NlGB7cMAoGCCqGSM49BAMCA0gAMEUCIBWS0StXMJCfOHU6UqKK
44+
PB+UYxG5mwIw4IP/T7sLa3XlAiEAyS8vLtbgrh8mLXwacAe/SFRS3L/DhOJQa+0e
45+
VQBbsVs=
46+
-----END CERTIFICATE-----
47+
`
48+
49+
testAccClickhouseTLSRootCA string = `
50+
-----BEGIN PUBLIC KEY-----
51+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2fZnlTyuGtgATXh0FmgvgsqTI/aB
52+
Wy2sRShP40UqdTQ4pxLkpkskb7RWssyrXZEiieGSIUY33setFOOMV6b4RA==
53+
-----END PUBLIC KEY-----
54+
`
2055
)
2156

2257
func TestAccClickhouseClusterResource(t *testing.T) {
@@ -27,6 +62,7 @@ func TestAccClickhouseClusterResource(t *testing.T) {
2762
RegionId: types.StringValue("eu-central-1"),
2863
CloudType: types.StringValue("aws"),
2964
NetworkId: types.StringValue(testNetworkId),
65+
Version: types.StringValue("24.8"),
3066
Resources: &clickhouseClusterResources{
3167
Clickhouse: &clickhouseClusterResourcesClickhouse{
3268
ResourcePresetId: types.StringValue("g2-c2-m8"),
@@ -84,6 +120,20 @@ func TestAccClickhouseClusterResource(t *testing.T) {
84120
},
85121
}
86122

123+
m4 := m3
124+
cc, _ := types.ObjectValue(map[string]attr.Type{
125+
"certificate": types.StringType,
126+
"key": types.StringType,
127+
"root_ca": types.StringType,
128+
},
129+
map[string]attr.Value{
130+
"certificate": types.StringValue(testAccClickhouseTLSCert),
131+
"key": types.StringValue(testAccClickhouseTLSKey),
132+
"root_ca": types.StringValue(testAccClickhouseTLSRootCA),
133+
},
134+
)
135+
m4.CustomCertificate = cc
136+
87137
resource.Test(t, resource.TestCase{
88138
PreCheck: func() { testAccPreCheck(t) },
89139
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
@@ -140,6 +190,16 @@ func TestAccClickhouseClusterResource(t *testing.T) {
140190
resource.TestCheckResourceAttr(testAccClickhouseId, "resources.clickhouse.max_disk_size", "68719476736"),
141191
),
142192
},
193+
// Check custom TLS certificate
194+
{
195+
Config: convertClickHouseModelToHCL(&m4),
196+
Check: resource.ComposeAggregateTestCheckFunc(
197+
resource.TestCheckNoResourceAttr(testAccClickhouseId, "resources.clickhouse.resource_preset_id"),
198+
resource.TestCheckResourceAttr(testAccClickhouseId, "resources.clickhouse.custom_certificate.certificate", testAccClickhouseTLSCert),
199+
resource.TestCheckResourceAttr(testAccClickhouseId, "resources.clickhouse.custom_certificate.key", testAccClickhouseTLSKey),
200+
resource.TestCheckResourceAttr(testAccClickhouseId, "resources.clickhouse.custom_certificate.root_ca", testAccClickhouseTLSRootCA),
201+
),
202+
},
143203
// Delete testing automatically occurs in TestCase
144204
},
145205
})
@@ -213,6 +273,8 @@ resource "doublecloud_clickhouse_cluster" "tf-acc-clickhouse" {
213273
region_id = "{{ .RegionId.ValueString }}"
214274
cloud_type = "{{ .CloudType.ValueString }}"
215275
network_id = "{{ .NetworkId.ValueString }}"
276+
{{- if not .Version.IsNull }}
277+
version = "{{ .Version.ValueString }}"{{end}}
216278
217279
resources {
218280
clickhouse {
@@ -277,6 +339,13 @@ resource "doublecloud_clickhouse_cluster" "tf-acc-clickhouse" {
277339
]
278340
{{- end}}
279341
}
342+
{{- if not .CustomCertificate.IsNull }}
343+
custom_certificate {
344+
certificate = {{ .CustomCertificate.Attributes.certificate }}
345+
key = {{ .CustomCertificate.Attributes.key }}
346+
root_ca = {{ .CustomCertificate.Attributes.root_ca }}
347+
}
348+
{{- end}}
280349
}`
281350

282351
var clickhouseHCLTemplate *template.Template

0 commit comments

Comments
 (0)