diff --git a/README.md b/README.md index 56fea7d2..e041e223 100644 --- a/README.md +++ b/README.md @@ -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" { diff --git a/kafka/client.go b/kafka/client.go index 7389058a..7b11c9a8 100644 --- a/kafka/client.go +++ b/kafka/client.go @@ -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 @@ -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 { diff --git a/kafka/provider.go b/kafka/provider.go index 0046d5ce..8b16cb42 100644 --- a/kafka/provider.go +++ b/kafka/provider.go @@ -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, @@ -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)) @@ -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) diff --git a/kafka/provider_test.go b/kafka/provider_test.go index 72f7b2a2..2d601822 100644 --- a/kafka/provider_test.go +++ b/kafka/provider_test.go @@ -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) diff --git a/kafka/resource_kafka_topic.go b/kafka/resource_kafka_topic.go index 79485b06..8b9b13df 100644 --- a/kafka/resource_kafka_topic.go +++ b/kafka/resource_kafka_topic.go @@ -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) diff --git a/kafka/resource_kafka_topic_test.go b/kafka/resource_kafka_topic_test.go index 409b1675..98661392 100644 --- a/kafka/resource_kafka_topic_test.go +++ b/kafka/resource_kafka_topic_test.go @@ -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") @@ -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 { @@ -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") @@ -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" { @@ -140,7 +140,7 @@ resource "kafka_topic" "test" { const testResourceTopic_updateConfig = ` provider "kafka" { - brokers = ["localhost:9092"] + bootstrap_servers = ["localhost:9092"] } resource "kafka_topic" "test" { @@ -157,7 +157,7 @@ resource "kafka_topic" "test" { const testResourceTopic_updatePartitions = ` provider "kafka" { - brokers = ["localhost:9092"] + bootstrap_servers = ["localhost:9092"] } resource "kafka_topic" "test" {