1 Star 0 Fork 0

NATS / terraform-provider-jetstream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

This is a work in progress Terraform Provider to manage NATS JetStream.

[!WARNING]

DEPRECATION NOTICE: This project will be deprecated after release 0.1.1 and will receive only bug fixes and security updates going forward.

There are two reasons for deprecation:

  • The primary one is that the NATS server currently has a limitation for supporting declarative-style configuration tools. Specifically, there are some APIs which result in an internal state change that causes the provider state to be implicitly out-of-sync. This is being addressed in 2.11
  • The secondary reason is that the provider is written using an old version of the Terraform SDK and needs to be updated to be compatible with Terraform 1.18+

Once NATS 2.11 is released, the intention is to re-write the provider using the latest Terraform SDK.

Installation

When using Terraform 0.13 or newer adding the provider and running terraform init will download the provider from the Terraform Registry.

Credentials

The provider supports NATS 2.0 credentials either in a file or as a Terraform Variable or Data, for local use you would set the credentials as in the examples later, but if you use something like Terraform Cloud or wish to store the credentials in a credential store you can use Terraform Variables:

variable "ngs_credential_data" {
  type = string
  description = "Text of the NATS credentials to use to manage JetStream"
}

provider "jetstream" {
  servers = "connect.ngs.global"
  credential_data = var.ngs_credential_data
}

A locked down user that can only admin JetStream but not retrieve any data stored in JetStream looks like this:

╭─────────────────────────────────────────────────────────────────────────────────╮
│                                      User                                       │
├──────────────────────┬──────────────────────────────────────────────────────────┤
│ Name                 │ ngs_jetstream_admin                                      │
│ User ID              │ UBI3V7PXXQHJ67C4G2W2D7ICX3NK4S2RJCBUPNLWGGV6W34HYFUSD57M │
│ Issuer ID            │ AARRII4JZYJB3WYECBTMU6WSST2SUZ7SN7PWNSDWQTYVPMXQHDA3WXZ7 │
│ Issued               │ 2020-03-11 10:37:29 UTC                                  │
│ Expires              │ 2020-04-11 10:37:29 UTC                                  │
+----------------------+----------------------------------------------------------+
| Pub Allow            | $JS.API.CONSUMER.DELETE.*.*                              |
|                      | $JS.API.CONSUMER.DURABLE.CREATE.*.*                      |
|                      | $JS.API.CONSUMER.INFO.*.*                                |
|                      | $JS.API.CONSUMER.LIST.*                                  |
|                      | $JS.API.CONSUMER.NAMES.*                                 |
|                      | $JS.API.INFO                                             |
|                      | $JS.API.STREAM.CREATE.*                                  |
|                      | $JS.API.STREAM.DELETE.*                                  |
|                      | $JS.API.STREAM.INFO.*                                    |
|                      | $JS.API.STREAM.LIST                                      |
|                      | $JS.API.STREAM.NAMES                                     |
|                      | $JS.API.STREAM.TEMPLATE.>                                |
|                      | $JS.API.STREAM.UPDATE.*                                  |
| Sub Allow            | _INBOX.>                                                 |
| Response Permissions | Not Set                                                  |
+----------------------+----------------------------------------------------------+
| Max Msg Payload      | Unlimited                                                |
| Max Data             | Unlimited                                                |
| Max Subs             | Unlimited                                                |
| Network Src          | Any                                                      |
| Time                 | Any                                                      |
+----------------------+----------------------------------------------------------+

Here's a command to create this using nsc, note replace the DemoAccount and 1M strings with your account name and desired expiry time:

$ nsc add user -a DemoAccount
--expiry 1M \
--name ngs_jetstream_admin \
--allow-pub '$JS.API.CONSUMER.DELETE.*.*' \
--allow-pub '$JS.API.CONSUMER.DURABLE.CREATE.*.*' \
--allow-pub '$JS.API.CONSUMER.INFO.*.*' \
--allow-pub '$JS.API.CONSUMER.LIST.*' \
--allow-pub '$JS.API.CONSUMER.NAMES.*' \
--allow-pub '$JS.API.INFO' \
--allow-pub '$JS.API.STREAM.CREATE.*' \
--allow-pub '$JS.API.STREAM.DELETE.*' \
--allow-pub '$JS.API.STREAM.INFO.*' \
--allow-pub '$JS.API.STREAM.LIST' \
--allow-pub '$JS.API.STREAM.NAMES' \
--allow-pub '$JS.API.STREAM.TEMPLATE.>' \
--allow-pub '$JS.API.STREAM.UPDATE.*' \
--allow-sub '_INBOX.>'

