Bootstrap FreeKB - RabbitMQ - Bind a Queue and Exchange using Terraform
RabbitMQ - Bind a Queue and Exchange using Terraform

Updated:   |  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.



Add the following to your file. This will bind "foo.queue" to "" with routing key "foo.key"

resource "rabbitmq_binding" "binding1" {
  vhost = "foo"
  source = ""
  destination = "foo.queue"
  destination_type = "queue"
  routing_key = "foo.key"


You may need to reissue the terraform init command.

~]# terraform init
Initializing the backend...
Initializing modules...
Initializing provider plugins...
Terraform has been successfully initialized!


The terraform plan command can be used to see what Terraform will try to do.

terraform plan


If the binding does not exist, Terraform will create the binding. If the binding already exist and the terraform.tfstate file contains the binding (it should), the binding will be updated. By default, the terraform.tfstate file should be found in your root module directory (/usr/local/terraform/rabbitmq in this example).

The terraform apply command from your root module directory (/usr/local/terraform/rabbitmq in this example) can be used to create or update 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 created
  + resource "rabbitmq_binding" "binding1" {
      + destination      = "foo.queue"
      + destination_type = "queue"
      + id               = (known after apply)
      + properties_key   = (known after apply)
      + routing_key      = "foo.key"
      + source           = ""
      + vhost            = "foo"

Plan: 1 to add, 0 to change, 0 to destroy.


After entering yes, the following should be displayed

rabbitmq_binding.binding1: Creating...
rabbitmq_binding.binding1: Creation complete after 0s [id=foo/]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter ea0c99 in the box below so that we can be sure you are a human.