Skip to content

Commit

Permalink
Add support for Kafka version configuration
Browse files Browse the repository at this point in the history
Fixes #329

Signed-off-by: Adrien Fillon <[email protected]>
  • Loading branch information
adrien-f authored and Mongey committed Mar 14, 2024
1 parent 246fe58 commit f2b86f5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 11 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ provider "kafka" {
sasl_aws_region = "us-east-1"
}
```
#### Compatibility with Redpanda

```hcl
provider "kafka" {
bootstrap_servers = ["localhost:9092"]
kafka_version = "2.1.0"
}
```

Due to Redpanda not implementing some Metadata APIs, we need to force the Kafka version to use when creating the provider.
>>>>>>> d9b1386 (Add support for Kafka version configuration)

| Property | Description | Default |
| ------------------- | --------------------------------------------------------------------------------------------------------------------- | ---------- |
Expand All @@ -109,6 +120,7 @@ provider "kafka" {
| `client_cert` | The client certificate or path to a file containing the client certificate in `PEM` format. Use for Client authentication to Kafka.<br>If you have Intermediate CA certificate(s) append them to `client_cert`.| `""` |
| `client_key` | The private key or path to a file containing the private key that the client certificate was issued for. | `""` |
| `client_key_passphrase` | The passphrase for the private key that the certificate was issued for. | `""` |
| `kafka_version` | The version of Kafka protocol to use in `$MAJOR.$MINOR.$PATCH` format. Some features may not be available on older versions. | `""` |
| `tls_enabled` | Enable communication with the Kafka Cluster over TLS. | `true` |
| `skip_tls_verify` | Skip TLS verification. | `false` |
| `sasl_username` | Username for SASL authentication. | `""` |
Expand Down
2 changes: 0 additions & 2 deletions docs/data-sources/topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ description: |-
- `id` (String) The ID of this resource.
- `partitions` (Number) Number of partitions.
- `replication_factor` (Number) Number of replicas.


1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ description: |-
- `client_key` (String) The private key that the certificate was issued for.
- `client_key_file` (String, Deprecated) Path to a file containing the private key that the certificate was issued for.
- `client_key_passphrase` (String) The passphrase for the private key that the certificate was issued for.
- `kafka_version` (String) The version of Kafka protocol to use in `$MAJOR.$MINOR.$PATCH` format. Some features may not be available on older versions.
- `sasl_mechanism` (String) SASL mechanism, can be plain, scram-sha512, scram-sha256, aws-iam
- `sasl_password` (String) Password for SASL authentication.
- `sasl_username` (String) Username for SASL authentication.
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/acl.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ description: |-
### Read-Only

- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/resources/quota.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@ description: |-
### Read-Only

- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/resources/topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ description: |-
### Read-Only

- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/resources/user_scram_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ description: |-
### Read-Only

- `id` (String) The ID of this resource.


14 changes: 13 additions & 1 deletion kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
ClientCert string
ClientCertKey string
ClientCertKeyPassphrase string
KafkaVersion string
TLSEnabled bool
SkipTLSVerify bool
SASLUsername string
Expand Down Expand Up @@ -95,7 +96,17 @@ func (c *Config) Token() (*sarama.AccessToken, error) {

func (c *Config) newKafkaConfig() (*sarama.Config, error) {
kafkaConfig := sarama.NewConfig()
kafkaConfig.Version = sarama.V2_7_0_0

if c.KafkaVersion != "" {
version, err := sarama.ParseKafkaVersion(c.KafkaVersion)
if err != nil {
return kafkaConfig, fmt.Errorf("error parsing kafka version '%s': %w", c.KafkaVersion, err)
}
kafkaConfig.Version = version
} else {
kafkaConfig.Version = sarama.V2_7_0_0
}

kafkaConfig.ClientID = "terraform-provider-kafka"
kafkaConfig.Admin.Timeout = time.Duration(c.Timeout) * time.Second
kafkaConfig.Metadata.Full = true // the default, but just being clear
Expand Down Expand Up @@ -275,6 +286,7 @@ func (config *Config) copyWithMaskedSensitiveValues() Config {
config.ClientCert,
"*****",
"*****",
config.KafkaVersion,
config.TLSEnabled,
config.SkipTLSVerify,
config.SASLUsername,
Expand Down
6 changes: 6 additions & 0 deletions kafka/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func Provider() *schema.Provider {
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAFKA_SASL_IAM_AWS_REGION", nil),
Description: "AWS region where MSK is deployed.",
"kafka_version": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAFKA_VERSION", "2.7.0"),
Description: "The version of Kafka protocol to use in `$MAJOR.$MINOR.$PATCH` format. Some features may not be available on older versions. Default is 2.7.0.",
},
"sasl_aws_role_arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -160,6 +165,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
ClientCert: d.Get("client_cert").(string),
ClientCertKey: d.Get("client_key").(string),
ClientCertKeyPassphrase: d.Get("client_key_passphrase").(string),
KafkaVersion: d.Get("kafka_version").(string),
SkipTLSVerify: d.Get("skip_tls_verify").(bool),
SASLAWSRegion: d.Get("sasl_aws_region").(string),
SASLUsername: d.Get("sasl_username").(string),
Expand Down

0 comments on commit f2b86f5

Please sign in to comment.