RabbitMQ - Remove Binding using Terraform

by
Jeremy Canfield |
Updated: December 23 2021
| RabbitMQ articles
This assumes you have setup Terraform as described in RabbitMQ - Getting Started with Terraform. Let's say you have the following files on your Terraform server.
/usr/local/terraform/main.tf
/usr/local/terraform/foo/required_provider.tf
/usr/local/terraform/foo/bindings.tf
/usr/local/terraform/foo/exchanges.tf
/usr/local/terraform/foo/policies.tf
/usr/local/terraform/foo/queues.tf
/usr/local/terraform/foo/shovels.tf
/usr/local/terraform/foo/vhosts.tf
Let's say you have created a binding between foo.queue and foo.exchange using Terraform. In this scenario, your bindings.tf would contain something like this.
resource "rabbitmq_binding" "binding1" {
vhost = "foo"
source = "foo.exchange"
destination = "foo.queue"
destination_type = "queue"
routing_key = "foo.key"
}
To remove the binding, you would remove the binding block from your bindings.tf file. Or, remove the bindings.tf file.
Then, issue the following command to destroy the binding.
terraform apply
Something like this should be displayed, and you will be prompted to enter yes.
Terraform will perform the following actions:
# rabbitmq_binding.binding1 will be destroyed
- resource "rabbitmq_binding" "binding1" {
- arguments = {} -> null
- destination = "foo.queue" -> null
- destination_type = "queue" -> null
- id = "foo/foo.exchange/foo.queue/queue/foo.key" -> null
- properties_key = "foo.key" -> null
- routing_key = "foo.key" -> null
- source = "foo.exchange" -> null
- vhost = "foo" -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
After entering yes, the following should be displayed.
rabbitmq_binding.binding1: Destroying... [id=foo/foo.exchange/foo.queue/queue/foo.key]
rabbitmq_binding.binding1: Destruction complete after 1s
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
Did you find this article helpful?
If so, consider buying me a coffee over at