Skip to content

Commit

Permalink
Rename brokers to bootstrap_servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey committed Feb 20, 2018
1 parent bde19c5 commit 0655c2f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A [Terraform][1] plugin for managing [Apache Kafka][2].

```hcl
provider "kafka" {
brokers = ["localhost:9092"]
bootstrap_servers = ["localhost:9092"]
}
resource "kafka_topic" "logs" {
Expand Down
16 changes: 8 additions & 8 deletions kafka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ type Client struct {
}

type Config struct {
Brokers *[]string
Timeout int
BootstrapServers *[]string
Timeout int
}

func NewClient(config *Config) (*Client, error) {
kafkaConfig := sarama.NewConfig()
kafkaConfig.Version = sarama.V0_11_0_0

log.Printf("[INFO] configuring brokers %v", config)
brokers := *(config.Brokers)
log.Printf("[INFO] configuring bootstrap_servers %v", config)
bootstrapServers := *(config.BootstrapServers)

if brokers == nil {
return nil, fmt.Errorf("No brokers provided")
if bootstrapServers == nil {
return nil, fmt.Errorf("No bootstrap_servers provided")
}

c, err := sarama.NewClient(brokers, kafkaConfig)
c, err := sarama.NewClient(bootstrapServers, kafkaConfig)
if err != nil {
fmt.Println("Error connecting to kafka")
return nil, err
Expand Down Expand Up @@ -147,7 +147,7 @@ func (c *Client) availableBroker() (*sarama.Broker, error) {
kafkaConfig := sarama.NewConfig()
kafkaConfig.Version = sarama.V0_11_0_0

brokers := *c.config.Brokers
brokers := *c.config.BootstrapServers

log.Printf("[DEBUG] Looking for Brokers @ %v", brokers)
for _, b := range brokers {
Expand Down
8 changes: 4 additions & 4 deletions kafka/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"brokers": {
"bootstrap_servers": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Required: true,
Expand All @@ -35,7 +35,7 @@ func Provider() terraform.ResourceProvider {
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
var brokers *[]string

if brokersRaw, ok := d.GetOk("brokers"); ok {
if brokersRaw, ok := d.GetOk("bootstrap_servers"); ok {
brokerI := brokersRaw.([]interface{})
log.Printf("[DEBUG] configuring provider with Brokers of size %d", len(brokerI))
b := make([]string, len(brokerI))
Expand All @@ -53,8 +53,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
timeout := d.Get("timeout").(int)

config := &Config{
Brokers: brokers,
Timeout: timeout,
BootstrapServers: brokers,
Timeout: timeout,
}

log.Printf("[DEBUG] Config @ %v", config)
Expand Down
4 changes: 2 additions & 2 deletions kafka/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func testAccPreCheck(t *testing.T) {

func accProvider() map[string]terraform.ResourceProvider {
provider := Provider().(*schema.Provider)
brokers := []string{"localhost:9092"}
bootstrap_servers := []string{"localhost:9092"}
raw := map[string]interface{}{
"brokers": brokers,
"bootstrap_servers": bootstrap_servers,
}

rawConfig, err := config.NewRawConfig(raw)
Expand Down
2 changes: 1 addition & 1 deletion kafka/resource_kafka_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func topicCreate(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)
t := metaToTopic(d, meta)

for i, b := range *c.config.Brokers {
for i, b := range *c.config.BootstrapServers {
log.Printf("[DEBUG] Brokers %d , %s", i, b)
}
err := c.CreateTopic(t)
Expand Down
12 changes: 6 additions & 6 deletions kafka/resource_kafka_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func testResourceTopic_initialCheck(s *terraform.State) error {
}

client, _ := NewClient(&Config{
Brokers: &[]string{"localhost:9092"},
BootstrapServers: &[]string{"localhost:9092"},
})

topic, err := client.ReadTopic("syslog")
Expand All @@ -85,7 +85,7 @@ func testResourceTopic_initialCheck(s *terraform.State) error {

func testResourceTopic_updateCheck(s *terraform.State) error {
client, _ := NewClient(&Config{
Brokers: &[]string{"localhost:9092"},
BootstrapServers: &[]string{"localhost:9092"},
})
topic, err := client.ReadTopic("syslog")
if err != nil {
Expand All @@ -108,7 +108,7 @@ func testResourceTopic_updateCheck(s *terraform.State) error {

func testResourceTopic_updatePartitionsCheck(s *terraform.State) error {
client, _ := NewClient(&Config{
Brokers: &[]string{"localhost:9092"},
BootstrapServers: &[]string{"localhost:9092"},
})
topic, err := client.ReadTopic("syslog")

Expand All @@ -123,7 +123,7 @@ func testResourceTopic_updatePartitionsCheck(s *terraform.State) error {

const testResourceTopic_initialConfig = `
provider "kafka" {
brokers = ["localhost:9092"]
bootstrap_servers = ["localhost:9092"]
}
resource "kafka_topic" "test" {
Expand All @@ -140,7 +140,7 @@ resource "kafka_topic" "test" {

const testResourceTopic_updateConfig = `
provider "kafka" {
brokers = ["localhost:9092"]
bootstrap_servers = ["localhost:9092"]
}
resource "kafka_topic" "test" {
Expand All @@ -157,7 +157,7 @@ resource "kafka_topic" "test" {

const testResourceTopic_updatePartitions = `
provider "kafka" {
brokers = ["localhost:9092"]
bootstrap_servers = ["localhost:9092"]
}
resource "kafka_topic" "test" {
Expand Down

0 comments on commit 0655c2f

Please sign in to comment.