From d450b9b04b5efc5fe434247e3a68002d6a2a40ae Mon Sep 17 00:00:00 2001 From: Pieter Loubser Date: Wed, 21 Aug 2024 14:26:42 +0100 Subject: [PATCH] (#114) Fix changing `max_waiting` value when `delivery_subject` is set Here we update the `max_waiting` consumer resource field to be computed. This allows us to set its value to 0 when `delivery_subject` is set and not have it flip to the default on every apply. `max_waiting` now also conficts with the `delivery_subject` field, since these two imply the use of push vs pull consumers and don't make sense when specified together. --- jetstream/resource_jetstream_consumer.go | 20 ++++++++++++------- jetstream/resource_jetstream_consumer_test.go | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/jetstream/resource_jetstream_consumer.go b/jetstream/resource_jetstream_consumer.go index 6a4463d..bb64a8a 100644 --- a/jetstream/resource_jetstream_consumer.go +++ b/jetstream/resource_jetstream_consumer.go @@ -193,12 +193,13 @@ func resourceConsumer() *schema.Resource { ForceNew: true, }, "max_waiting": { - Type: schema.TypeInt, - Description: "The number of pulls that can be outstanding on a pull consumer, pulls received after this is reached are ignored", - Optional: true, - Default: 512, - ForceNew: false, - ValidateFunc: validation.IntAtLeast(0), + Type: schema.TypeInt, + Description: "The number of pulls that can be outstanding on a pull consumer, pulls received after this is reached are ignored", + Optional: true, + Computed: true, + ConflictsWith: []string{"delivery_subject"}, + ForceNew: false, + ValidateFunc: validation.IntAtLeast(0), }, "headers_only": { Type: schema.TypeBool, @@ -291,7 +292,12 @@ func consumerConfigFromResourceData(d *schema.ResourceData) (cfg api.ConsumerCon if cfg.DeliverSubject != "" { cfg.DeliverGroup = d.Get("delivery_group").(string) } else { - cfg.MaxWaiting = d.Get("max_waiting").(int) + if max_waiting := d.Get("max_waiting").(int); max_waiting == 0 { + // set default value. default cannot be set because this field is computed + max_waiting = 512 + } else { + cfg.MaxWaiting = max_waiting + } } for _, d := range d.Get("backoff").([]any) { diff --git a/jetstream/resource_jetstream_consumer_test.go b/jetstream/resource_jetstream_consumer_test.go index 3a1a676..adc357c 100644 --- a/jetstream/resource_jetstream_consumer_test.go +++ b/jetstream/resource_jetstream_consumer_test.go @@ -51,6 +51,7 @@ resource "jetstream_consumer" "TEST_C2" { stream_sequence = 10 max_ack_pending = 20 filter_subjects = ["TEST.a", "TEST.b"] + max_waiting = 10 } ` @@ -70,6 +71,7 @@ resource "jetstream_consumer" "TEST_C3" { stream_sequence = 10 max_ack_pending = 20 filter_subject = "TEST.a" + delivery_subject = "ORDERS.a" } `