This will create the credential in ~/.nkeys/creds/synadia/MyAccount/ngs_jetstream_admin.creds

Provider

Terraform Provider that connects to any NATS JetStream server

Example

provider "jetstream" {
  servers     = "connect.ngs.global:4222"
  credentials = "/home/you/ngs_stream_admin.creds"
}

Argument Reference

  • servers - The list of servers to connect to in a comma seperated list.
  • credentials - (optional) Fully Qualified Path to a file holding NATS credentials.
  • credential_data - (optional) The NATS credentials as a string, intended to use with data providers.
  • user - (optional) Connects using a username, when no password is set this is assumed to be a Token.
  • password - (optional) Connects using a password.
  • nkey - (optional) Connects using an nkey stored in a file.
  • tls.ca_file - (optional) Fully Qualified Path to a file containing Root CA (PEM format). Use when the server has certs signed by an unknown authority.
  • tls.ca_file_data - (optional) The Root CA PEM as a string, intended to use with data providers. Use when the server has certs signed by an unknown authority.
  • tls.cert_file - (optional) The certificate to authenticate with.
  • tls.cert_file_data - (optional) The certificate to authenticate with, intended to use with data providers.
  • tls.key_file - (optional) The private key to authenticate with.
  • tls.key_file_data - (optional) The private key to authenticate with, intended to use with data providers.

jetstream_stream

Creates a JetStream Stream, supports editing resources in place.

Example

resource "jetstream_stream" "ORDERS" {
  name     = "ORDERS"
  subjects = ["ORDERS.*"]
  storage  = "file"
  max_age  = 60 * 60 * 24 * 365
}

resource "jetstream_stream" "TRANSFORM" {
  name     = "TRANSFORM"
  subjects = ["TRANSFORM.*"]
  storage  = "file"
  subject_transform {
    source      = "TRANSFORM.>"
    destination = "NEWSUBJECT.>"
  }
}

Attribute Reference

  • description - (optional) Contains additional information about this stream (string)
  • metadata - (optional) A map of strings with arbitrary metadata for the stream
  • ack - (optional) If the Stream should support confirming receiving messages via acknowledgements (bool)
  • max_age - (optional) The maximum oldest message that can be kept in the stream, duration specified in seconds (number)
  • max_bytes - (optional) The maximum size of all messages that can be kept in the stream (number)
  • compression - (optional) Enable stream compression by setting the value to s2
  • max_consumers - (optional) Number of consumers this stream allows (number)
  • max_msg_size - (optional) The maximum individual message size that the stream will accept (number)
  • max_msgs - (optional) The maximum amount of messages that can be kept in the stream (number)
  • max_msgs_per_subject (optional) The maximum amount of messages that can be kept in the stream on a per-subject basis (number)
  • name - The name of the stream (string)
  • replicas - (optional) How many replicas of the data to keep in a clustered environment (number)
  • retention - (optional) The retention policy to apply over and above max_msgs, max_bytes and max_age (string)
  • storage - (optional) The storage engine to use to back the stream (string)
  • subjects - The list of subjects that will be consumed by the Stream (["list", "string"])
  • duplicate_window - (optional) The time window size for duplicate tracking, duration specified in seconds (number)
  • placement_cluster - (optional) Place the stream in a specific cluster, influenced by placement_tags
  • placement_tags - (optional) Place the stream only on servers with these tags
  • source - (optional) List of streams to source
  • mirror - (optional) Stream to mirror
  • deny_delete - (optional) Restricts the ability to delete messages from a stream via the API. Cannot be changed once set to true (bool)
  • deny_purge - (optional) Restricts the ability to purge messages from a stream via the API. Cannot be change once set to true (bool)
  • allow_rollup_hdrs - (optional) Allows the use of the Nats-Rollup header to replace all contents of a stream, or subject in a stream, with a single new message (bool)
  • allow_direct - (optional) Allow higher performance, direct access to get individual messages via the $JS.DS.GET API (bool)
  • subject_transform - (optional) A map of source and destination subjects to transform.

jetstream_consumer

Create or Delete Consumers on any Terraform managed Stream. Does not support editing consumers in place

Example

resource "jetstream_stream" "ORDERS" {
  name     = "ORDERS"
  subjects = ["ORDERS.*"]
  storage  = "file"
  max_age  = 60 * 60 * 24 * 365
}

resource "jetstream_consumer" "ORDERS_NEW" {
  stream_id      = jetstream_stream.ORDERS.id
  durable_name   = "NEW"
  deliver_all    = true
  filter_subject = "ORDERS.received"
  sample_freq    = 100
}

