Skip to content

Commit 5eddd6a

Browse files
authored
Merge pull request #3 from Mongey/cm-ci
Prune Deps, Run acceptance tests in CI, update to go 1.10
2 parents 2c6ca25 + 9588f49 commit 5eddd6a

File tree

911 files changed

+5497
-263943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

911 files changed

+5497
-263943
lines changed

.circleci/config.yml

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
build:
44
working_directory: /go/src/github.com/Mongey/terraform-provider-kafka-connect
55
docker:
6-
- image: circleci/golang:1.9
6+
- image: circleci/golang:1.10
77
environment:
88
TEST_RESULTS: /tmp/test-results
99
- image: confluentinc/cp-zookeeper:latest
@@ -16,6 +16,23 @@ jobs:
1616
KAFKA_ZOOKEEPER_CONNECT: localhost:2181
1717
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
1818
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
19+
- image: confluentinc/cp-kafka-connect:4.0.0-2
20+
environment:
21+
CONNECT_BOOTSTRAP_SERVERS: PLAINTEXT://localhost:9092
22+
CONNECT_GROUP_ID: connect
23+
CONNECT_REST_PORT: 8083
24+
CONNECT_CONFIG_STORAGE_TOPIC: "quickstart-config"
25+
CONNECT_OFFSET_STORAGE_TOPIC: "quickstart-offsets"
26+
CONNECT_STATUS_STORAGE_TOPIC: "quickstart-status"
27+
CONNECT_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
28+
CONNECT_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
29+
CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
30+
CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
31+
CONNECT_REST_ADVERTISED_HOST_NAME: "localhost"
32+
CONNECT_PLUGIN_PATH: /usr/share/java
33+
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
34+
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
35+
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
1936
steps:
2037
- checkout
2138
- run: go build
@@ -24,6 +41,13 @@ jobs:
2441
destination: terraform-provider-kafka
2542
- run: go get github.com/jstemmer/go-junit-report
2643
- run: mkdir -p $TEST_RESULTS
44+
- run:
45+
name: Wait for connect
46+
command: |
47+
until $(curl --output /dev/null --silent --head --fail http://localhost:8083); do
48+
printf '.'
49+
sleep 5
50+
done
2751
- run:
2852
name: Run Tests
2953
command: |

GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ test:
1212
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
1313

1414
testacc:
15-
KAFKA_BROKER=localhost:9092 TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
15+
KAFKA_CONNECT_URL=http://localhost:8083 TF_LOG=debug TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
1616

1717
.PHONY: build test testacc

Gopkg.lock

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+5-22
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
# Gopkg.toml example
2-
#
3-
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4-
# for detailed Gopkg.toml documentation.
5-
#
6-
# required = ["github.com/user/thing/cmd/thing"]
7-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8-
#
9-
# [[constraint]]
10-
# name = "github.com/user/project"
11-
# version = "1.0.0"
12-
#
13-
# [[constraint]]
14-
# name = "github.com/user/project2"
15-
# branch = "dev"
16-
# source = "github.com/myfork/project2"
17-
#
18-
# [[override]]
19-
# name = "github.com/x/y"
20-
# version = "2.4.0"
21-
22-
231
[[constraint]]
242
name = "github.com/hashicorp/terraform"
253
version = "0.11.3"
264

275
[[constraint]]
286
branch = "master"
297
name = "github.com/ricardo-ch/go-kafka-connect"
8+
9+
[prune]
10+
go-tests = true
11+
non-go = true
12+
unused-packages = true

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ your [terraform plugin directory][third-party-plugins] (typically `~/.terraform.
1111

1212
## Example
1313

14+
Configure the provider directly, or set the Env variable `KAFKA_CONNECT_URL`
1415
```hcl
1516
provider "kafka-connect" {
1617
url = "http://localhost:8083"

connect/provider.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package connect
22

33
import (
4+
"log"
5+
46
"github.com/hashicorp/terraform/helper/schema"
57
"github.com/hashicorp/terraform/terraform"
68
kc "github.com/ricardo-ch/go-kafka-connect/lib/connectors"
79
)
810

911
func Provider() terraform.ResourceProvider {
12+
log.Printf("[INFO] Creating Provider")
1013
return &schema.Provider{
1114
Schema: map[string]*schema.Schema{
1215
"url": {
13-
Type: schema.TypeString,
14-
Required: true,
16+
Type: schema.TypeString,
17+
Optional: true,
18+
DefaultFunc: schema.EnvDefaultFunc("KAFKA_CONNECT_URL", ""),
1519
},
1620
},
17-
1821
ConfigureFunc: providerConfigure,
1922
ResourcesMap: map[string]*schema.Resource{
2023
"kafka-connect_connector": kafkaConnectorResource(),
@@ -23,7 +26,9 @@ func Provider() terraform.ResourceProvider {
2326
}
2427

2528
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
26-
c := kc.NewClient(d.Get("url").(string))
29+
log.Printf("[INFO] Initializing KafkaConnect client")
30+
addr := d.Get("url").(string)
31+
c := kc.NewClient(addr)
2732

2833
return c, nil
2934
}

connect/provider_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package connect
22

33
import (
4+
"log"
45
"testing"
56

67
"github.com/hashicorp/terraform/helper/schema"
@@ -10,18 +11,23 @@ import (
1011
var testProvider *schema.Provider
1112
var testProviders map[string]terraform.ResourceProvider
1213

14+
func init() {
15+
testProvider = Provider().(*schema.Provider)
16+
testProviders = map[string]terraform.ResourceProvider{
17+
"kafka-connect": testProvider,
18+
}
19+
}
20+
1321
func TestProvider(t *testing.T) {
1422
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
1523
t.Fatalf("err: %s", err)
1624
}
1725
}
1826

1927
func testAccPreCheck(t *testing.T) {
20-
}
21-
22-
func accProvider() map[string]terraform.ResourceProvider {
23-
provider := Provider().(*schema.Provider)
24-
return map[string]terraform.ResourceProvider{
25-
"kafka-connect": provider,
28+
client := testProvider.Meta()
29+
log.Printf("[INFO] Checking KafkaConnect client")
30+
if client == nil {
31+
//t.Fatal("No client")
2632
}
2733
}

connect/resource_kafka_connector.go

+33-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package connect
22

33
import (
4+
"fmt"
45
"log"
56

67
"github.com/hashicorp/terraform/helper/schema"
@@ -35,26 +36,17 @@ func kafkaConnectorResource() *schema.Resource {
3536

3637
func connectorCreate(d *schema.ResourceData, meta interface{}) error {
3738
c := meta.(kc.Client)
38-
name := d.Get("name").(string)
39-
40-
cfg := d.Get("config").(map[string]interface{})
41-
config := make(map[string]string)
42-
43-
for k, v := range cfg {
44-
switch v := v.(type) {
45-
case string:
46-
config[k] = v
47-
}
48-
}
49-
39+
name := nameFromRD(d)
40+
config := configFromRD(d)
5041
req := kc.CreateConnectorRequest{
5142
ConnectorRequest: kc.ConnectorRequest{
5243
Name: name,
5344
},
5445
Config: config,
5546
}
5647

57-
_, err := c.CreateConnector(req, true)
48+
connectorResponse, err := c.CreateConnector(req, true)
49+
fmt.Printf("[INFO] Created the connector %v\n", connectorResponse)
5850

5951
if err == nil {
6052
d.SetId(name)
@@ -63,14 +55,21 @@ func connectorCreate(d *schema.ResourceData, meta interface{}) error {
6355
return err
6456
}
6557

58+
func nameFromRD(d *schema.ResourceData) string {
59+
return d.Get("name").(string)
60+
}
61+
6662
func connectorDelete(d *schema.ResourceData, meta interface{}) error {
6763
c := meta.(kc.Client)
6864

65+
name := nameFromRD(d)
6966
req := kc.ConnectorRequest{
70-
Name: d.Get("name").(string),
67+
Name: name,
7168
}
72-
_, err := c.DeleteConnector(req, true)
7369

70+
fmt.Printf("[INFO] Deleing the connector %s\n", name)
71+
72+
_, err := c.DeleteConnector(req, true)
7473
if err == nil {
7574
d.SetId("")
7675
}
@@ -81,16 +80,8 @@ func connectorDelete(d *schema.ResourceData, meta interface{}) error {
8180
func connectorUpdate(d *schema.ResourceData, meta interface{}) error {
8281
c := meta.(kc.Client)
8382

84-
name := d.Get("name").(string)
85-
cfg := d.Get("config").(map[string]interface{})
86-
config := make(map[string]string)
87-
88-
for k, v := range cfg {
89-
switch v := v.(type) {
90-
case string:
91-
config[k] = v
92-
}
93-
}
83+
name := nameFromRD(d)
84+
config := configFromRD(d)
9485

9586
req := kc.CreateConnectorRequest{
9687
ConnectorRequest: kc.ConnectorRequest{
@@ -103,12 +94,13 @@ func connectorUpdate(d *schema.ResourceData, meta interface{}) error {
10394
conn, err := c.UpdateConnector(req, true)
10495

10596
if err == nil {
106-
log.Printf("[INFO] this the shit %v", conn.Config)
97+
log.Printf("[INFO] Config updated %v", conn.Config)
10798
d.Set("config", conn.Config)
10899
}
109100

110101
return err
111102
}
103+
112104
func connectorRead(d *schema.ResourceData, meta interface{}) error {
113105
c := meta.(kc.Client)
114106

@@ -120,9 +112,23 @@ func connectorRead(d *schema.ResourceData, meta interface{}) error {
120112
conn, err := c.GetConnector(req)
121113

122114
if err == nil {
123-
log.Printf("[INFO] this the shit %v", conn.Config)
115+
log.Printf("[INFO] found the config %v", conn.Config)
124116
d.Set("config", conn.Config)
125117
}
126118

127119
return err
128120
}
121+
122+
func configFromRD(d *schema.ResourceData) map[string]string {
123+
cfg := d.Get("config").(map[string]interface{})
124+
config := make(map[string]string)
125+
126+
for k, v := range cfg {
127+
switch v := v.(type) {
128+
case string:
129+
config[k] = v
130+
}
131+
}
132+
133+
return config
134+
}

0 commit comments

Comments
 (0)