Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get only bindings related to source/destination when checking if bindings exists or has been changed #43

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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