Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topic protection flag #180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ resource "kafka_topic" "logs" {
"segment.ms" = "20000"
"cleanup.policy" = "compact"
}
termination_protection = false
}
```

#### Properties

| Property | Description |
| -------------------- | ---------------------------------------------- |
| `name` | The name of the topic |
| `partitions` | The number of partitions the topic should have |
| `replication_factor` | The number of replicas the topic should have |
| `config` | A map of string [K/V attributes][topic-config] |
| Property | Description |
| ------------------------ | ---------------------------------------------- |
| `name` | The name of the topic |
| `partitions` | The number of partitions the topic should have |
| `replication_factor` | The number of replicas the topic should have |
| `config` | A map of string [K/V attributes][topic-config] |
| `termination_protection` | Client side removal protection |


#### Importing Existing Topics
Expand Down
11 changes: 11 additions & 0 deletions kafka/resource_kafka_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func kafkaTopicResource() *schema.Resource {
Description: "A map of string k/v attributes.",
Elem: schema.TypeString,
},
"termination_protection": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: false,
Description: `Prevents a Kafka topic from being deleted.`,
},
},
}
}
Expand Down Expand Up @@ -210,6 +217,10 @@ func topicDelete(d *schema.ResourceData, meta interface{}) error {
c := meta.(*LazyClient)
t := metaToTopic(d, meta)

if d.Get("termination_protection").(bool) {
return fmt.Errorf("Topic '%s' have termination_protection enabled and it prevent from deletion", t.Name)
}

err := c.DeleteTopic(t.Name)
if err != nil {
return err
Expand Down