Skip to content

Commit 17e016d

Browse files
committed
Add kafka_connect_v2 resource tests and documentation
1 parent 62fc4ab commit 17e016d

File tree

11 files changed

+495
-113
lines changed

11 files changed

+495
-113
lines changed

docs/resources/kafka_connect_v2.md

+221
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
page_title: "Conduktor : conduktor_kafka_connect_v2 "
3+
subcategory: "console/v2"
4+
description: |-
5+
Resource for managing Conduktor Kafka Connect servers definition linked to an existing Kafka cluster inside Console.
6+
This resource allows you to create, read, update and delete Kafka Connect servers in Conduktor.
7+
---
8+
9+
# conduktor_kafka_connect_v2
10+
11+
Resource for managing Conduktor Kafka connect servers definition linked to an existing Kafka cluster inside Console.
12+
This resource allows you to create, read, update and delete Kafka Connect servers in Conduktor.
13+
14+
## Example Usage
15+
16+
### Simple Kafka Connect server
17+
This example creates a simple Kafka Connect server without any authentication.
18+
```terraform
19+
resource "conduktor_kafka_cluster_v2" "minimal" {
20+
name = "mini-cluster"
21+
spec {
22+
display_name = "Minimal Cluster"
23+
bootstrap_servers = "localhost:9092"
24+
}
25+
}
26+
27+
resource "conduktor_kafka_connect_v2" "simple" {
28+
name = "simple-connect"
29+
cluster = conduktor_kafka_cluster_v2.minimal.name
30+
spec {
31+
display_name = "Simple Connect Server"
32+
urls = "http://localhost:8083"
33+
}
34+
}
35+
```
36+
37+
### Basic Kafka Connect server
38+
This example creates a complex Kafka Connect server with basic authentication.
39+
```terraform
40+
resource "conduktor_kafka_cluster_v2" "minimal" {
41+
name = "mini-cluster"
42+
spec {
43+
display_name = "Minimal Cluster"
44+
bootstrap_servers = "localhost:9092"
45+
}
46+
}
47+
48+
resource "conduktor_kafka_connect_v2" "basic" {
49+
name = "basic-connect"
50+
cluster = conduktor_kafka_cluster_v2.minimal.name
51+
labels = {
52+
description = "This is a complex connect using basic authentication"
53+
documentation = "https://docs.mycompany.com/complex-connect"
54+
env = "dev"
55+
}
56+
spec {
57+
display_name = "Basic Connect server"
58+
urls = "http://localhost:8083"
59+
headers = {
60+
X-PROJECT-HEADER = "value"
61+
Cache-Control : "no-cache"
62+
}
63+
ignore_untrusted_certificate = false
64+
security = {
65+
type = "BasicAuth"
66+
username = "user"
67+
password = "password"
68+
}
69+
}
70+
}
71+
```
72+
73+
### Bearer token Kafka Connect server
74+
This example creates a complex Kafka Connect server with bearer token authentication.
75+
```terraform
76+
resource "conduktor_kafka_cluster_v2" "minimal" {
77+
name = "mini-cluster"
78+
spec {
79+
display_name = "Minimal Cluster"
80+
bootstrap_servers = "localhost:9092"
81+
}
82+
}
83+
84+
resource "conduktor_kafka_connect_v2" "bearer" {
85+
name = "bearer-connect"
86+
cluster = conduktor_kafka_cluster_v2.minimal.name
87+
labels = {
88+
description = "This is a complex connect using bearer token authentication"
89+
documentation = "https://docs.mycompany.com/complex-connect"
90+
env = "dev"
91+
}
92+
spec {
93+
display_name = "Bearer Connect server"
94+
urls = "http://localhost:8083"
95+
headers = {
96+
X-PROJECT-HEADER = "value"
97+
Cache-Control : "no-cache"
98+
}
99+
ignore_untrusted_certificate = false
100+
security = {
101+
type = "BearerToken"
102+
token = "token"
103+
}
104+
}
105+
}
106+
```
107+
108+
### mTLS Kafka Connect server
109+
This example creates a complex Kafka Connect server with mTLS authentication.
110+
```terraform
111+
resource "conduktor_kafka_cluster_v2" "minimal" {
112+
name = "mini-cluster"
113+
spec {
114+
display_name = "Minimal Cluster"
115+
bootstrap_servers = "localhost:9092"
116+
}
117+
}
118+
119+
resource "conduktor_kafka_connect_v2" "mtls" {
120+
name = "mtls-connect"
121+
cluster = conduktor_kafka_cluster_v2.minimal.name
122+
labels = {
123+
description = "This is a complex connect using mTLS authentication"
124+
documentation = "https://docs.mycompany.com/complex-connect"
125+
env = "dev"
126+
}
127+
spec {
128+
display_name = "mTLS Connect server"
129+
urls = "http://localhost:8083"
130+
headers = {
131+
X-PROJECT-HEADER = "value"
132+
Cache-Control : "no-cache"
133+
}
134+
ignore_untrusted_certificate = false
135+
security = {
136+
type = "SSLAuth"
137+
key = <<EOT
138+
-----BEGIN PRIVATE KEY-----
139+
MIIOXzCCDUegAwIBAgIRAPRytMVYJNUgCbhnA+eYumgwDQYJKoZIhvcNAQELBQAw
140+
...
141+
IFyCs+xkcgvHFtBjjel4pnIET0agtbGJbGDEQBNxX+i4MDA=
142+
-----END PRIVATE KEY-----
143+
EOT
144+
certificate_chain = <<EOT
145+
-----BEGIN CERTIFICATE-----
146+
MIIOXzCCDUegAwIBAgIRAPRytMVYJNUgCbhnA+eYumgwDQYJKoZIhvcNAQELBQAw
147+
...
148+
IFyCs+xkcgvHFtBjjel4pnIET0agtbGJbGDEQBNxX+i4MDA=
149+
-----END CERTIFICATE-----
150+
EOT
151+
}
152+
}
153+
}
154+
```
155+
156+
<!-- schema generated by tfplugindocs -->
157+
## Schema
158+
159+
### Required
160+
161+
- `cluster` (String) Kafka cluster name linked with Kafka current connect server. Must exist in Conduktor Console
162+
- `name` (String) Kafka connect server name, must be unique, act as ID for import
163+
164+
### Optional
165+
166+
- `labels` (Map of String) Kafka connect server labels
167+
- `spec` (Block, Optional) (see [below for nested schema](#nestedblock--spec))
168+
169+
<a id="nestedblock--spec"></a>
170+
### Nested Schema for `spec`
171+
172+
Required:
173+
174+
- `display_name` (String) Kafka connect server display name
175+
- `urls` (String) URL of a Kafka Connect cluster. **Multiple URLs are not supported for now**
176+
177+
Optional:
178+
179+
- `headers` (Map of String) Key-Value HTTP headers to add to requests
180+
- `ignore_untrusted_certificate` (Boolean) Ignore untrusted certificate for Kafka connect server requests
181+
- `security` (Attributes) Kafka connect server security configuration. One of `BasicAuth`, `BearerToken`, `SSLAuth` (see [below for nested schema](#nestedatt--spec--security))
182+
183+
<a id="nestedatt--spec--security"></a>
184+
### Nested Schema for `spec.security`
185+
186+
Required:
187+
188+
- `type` (String) Kafka connect server security type. Either `BasicAuth`, `BearerToken`, `SSLAuth`
189+
190+
More detail on our [documentation](https://docs.conduktor.io/platform/reference/resource-reference/console/#kafkaconnectcluster)
191+
192+
Optional:
193+
194+
- `certificate_chain` (String) Kafka connect server mTLS auth certificate chain PEM. Required if security type is `SSLAuth`
195+
- `key` (String, Sensitive) Kafka connect server mTLS auth private key PEM. Required if security type is `SSLAuth`
196+
- `password` (String, Sensitive) Kafka connect server basic auth password. Required if security type is `BasicAuth`
197+
- `token` (String, Sensitive) Kafka connect server bearer token. Required if security type is `BearerToken`
198+
- `username` (String) Kafka connect server basic auth username. Required if security type is `BasicAuth`
199+
200+
201+
202+
203+
204+
## Import
205+
206+
In order to import a Kafka Connect server into Conduktor, you need to know the Kafka cluster ID and the Kafka Connect server ID.
207+
208+
The import ID is constructed as follows: `< cluster_id >/< connect_id >`.
209+
210+
For example, using an [`import` block](https://developer.hashicorp.com/terraform/language/import) :
211+
```terraform
212+
import {
213+
to = conduktor_kafka_connect_v2.example
214+
id = "mini-cluster/import-connect" # Import "import-connect" Connect server for "mini-cluster" Kafka cluster
215+
}
216+
```
217+
218+
Using the `terraform import` command:
219+
```shell
220+
terraform import conduktor_kafka_connect_v2.example mini-cluster/import-connect
221+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resource "conduktor_kafka_cluster_v2" "minimal" {
2+
name = "mini-cluster"
3+
spec {
4+
display_name = "Minimal Cluster"
5+
bootstrap_servers = "localhost:9092"
6+
}
7+
}
8+
9+
resource "conduktor_kafka_connect_v2" "basic" {
10+
name = "basic-connect"
11+
cluster = conduktor_kafka_cluster_v2.minimal.name
12+
labels = {
13+
description = "This is a complex connect using basic authentication"
14+
documentation = "https://docs.mycompany.com/complex-connect"
15+
env = "dev"
16+
}
17+
spec {
18+
display_name = "Basic Connect server"
19+
urls = "http://localhost:8083"
20+
headers = {
21+
X-PROJECT-HEADER = "value"
22+
Cache-Control : "no-cache"
23+
}
24+
ignore_untrusted_certificate = false
25+
security = {
26+
type = "BasicAuth"
27+
username = "user"
28+
password = "password"
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
resource "conduktor_kafka_cluster_v2" "minimal" {
2+
name = "mini-cluster"
3+
spec {
4+
display_name = "Minimal Cluster"
5+
bootstrap_servers = "localhost:9092"
6+
}
7+
}
8+
9+
resource "conduktor_kafka_connect_v2" "bearer" {
10+
name = "bearer-connect"
11+
cluster = conduktor_kafka_cluster_v2.minimal.name
12+
labels = {
13+
description = "This is a complex connect using bearer token authentication"
14+
documentation = "https://docs.mycompany.com/complex-connect"
15+
env = "dev"
16+
}
17+
spec {
18+
display_name = "Bearer Connect server"
19+
urls = "http://localhost:8083"
20+
headers = {
21+
X-PROJECT-HEADER = "value"
22+
Cache-Control : "no-cache"
23+
}
24+
ignore_untrusted_certificate = false
25+
security = {
26+
type = "BearerToken"
27+
token = "token"
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {
2+
to = conduktor_kafka_connect_v2.example
3+
id = "mini-cluster/import-connect" # Import "import-connect" Connect server for "mini-cluster" Kafka cluster
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
resource "conduktor_kafka_cluster_v2" "minimal" {
2+
name = "mini-cluster"
3+
spec {
4+
display_name = "Minimal Cluster"
5+
bootstrap_servers = "localhost:9092"
6+
}
7+
}
8+
9+
resource "conduktor_kafka_connect_v2" "mtls" {
10+
name = "mtls-connect"
11+
cluster = conduktor_kafka_cluster_v2.minimal.name
12+
labels = {
13+
description = "This is a complex connect using mTLS authentication"
14+
documentation = "https://docs.mycompany.com/complex-connect"
15+
env = "dev"
16+
}
17+
spec {
18+
display_name = "mTLS Connect server"
19+
urls = "http://localhost:8083"
20+
headers = {
21+
X-PROJECT-HEADER = "value"
22+
Cache-Control : "no-cache"
23+
}
24+
ignore_untrusted_certificate = false
25+
security = {
26+
type = "SSLAuth"
27+
key = <<EOT
28+
-----BEGIN PRIVATE KEY-----
29+
MIIOXzCCDUegAwIBAgIRAPRytMVYJNUgCbhnA+eYumgwDQYJKoZIhvcNAQELBQAw
30+
...
31+
IFyCs+xkcgvHFtBjjel4pnIET0agtbGJbGDEQBNxX+i4MDA=
32+
-----END PRIVATE KEY-----
33+
EOT
34+
certificate_chain = <<EOT
35+
-----BEGIN CERTIFICATE-----
36+
MIIOXzCCDUegAwIBAgIRAPRytMVYJNUgCbhnA+eYumgwDQYJKoZIhvcNAQELBQAw
37+
...
38+
IFyCs+xkcgvHFtBjjel4pnIET0agtbGJbGDEQBNxX+i4MDA=
39+
-----END CERTIFICATE-----
40+
EOT
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "conduktor_kafka_cluster_v2" "minimal" {
2+
name = "mini-cluster"
3+
spec {
4+
display_name = "Minimal Cluster"
5+
bootstrap_servers = "localhost:9092"
6+
}
7+
}
8+
9+
resource "conduktor_kafka_connect_v2" "simple" {
10+
name = "simple-connect"
11+
cluster = conduktor_kafka_cluster_v2.minimal.name
12+
spec {
13+
display_name = "Simple Connect Server"
14+
urls = "http://localhost:8083"
15+
}
16+
}

internal/provider/kafka_connect_v2_resource.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-framework/resource"
1212
"github.com/hashicorp/terraform-plugin-log/tflog"
1313
jsoniter "github.com/json-iterator/go"
14+
"strings"
1415
)
1516

1617
func kafkaConnectV2ApiPutPath(cluster string) string {
@@ -215,5 +216,16 @@ func (r *KafkaConnectV2Resource) Delete(ctx context.Context, req resource.Delete
215216
}
216217

217218
func (r *KafkaConnectV2Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
218-
resource.ImportStatePassthroughID(ctx, path.Root("name"), req, resp)
219+
idParts := strings.Split(req.ID, "/")
220+
221+
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
222+
resp.Diagnostics.AddError(
223+
"Unexpected Import Identifier",
224+
fmt.Sprintf("Expected import identifier with format: cluster/name. Got: %q", req.ID),
225+
)
226+
return
227+
}
228+
229+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("cluster"), idParts[0])...)
230+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[1])...)
219231
}

0 commit comments

Comments
 (0)