|
| 1 | +# msk_topic_config_comments |
| 2 | + |
| 3 | +## Requirements |
| 4 | + |
| 5 | +Topic configurations expressed in milliseconds must have comments explaining the property and including the human-readable value. |
| 6 | +The comments can be placed after the property definition on the same line or on the line before the definition. |
| 7 | + |
| 8 | +For computing the human-readable values it considers the following: |
| 9 | +- 1 month has 30 days |
| 10 | +- 1 year has 365 days |
| 11 | + |
| 12 | +It currently checks the properties: |
| 13 | +- retention.ms: explanation must start with `keep data` |
| 14 | +- local.retention.ms: explanation must start with `keep data in primary storage` |
| 15 | +- max.compaction.lag.ms: explanation must start with `allow not compacted keys maximum` |
| 16 | + |
| 17 | +## Example |
| 18 | + |
| 19 | +### Good example |
| 20 | + |
| 21 | +```hcl |
| 22 | +# Good topic example with remote storage enabled |
| 23 | +resource "kafka_topic" "good_topic" { |
| 24 | + name = "pubsub.good-topic" |
| 25 | + replication_factor = 3 |
| 26 | + config = { |
| 27 | + "remote.storage.enable" = "true" |
| 28 | + "cleanup.policy" = "delete" |
| 29 | + # keep data in primary storage for 1 day |
| 30 | + "local.retention.ms" = "86400000" |
| 31 | + "retention.ms" = "2592000000" # keep data for 1 month |
| 32 | + "compression.type" = "zstd" |
| 33 | + } |
| 34 | +} |
| 35 | +
|
| 36 | +# Good compacted topic |
| 37 | +resource "kafka_topic" "good topic" { |
| 38 | + name = "good_topic" |
| 39 | + replication_factor = 3 |
| 40 | + config = { |
| 41 | + "cleanup.policy" = "compact" |
| 42 | + "compression.type" = "zstd" |
| 43 | + # allow not compacted keys maximum for 7 days |
| 44 | + "max.compaction.lag.ms" = "604800000" |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Bad examples |
| 50 | + |
| 51 | +```hcl |
| 52 | +# the value in the comment doesn't correspond to the actual value. |
| 53 | +resource "kafka_topic" "topic_wrong_retention_comment" { |
| 54 | + name = "topic_wrong_retention_comment" |
| 55 | + replication_factor = 3 |
| 56 | + config = { |
| 57 | + # keep data for 1 day |
| 58 | + "retention.ms" = "172800000" |
| 59 | + } |
| 60 | +} |
| 61 | +
|
| 62 | +# the value is not commented at all |
| 63 | +resource "kafka_topic" "topic_without_retention_comment" { |
| 64 | + name = "topic_without_retention_comment" |
| 65 | + config = { |
| 66 | + "local.retention.ms" = "86400000" |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +## How To Fix |
| 72 | + |
| 73 | +The rule automatically fixes the comments. See the [requirements](#requirements) |
| 74 | + |
| 75 | +See [good example](#good-example) |
0 commit comments