Skip to content

Commit

Permalink
Add exchange parameter to AMQP External Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
graham-russell committed Dec 13, 2023
1 parent ac3a916 commit d850dbf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/resources/rule_amqp_external.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Optional:

Required:

- `Exchange` (String) The RabbitMQ exchange, if needed supports interpolation; see https://faqs.ably.com/what-is-the-format-of-the-routingkey-for-an-amqp-or-kinesis-reactor-rule for more info. If you don't use RabbitMQ exchanges, leave this blank.
- `mandatory_route` (Boolean) Reject delivery of the message if the route does not exist, otherwise fail silently.
- `persistent_messages` (Boolean) Marks the message as persistent, instructing the broker to write it to disk if it is in a durable queue.
- `routing_key` (String) The Kafka partition key. This is used to determine which partition a message should be routed to, where a topic has been partitioned. routingKey should be in the format topic:key where topic is the topic to publish to, and key is the value to use as the message key
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/rule_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ resource "ably_rule_http" "rule0" {
signing_key_id = ably_api_key.api_key_0.id
enveloped = true
format = "json"
# Note, "enveloped" can only be set to true for "single" request_mode.
# "batch" request_mode is automatically enveloped.
enveloped = false
}
}
```
Expand Down Expand Up @@ -78,6 +81,7 @@ Required:

Optional:

- `enveloped` (Boolean) Delivered messages are wrapped in an Ably envelope by default that contains metadata about the message and its payload. The form of the envelope depends on whether it is part of a Webhook/Function or a Queue/Firehose rule. For everything besides Webhooks, you can ensure you only get the raw payload by unchecking "Enveloped" when setting up the rule.
- `format` (String) JSON provides a text-based encoding, whereas MsgPack provides a more efficient binary encoding
- `headers` (Attributes List) If you have additional information to send, you'll need to include the relevant headers (see [below for nested schema](#nestedatt--target--headers))
- `signing_key_id` (String) The signing key ID for use in batch mode. Ably will optionally sign the payload using an API key ensuring your servers can validate the payload using the private API key. See the [webhook security docs](https://ably.com/docs/general/webhooks#security) for more information
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ably/terraform-provider-ably
go 1.19

require (
github.com/ably/ably-control-go v0.1.0
github.com/ably/ably-control-go v0.1.1-0.20231211162000-164517f286eb
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-framework v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.21.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C6
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/ably/ably-control-go v0.1.0 h1:flhd5ZiJZyWs+RxOK//ozsev6VpmRrqOmvXhVvgon3I=
github.com/ably/ably-control-go v0.1.0/go.mod h1:TP7gWAy+ga++gX6OZ0DtjwH8oVKKdiaIGQvZvxDKNdk=
github.com/ably/ably-control-go v0.1.1-0.20231211162000-164517f286eb h1:WVq8ysFKqCc8OtM77GnWF7s+cyEcRBT5+i2iirOZeoQ=
github.com/ably/ably-control-go v0.1.1-0.20231211162000-164517f286eb/go.mod h1:TP7gWAy+ga++gX6OZ0DtjwH8oVKKdiaIGQvZvxDKNdk=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/resource_ably_rule_amqp_external.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (r resourceRuleAmqpExternal) GetSchema(_ context.Context) (tfsdk.Schema, di
Required: true,
Description: "The Kafka partition key. This is used to determine which partition a message should be routed to, where a topic has been partitioned. routingKey should be in the format topic:key where topic is the topic to publish to, and key is the value to use as the message key",
},
"exchange": {
Type: types.StringType,
Required: true,
Description: "The RabbitMQ exchange, if needed supports interpolation; see https://faqs.ably.com/what-is-the-format-of-the-routingkey-for-an-amqp-or-kinesis-reactor-rule for more info. If you don't use RabbitMQ exchanges, leave this blank.",
},
"mandatory_route": {
Type: types.BoolType,
Required: true,
Expand Down
20 changes: 13 additions & 7 deletions internal/provider/resource_ably_rule_amqp_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestAccAblyRuleAmqpExternal(t *testing.T) {
"channel.message",
"amqps://test.example",
"topic:key",
"exchange",
true,
true,
44,
Expand All @@ -68,6 +69,7 @@ func TestAccAblyRuleAmqpExternal(t *testing.T) {
"channel.message",
"amqps://test.example",
"newtopic:key",
"newexchange",
false,
false,
23,
Expand All @@ -81,6 +83,7 @@ func TestAccAblyRuleAmqpExternal(t *testing.T) {
resource.TestCheckResourceAttr("ably_rule_amqp_external.rule0", "source.channel_filter", "^my-channel.*"),
resource.TestCheckResourceAttr("ably_rule_amqp_external.rule0", "source.type", "channel.message"),
resource.TestCheckResourceAttr("ably_rule_amqp_external.rule0", "target.routing_key", "newtopic:key"),
resource.TestCheckResourceAttr("ably_rule_amqp_external.rule0", "target.exchange", "newexchange"),
resource.TestCheckResourceAttr("ably_rule_amqp_external.rule0", "target.enveloped", "false"),
resource.TestCheckResourceAttr("ably_rule_amqp_external.rule0", "target.format", "msgpack"),
),
Expand All @@ -98,6 +101,7 @@ func testAccAblyRuleAmqpExternalConfig(
sourceType string,
targetUrl string,
targetRoutingKey string,
targetExchange string,
targetManditoryRoute bool,
targetPersistentMessages bool,
targetMessageTtl int,
Expand Down Expand Up @@ -133,13 +137,15 @@ resource "ably_rule_amqp_external" "rule0" {
target = {
url = %[5]q
routing_key = %[6]q,
mandatory_route = %[7]t
persistent_messages = %[8]t
message_ttl = %[9]d
headers = %[10]s
enveloped = %[11]s,
format = %[12]q,
exchange = %[7]q,
mandatory_route = %[8]t
persistent_messages = %[9]t
message_ttl = %[10]d
headers = %[11]s
enveloped = %[12]s,
format = %[13]q,
}
}
`, appName, ruleStatus, channelFilter, sourceType, targetUrl, targetRoutingKey, targetManditoryRoute, targetPersistentMessages, targetMessageTtl, targetHeaders, targetEnveloped, targetFormat)
`, appName, ruleStatus, channelFilter, sourceType, targetUrl, targetRoutingKey, targetExchange, targetManditoryRoute, targetPersistentMessages, targetMessageTtl, targetHeaders, targetEnveloped, targetFormat)
}

0 comments on commit d850dbf

Please sign in to comment.