Skip to content

Commit

Permalink
Merge pull request #97 from askoriy/feat/connector-sensitive-config
Browse files Browse the repository at this point in the history
feat: Add config_sensitive parameter for sensitive connector config
  • Loading branch information
Mongey authored Aug 12, 2021
2 parents f0f313a + 73b354b commit 0328b5c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
17 changes: 16 additions & 1 deletion ccloud/resource_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func connectorResource() *schema.Resource {
Type: schema.TypeMap,
Required: true,
ForceNew: false,
Description: "Type-specific Configuration of cluster. String keys and values",
Description: "Type-specific Configuration of connector. String keys and values",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// ignore common auto-generated config fields
for _, ik := range ignoreConnectorConfigs() {
Expand All @@ -83,6 +83,13 @@ func connectorResource() *schema.Resource {
return false
},
},
"config_sensitive": {
Type: schema.TypeMap,
Optional: true,
ForceNew: false,
Sensitive: true,
Description: "Sensitive part of connector configuration. String keys and values",
},
},
}
}
Expand All @@ -92,6 +99,7 @@ func connectorUpdate(_ context.Context, d *schema.ResourceData, meta interface{}

name := d.Get("name").(string)
config := d.Get("config").(map[string]interface{})
configSensitive := d.Get("config_sensitive").(map[string]interface{})
accountID := d.Get("environment_id").(string)
clusterID := d.Get("cluster_id").(string)

Expand All @@ -100,6 +108,9 @@ func connectorUpdate(_ context.Context, d *schema.ResourceData, meta interface{}
for key, value := range config {
configStrings[key] = value.(string)
}
for key, value := range configSensitive {
configStrings[key] = value.(string)
}

_, err := c.UpdateConnectorConfig(accountID, clusterID, name, configStrings)
d.SetId(name)
Expand All @@ -118,6 +129,7 @@ func connectorCreate(ctx context.Context, d *schema.ResourceData, meta interface

name := d.Get("name").(string)
config := d.Get("config").(map[string]interface{})
configSensitive := d.Get("config_sensitive").(map[string]interface{})
accountID := d.Get("environment_id").(string)
clusterID := d.Get("cluster_id").(string)

Expand All @@ -126,6 +138,9 @@ func connectorCreate(ctx context.Context, d *schema.ResourceData, meta interface
for key, value := range config {
configStrings[key] = value.(string)
}
for key, value := range configSensitive {
configStrings[key] = value.(string)
}

return diag.FromErr(resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
_, err := c.CreateConnector(accountID, clusterID, name, configStrings)
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ description: |-
### Required

- **cluster_id** (String) ID of containing cluster, e.g. lkc-abc123
- **config** (Map of String) Type-specific Configuration of cluster. String keys and values
- **config** (Map of String) Type-specific Configuration of connector. String keys and values
- **environment_id** (String) ID of containing environment, e.g. env-abc123
- **name** (String) The name of the connector

### Optional

- **config_sensitive** (Map of String) Sensitive part of connector configuration. String keys and values
- **id** (String) The ID of this resource.
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

Expand Down
36 changes: 36 additions & 0 deletions examples/connector/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
terraform {
required_providers {
kafka = {
source = "Mongey/kafka"
version = "0.2.11"
}
confluentcloud = {
source = "Mongey/confluentcloud"
}
}
}

provider "confluentcloud" {}

resource "confluentcloud_connector" "connector" {
name = "pubsub-kafka-connector"
environment_id = "env-ab123"
cluster_id = "lkc-cd456"
config = {
"name" = "pubsub-kafka-connector"
"connector.class" = "PubSubSource"
"kafka.topic" = "kafka-topic1"
"gcp.pubsub.project.id" = "project-1234"
"gcp.pubsub.subscription.id" = "topic1-subscription1"
"gcp.pubsub.topic.id" = "topic1"
"gcp.pubsub.max.retry.time" = "5"
"gcp.pubsub.message.max.count" = "1000"
"errors.tolerance" = "all"
"tasks.max" = "1"
}
config_sensitive = {
"kafka.api.key" = <<kafka-api-key>>
"kafka.api.secret" = <<kafka-api-secret>>
"gcp.pubsub.credentials.json" = <<gcp-service-account-key>
}
}

0 comments on commit 0328b5c

Please sign in to comment.