Mongey/terraform-provider-kafka

`terraform plan` returns unexpected diff if brokers have cluster-wide default config

joker1007 opened this issue · 1 comments

Definition

terraform {
  required_providers {
    kafka = {
      source  = "Mongey/kafka"
      version = "0.7.1"
    }
  }
}

provider "kafka" {
  bootstrap_servers = ["kafka-broker:9092"]
  tls_enabled       = false
}

resource "kafka_topic" "terraform_test" {
  name               = "terraform-test"
  replication_factor = 3
  partitions         = 16

  config = {
    "cleanup.policy" = "compact"
  }
}

There is no problem with creating.

Plan result

I executed terraform plan with no changes.
The result is following:

kafka_topic.terraform_test: Refreshing state... [id=terraform-test]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # kafka_topic.terraform_test will be updated in-place
  ~ resource "kafka_topic" "terraform_test" {
      ~ config             = {
          - "max.compaction.lag.ms"     = "259200000" -> null
          - "max.message.bytes"         = "8000096" -> null
          - "min.cleanable.dirty.ratio" = "0.2" -> null
            # (1 unchanged element hidden)
        }
        id                 = "terraform-test"
        name               = "terraform-test"
        # (2 unchanged attributes hidden)
    }

Then, terraform apply is failed due to the resource not found.

The kafka brokers have these configs as cluster-wide default configs.

$ kafka-configs --bootstrap-server localhost:9092 --entity-type brokers --entity-default --describe
Default configs for brokers in the cluster are:
  log.cleaner.max.compaction.lag.ms=259200000 sensitive=false synonyms={DYNAMIC_DEFAULT_BROKER_CONFIG:log.cleaner.max.compaction.lag.ms=259200000}
  log.cleaner.min.cleanable.ratio=0.2 sensitive=false synonyms={DYNAMIC_DEFAULT_BROKER_CONFIG:log.cleaner.min.cleanable.ratio=0.2}
  message.max.bytes=8000096 sensitive=false synonyms={DYNAMIC_DEFAULT_BROKER_CONFIG:message.max.bytes=8000096}

Expected Behavior

I anticipate that the kafka-topic resource should not rely on cluster-wide default configurations. Otherwise, every topic resource must contain definitions for cluster-wide default configurations. Additionally, if I wish to modify a cluster-wide default configuration value, I must update all configuration values within the Terraform definitions.

Thank you so much for merging #408.
I think this issue is fixed.