Attribute Reference

  • description - (optional) Contains additional information about this consumer
  • metadata - (optional) A map of strings with arbitrary metadata for the consumer
  • discard - (optional) When a Stream reach it's limits either old messages are deleted or new ones are denied (new or old)
  • discard_new_per_subject - (optional) When discard policy is new and the stream is one with max messages per subject set, this will apply the new behavior to every subject. Essentially turning discard new from maximum number of subjects into maximum number of messages in a subject (bool)
  • ack_policy - (optional) The delivery acknowledgement policy to apply to the Consumer
  • ack_wait - (optional) Number of seconds to wait for acknowledgement
  • deliver_all - (optional) Starts at the first available message in the Stream
  • deliver_last - (optional) Starts at the latest available message in the Stream
  • delivery_subject - (optional) The subject where a Push-based consumer will deliver messages
  • delivery_group - (optional) When set Push consumers will only deliver messages to subscriptions with this group set
  • durable_name - The durable name of the Consumer
  • filter_subject - (optional) Only receive a subset of messages from the Stream based on the subject they entered the Stream on
  • filter_subjects - (optional) Only receive a subset tof messages from the Stream based on subjects they entered the Stream on. This is exclusive to filter_subject. Only works with v2.10 or better.
  • max_delivery - (optional) Maximum deliveries to attempt for each message
  • replay_policy - (optional) The rate at which messages will be replayed from the stream
  • sample_freq - (optional) The percentage of acknowledgements that will be sampled for observability purposes
  • start_time - (optional) The timestamp of the first message that will be delivered by this Consumer
  • stream_id - The name of the Stream that this consumer consumes
  • stream_sequence - (optional) The Stream Sequence that will be the first message delivered by this Consumer
  • ratelimit - (optional) The rate limit for delivering messages to push consumers, expressed in bits per second
  • heartbeat - (optional) Enable heartbeat messages for push consumers, duration specified in seconds
  • flow_control - (optional) Enable flow control for push consumers
  • max_waiting - (optional) The number of pulls that can be outstanding on a pull consumer, pulls received after this is reached are ignored
  • headers_only - (optional) When true no message bodies will be delivered only headers
  • max_batch - (optional) Limits Pull Batch sizes to this maximum
  • max_bytes - (optional)The maximum bytes value that maybe set when dong a pull on a Pull Consumer
  • max_expires - (optional) Limits the Pull Expires duration to this maximum in seconds
  • inactive_threshold - (optional) Removes the consumer after a idle period, specified as a duration in seconds
  • replicas - (optional) How many replicas of the data to keep in a clustered environment
  • memory - (optional) Force the consumer state to be kept in memory rather than inherit the setting from the stream
  • backoff - (optional) List of durations in Go format that represents a retry time scale for NaK'd messages. A list of durations in seconds
  • republish_source - (optional) Republish matching messages to republish_destination
  • republish_destination - (optional) The destination to publish messages to
  • republish_headers_only - (optional) Republish only message headers, no bodies

jetstream_kv_bucket

Creates a JetStream based KV bucket

Example

resource "jetstream_kv_bucket" "test" {
  name = "TEST"
  ttl = 60
  history = 10
  max_value_size = 1024
  max_bucket_size = 10240
}

Attribute Reference

  • name - (required) The unique name of the KV bucket, must match \A[a-zA-Z0-9_-]+\z
  • description - (optional) Contains additional information about this bucket
  • history - (optional) Number of historic values to keep
  • ttl - (optional) How many seconds to keep values for, keeps forever when not set
  • placement_cluster - (optional) Place the bucket in a specific cluster, influenced by placement_tags
  • placement_tags - (optional) Place the bucket only on servers with these tags
  • max_value_size - (optional) Maximum size of any value
  • max_bucket_size - (optional) The maximum size of all data in the bucket
  • replicas - (optional) How many replicas to keep on a JetStream cluster

jetstream_kv_entry

Creates a JetStream based KV bucket entry

Example

resource "jetstream_kv_entry" "test_entry" {
  bucket = "TEST"
  key = "foo"
  value = "bar"
}

Attribute Reference

  • bucket - (required) The name of the KV bucket
  • key - (required) The entry key
  • value - (required) The entry value

Import existing JetStream resources

See docs/guides/import.md

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Terraform Provider to manage NATS JetStream 展开 收起
Go 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/nats-io/terraform-provider-jetstream.git
git@gitee.com:nats-io/terraform-provider-jetstream.git
nats-io
terraform-provider-jetstream
terraform-provider-jetstream
main

搜索帮助