diff --git a/go.mod b/go.mod index 27ebc3e..ec3c86d 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.20 require ( github.com/google/go-cmp v0.5.9 github.com/hashicorp/terraform-plugin-sdk v1.17.2 - github.com/nats-io/jsm.go v0.0.36-0.20230919135355-c609acc39d33 + github.com/nats-io/jsm.go v0.1.1-0.20230921074448-1bbb5650afc8 github.com/nats-io/jwt/v2 v2.5.2 - github.com/nats-io/nats-server/v2 v2.9.23-0.20230918205325-3dc06278119c - github.com/nats-io/nats.go v1.29.0 + github.com/nats-io/nats-server/v2 v2.10.1 + github.com/nats-io/nats.go v1.30.0 github.com/xeipuuv/gojsonschema v1.2.0 ) @@ -21,7 +21,7 @@ require ( github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/sprig v2.22.0+incompatible // indirect github.com/agext/levenshtein v1.2.2 // indirect - github.com/antonmedv/expr v1.15.2 // indirect + github.com/antonmedv/expr v1.15.3 // indirect github.com/apparentlymart/go-cidr v1.1.0 // indirect github.com/apparentlymart/go-textseg/v12 v12.0.0 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect diff --git a/go.sum b/go.sum index 7d03bc2..311335f 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,8 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/g github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/antonmedv/expr v1.15.2 h1:afFXpDWIC2n3bF+kTZE1JvFo+c34uaM3sTqh8z0xfdU= -github.com/antonmedv/expr v1.15.2/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4JUv1ihsE= +github.com/antonmedv/expr v1.15.3 h1:q3hOJZNvLvhqE8OHBs1cFRdbXFNKuA+bHmRaI+AmRmI= +github.com/antonmedv/expr v1.15.3/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4JUv1ihsE= github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU= github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= @@ -494,14 +494,14 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/nats-io/jsm.go v0.0.36-0.20230919135355-c609acc39d33 h1:Ixd98B8Pq0dUxi++ENmZFxDeTBsfG3lbSkaaiDVV6So= -github.com/nats-io/jsm.go v0.0.36-0.20230919135355-c609acc39d33/go.mod h1:/lp3tYWC8DYa7XLxRICA57igfAYquPXEcZvCQ5L3zSk= +github.com/nats-io/jsm.go v0.1.1-0.20230921074448-1bbb5650afc8 h1:OKm9e1//rlcl4i9zXQ6QQxj7DJaeL+Oe8WBgAKO4cqI= +github.com/nats-io/jsm.go v0.1.1-0.20230921074448-1bbb5650afc8/go.mod h1:hB4Qd+IKoRvAAWTOI1HkCy4wotjFwOIT+codHCFOZqk= github.com/nats-io/jwt/v2 v2.5.2 h1:DhGH+nKt+wIkDxM6qnVSKjokq5t59AZV5HRcFW0zJwU= github.com/nats-io/jwt/v2 v2.5.2/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI= -github.com/nats-io/nats-server/v2 v2.9.23-0.20230918205325-3dc06278119c h1:yHb64vNSinDkZbBQRpoKR4cfTuAR57uJ9qW93oQCdbM= -github.com/nats-io/nats-server/v2 v2.9.23-0.20230918205325-3dc06278119c/go.mod h1:3PMvMSu2cuK0J9YInRLWdFpFsswKKGUS77zVSAudRto= -github.com/nats-io/nats.go v1.29.0 h1:dSXZ+SZeGyTdHVYeXimeq12FsIpb9dM8CJ2IZFiHcyE= -github.com/nats-io/nats.go v1.29.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc= +github.com/nats-io/nats-server/v2 v2.10.1 h1:MIJ614dhOIdo71iSzY8ln78miXwrYvlvXHUyS+XdKZQ= +github.com/nats-io/nats-server/v2 v2.10.1/go.mod h1:3PMvMSu2cuK0J9YInRLWdFpFsswKKGUS77zVSAudRto= +github.com/nats-io/nats.go v1.30.0 h1:bj/rVsRCrFXxmm9mJiDhb74UKl2HhKpDwKRBtvCjZjc= +github.com/nats-io/nats.go v1.30.0/go.mod h1:dcfhUgmQNN4GJEfIb2f9R7Fow+gzBF4emzDHrVBd5qM= github.com/nats-io/nkeys v0.4.5 h1:Zdz2BUlFm4fJlierwvGK+yl20IAKUm7eV6AAZXEhkPk= github.com/nats-io/nkeys v0.4.5/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= diff --git a/jetstream/resource_jetstream_consumer.go b/jetstream/resource_jetstream_consumer.go index 8b24291..9677d02 100644 --- a/jetstream/resource_jetstream_consumer.go +++ b/jetstream/resource_jetstream_consumer.go @@ -419,6 +419,25 @@ func resourceConsumerUpdate(d *schema.ResourceData, m any) error { return resourceConsumerRead(d, m) } +func checkConsumerOnLimitsStream(mgr *jsm.Manager, streamName string, cfg *api.ConsumerConfig) error { + stream, err := mgr.LoadStream(streamName) + if err != nil { + return err + } + + if stream.ConsumerLimits().InactiveThreshold > 0 || stream.ConsumerLimits().MaxAckPending > 0 { + if cfg.InactiveThreshold == 0 { + return fmt.Errorf("inactive_threshold is required on streams with consumer limits set") + } + + if cfg.MaxAckPending == 0 { + return fmt.Errorf("inactive_threshold is required on streams with consumer limits set") + } + } + + return nil +} + func resourceConsumerCreate(d *schema.ResourceData, m any) error { cfg, err := consumerConfigFromResourceData(d) if err != nil { @@ -436,6 +455,11 @@ func resourceConsumerCreate(d *schema.ResourceData, m any) error { } defer nc.Close() + err = checkConsumerOnLimitsStream(mgr, stream, &cfg) + if err != nil { + return err + } + _, err = mgr.NewConsumerFromDefault(stream, cfg) if err != nil { return err