Skip to content

Commit

Permalink
Get only bindings related to source/destination when checking if bind…
Browse files Browse the repository at this point in the history
…ings exists or has been changed (#43)
  • Loading branch information
avitsidis authored Mar 15, 2023
1 parent 472eb34 commit b739f27
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
20 changes: 17 additions & 3 deletions rabbitmq/resource_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,23 @@ func ReadBinding(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] RabbitMQ: Attempting to find binding for: vhost=%s source=%s destination=%s destinationType=%s propertiesKey=%s",
vhost, source, destination, destinationType, propertiesKey)

bindings, err := rmqc.ListBindingsIn(vhost)
if err != nil {
return err
var bindings []rabbithole.BindingInfo
var err error
if destinationType == "queue" {
bindings, err = rmqc.ListQueueBindingsBetween(vhost, source, destination)
if err != nil {
return err
}
} else if destinationType == "exchange" {
bindings, err = rmqc.ListExchangeBindingsBetween(vhost, source, destination)
if err != nil {
return err
}
} else {
bindings, err = rmqc.ListBindingsIn(vhost)
if err != nil {
return err
}
}

log.Printf("[DEBUG] RabbitMQ: Bindings retrieved: %#v", bindings)
Expand Down
34 changes: 34 additions & 0 deletions rabbitmq/resource_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestAccBinding_basic(t *testing.T) {
"rabbitmq_binding.test", &bindingInfo,
),
},
{
Config: testAccBindingConfig_basic,
Check: testAccBindingCheck(
"rabbitmq_binding.foo_to_bar", &bindingInfo,
),
},
},
})
}
Expand Down Expand Up @@ -174,6 +180,26 @@ resource "rabbitmq_permissions" "guest" {
}
}
resource "rabbitmq_exchange" "foo" {
name = "foo"
vhost = "${rabbitmq_permissions.guest.vhost}"
settings {
type = "fanout"
durable = false
auto_delete = true
}
}
resource "rabbitmq_exchange" "bar" {
name = "foo"
vhost = "${rabbitmq_permissions.guest.vhost}"
settings {
type = "fanout"
durable = false
auto_delete = true
}
}
resource "rabbitmq_exchange" "test" {
name = "test"
vhost = "${rabbitmq_permissions.guest.vhost}"
Expand All @@ -193,6 +219,14 @@ resource "rabbitmq_queue" "test" {
}
}
resource "rabbitmq_binding" "foo_to_bar" {
source = "${rabbitmq_exchange.foo.name}"
vhost = "${rabbitmq_vhost.test.name}"
destination = "${rabbitmq_exchange.bar.name}"
destination_type = "exchange"
routing_key = "#"
}
resource "rabbitmq_binding" "test" {
source = "${rabbitmq_exchange.test.name}"
vhost = "${rabbitmq_vhost.test.name}"
Expand Down

0 comments on commit b739f27

Please sign in to comment.